Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get the size of the request body of scripted rest API?

Mahesh Bachhav
Kilo Expert

I have scripted REST API in my ServiceNow scoped application. I would like to get the size of the request body when someone calls this REST API.

How to get the size of request body?

8 REPLIES 8

Hi,

yes there is a property but I don't think you can calculate the size

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Headers can be retrieved with " var headers = request.headers"

Try below.

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
  var headers = request.headers;
  var contentLength = headers['content-length'];

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Mahesh,

Since it's getting the size of the body, it's going to be POST or PUSH request.

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
        var requestData = request.body.data;
        var sizeOfBody = requestData.length;