How to get the size of the request body of scripted rest API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 03:34 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 03:43 AM
Hi,
what do you mean by size of request body?
It's not a file which can be measured in MB
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 03:52 AM
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. |
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 03:54 AM
Hi
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 08:33 PM
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?