The CreatorCon Call for Content is officially open! Get started here.

How to get HTTP status code in Rest message

shidhartha
Tera Contributor

How to get HTTP status code in Rest message??

 

please provide me the code...

1 ACCEPTED SOLUTION

@shidhartha 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can obtain it using getStatusCode() function on the response you received

example

var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://dev22614.service-now.com/api/now/table/u_cart_order');
request.setHttpMethod('POST');

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

request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody('{"u_catalog_item":"Blackberry",' +
                       '"u_variables":"original^299-999-9991|' +
                       'replacement^Yes"}');
var response = request.execute();

var httpStatus = response.getStatusCode();

gs.log(response.getBody());

Regards
Ankur

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

Thanks Ankur for your quick response.

@shidhartha 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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