Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thisnameissoclever/abff2bc7b67dcf9c383ce8d0c1344a5e to your computer and use it in GitHub Desktop.
Save thisnameissoclever/abff2bc7b67dcf9c383ce8d0c1344a5e to your computer and use it in GitHub Desktop.
Handle data stream for plain-text or non-standard request body content-types in scripted rest API in ServiceNow.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var body = request.body;
var streamBody = body.dataStream;
var stringBody = getBodyText(streamBody);
gs.log('Message body: ' + stringBody);
function getBodyText(streamBody) {
var reader = new GlideTextReader(streamBody);
var input = "";
var ln= "";
while((ln = reader.readLine()) != null) {
input += ln + '\n';
}
return input;
}
})(request, response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment