REST API response in Json format

salu
Mega Guru

Hello,

I am very new in the web service.

I want to access a third party URL and retrieve data in json format using get method.

I have created a REST message and using get method am expecting a json format but not coming as [],but status is 200.

What the step am missing here or how can make it working

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Saranya,



The status of 200 means a success. The response you should be able to get in logs using the below script



var r = new sn_ws.RESTMessageV2('getCartoon Number', 'get');  


// set various parameters which you want



var response = r.execute();  


var responseBody = response.getBody();  


var httpStatus = response.getStatusCode();  


gs.log(JSON.stringify(responseBody));



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Saranya,



The status of 200 means a success. The response you should be able to get in logs using the below script



var r = new sn_ws.RESTMessageV2('getCartoon Number', 'get');  


// set various parameters which you want



var response = r.execute();  


var responseBody = response.getBody();  


var httpStatus = response.getStatusCode();  


gs.log(JSON.stringify(responseBody));



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hello ankur,


Tried in background script and getting null



*** Script: null


bawiskar


Hello Ankur,



I tried the below script



try {


var r = new sn_ws.RESTMessageV2('getCarton Number', 'get');


r.setStringParameter('olpn', 'DTR000628859');




//override authentication profile


//authentication type ='basic'/ 'oauth2'


//r.setAuthentication(authentication type, profile name);




var response = r.execute();


var responseBody = response.getBody();


var httpStatus = response.getStatusCode();


gs.log('http response status_code: '+httpStatus);


gs.log('http response responseBody: '+responseBody);


}


catch(ex) {


var message = ex.getMessage();


}




*** Script: http response status_code: 200


*** Script: http response responseBody: []




Does it will   the issue in endpoint url/external server?


Hi Saranya,



Since you are setting the parameter "olpn" and you have hardcoded the olpn number in the endpoint it might not be able to get the value for that olpn number in that system.


Have this in endpoint olpn=${olpn} and in the variable substitutions create a variable and have following in name and test value olpn and then test


This will have a dynamic value for olpn



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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