Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

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  ||  ✨ 10x 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

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;