Created
April 21, 2019 20:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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