Not getting correct error message for Scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 07:42 AM
I have scripted REST API that accepts request body in JSON format and the maximum size is 10 MB(default).
Partial REST API Code -
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestBody = request.body;
var requestString = requestBody.dataString;
.
.
.
.
.
.
})(request, response);
If the size of request body is more than 10 MB then ServiceNow returns 500 Internal Server Error response with the below error message -
I am expecting the below error message from the API response. How to get the below error message?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 07:35 PM
To handle a response data larger than 10 MB you need to use a Data Stream
https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/integrationhub/tasks/use-data-stream-in-flow.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 07:36 PM
Hi, I have not found any SNC reference to configuring custom response for excessive payload size, can you clarify where this is configured?
I am guessing but if it is in the scripted REST API and if your file size exceeds the set limits, then I would not expect the payload to get as far as your scripted REST API so could not generate the custom message.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 09:55 PM
Hi Mahesh,
Is there a try-catch block to catch errors in code?
getMessage() is a function to get message translation. An error may be occurring somewhere in the code and not being able to get a message to be returned.