How can we send response of one scripted rest api to another scripted rest api

Lakshmi Meghana
Kilo Contributor

I have created a Scripted Rest API which generates a response, how to send the response to another Scripted Rest API

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Scripted REST API would return the response to the external application which has consumed the ServiceNow Endpoint.

you can consume API and send that response as request body

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Anil Lande
Kilo Patron

Can you please explain complete use case?

To which API you want to send the response and from where?

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

I am trying to send response from Scripted API to another Scripted API [my custom api]

Is this the right way to send response 

try {
var json = new JSON();
var jsonObj = json.encode(result_arr);
gs.log("JSON" + jsonObj);
var rm = new sn_ws.RESTMessageV2();
rm.setEndpoint('my custom api url');
rm.setHttpMethod('POST');

//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';

rm.setBasicAuth(user, password);
rm.setRequestHeader("Accept", "application/json");
rm.setRequestHeader('Content-Type', 'application/json');
rm.setRequestHeader("Accept", "application/json");
rm.setRequestBody(jsonObj);
var response1 = rm.execute();
responseBody=response1.getBody();
gs.log(response1.getBody());
status1 = response.getStatusCode();
} catch (ex) {
errorMsg = ex.getMessage();
status1 = '500';
}

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Scripted REST API would return the response to the external application which has consumed the ServiceNow Endpoint.

you can consume API and send that response as request body

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Can you please share sample documentation or an example on how to consume API and send that response as request body