How to pass JSON data when running REST API request

Mike278
Kilo Explorer

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.

5 REPLIES 5

Mike Patel
Tera Sage

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);

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?

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);

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.