400 error when making a rest api call

Jonathan Yowell
Kilo Explorer

Hi All,


Trying to figure out how to make a REST call.  In postman, when I do the following call, I get the expected response.  When I run this is ServiceNow, I am getting a 400 error.  I am leaning toward the issue being the string next to scope being my issue, but I am not finding a way to fix it.  Thoughts?

 

 var USER = workflow.scratchpad.USER;
 var PASS = workflow.scratchpad.PASS;    
 var r = new sn_ws.RESTMessageV2();
 r.setEndpoint("Endpoint here");
 r.setHttpMethod("POST");
 r.setRequestHeader("Content-Type","Application/json"); 
 r.setRequestBody('{"client_id":"client","Username":"' + USER + '","Password":"' + PASS + '","scope":"entitlement1:read,write,delete;config:manage,delete"}');

4 REPLIES 4

Vaibhav Dane
Tera Expert
Tera Expert

Hi Johnathan,

 

There can be 2 issues with your rest call.

  • Does the REST call from ServiceNow require Mid-Server as you are not setting any mid-server  in the example shown above.
  • Does your REST call require any authentication apart from the credentials provided in the request body?

Please check them and let me know if it works.

 

Regards,

Vaibhav Dane

Thanks for the reply!

 

It seems I removed the part of the call where I am setting a mid-server:

 r.setMIDServer(workflow.scratchpad.MIDServer);

in regards to any authentication, no, there isn't any additional needed.  I am able to do a similar call to this where only the user and pass are needed (different endpoint).  When I change to this call, I am getting the 400 error. 

Can you do r.getErrorMessage() after the rest call to check the error if any?

I'm not seeing an error.  It is moving passed this step but since no data is coming back, I am unable to parse anything for later use.  I am checking the httpStatus which is where I am seeing 400.