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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

what do you mean by size of request body?

It's not a file which can be measured in MB

regards
Ankur

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

Aman Kumar S
Kilo Patron

Hey,

You can't really check the size of the payload

If you are looking to do some relevant details:

Property Default value Description
glide.rest.scripted.max_inbound_content_length_mb 10 The maximum size, in megabytes, for a scripted REST request body that is not gzipped.
glide.rest.scripted.max_inbound_gzip_content_length_mb 1 The maximum size, in megabytes, for a scripted REST request body that is gzipped.
glide.rest.max_content_length 10

The maximum size, in megabytes, for a scripted REST request body, whether or not it is gzipped.

Maximum: 25

As a result, even if glide.rest.scripted.max_inbound_content_length_mb or glide.rest.scripted.max_inbound_gzip_content_length_mb are set, the request body is limited to the value of glide.rest.max_content_length.

Best Regards
Aman Kumar

SumanthDosapati
Mega Sage
Mega Sage

Hi @Mahesh Bachhav 

It is not a file to get size.

If your body is in JSON format, you can get the length of the object. i.e, number of key-value pairs in that with below sample script.

let a = {
   name: "ABC",
   age: 100,
   country: "Singapore"
}
console.log(Object.keys(a).length)


//It will print 3 as output

 

Mark as correct or helpful if it works.

Regards,

Sumanth

Mahesh Bachhav
Kilo Expert

As per Splunk documentation, the property "glide.rest.max_content_length" limits the maximum size, in megabytes, for a scripted REST request body.

Let me rephrase my question - 

I would like to get the content length of the request body in megabytes. The request body is in JSON and may have new line characters. How to do this?