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 08:38 PM
Hi,
yes there is a property but I don't think you can calculate the size
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 09:16 PM
Headers can be retrieved with " var headers = request.headers"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 09:34 PM
Try below.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var headers = request.headers;
var contentLength = headers['content-length'];

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 09:01 PM
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;