400 error when making a rest api call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 05:54 AM
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"}');
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 06:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 06:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 06:23 AM
Can you do r.getErrorMessage() after the rest call to check the error if any?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 07:40 AM
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.