How to pass JSON data when running REST API request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 09:51 AM
I am using a scripted REST API. From another system, is it possible to send some data in the form of JSON data? How would I go about doing that with a curl command? I can pass the query parameter within the URL, but that's not what I need.
I would like to use the GET method, but I don't believe --data flag can be used with GET. So I would have to use POST.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 10:20 AM
Are you trying to send some data from scripted rest api to external system ?
Ex:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var responseText = 'Successfully created case.';
var returnObj = {
"response_type": "success",
"text": '"'+ responseText + '"'
};
response.setContentType('application/json');
response.setStatus(200);
response.getStreamWriter().writeString(JSON.stringify(returnObj));
})(request, response);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 10:45 AM
Thank you very much for the example. This gives me some ideas. But what I actually need is actually to accept data from external source. Could you please provide an example?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 10:49 AM
If external system is sending the data then try to log it and see if anything is coming from external system.
EX:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestBody = request.body.dataString;
gs.log('requestBody: ' +requestBody, "Scripted API");
})(request, response);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 11:37 AM
Thank you. This gives me a string. But is there any way to take the JSON and keep it intact to easily be able to grab values out of it within the scripted REST API script? Would be nice if JSON object stayed as is when it reaches the scripted REST API.