Hello the community,
We have build all our API's request in postman to interact with serviceNow and now we try to automate all requests from Vmware vRealize Orchestrator.
We are stuck on the step to get an access token with OAuth.
1°) we build our BODY (username & password are in variable) :
//create a fresh json object to store the data from the user
jsonContent = new Object();
jsonContent.grant_type = "password_credentials";
jsonContent.username = username;
jsonContent.password = password;
jsonContent.client_id = "4e88edc1992XXXXXXXXX38567";
jsonContent.client_secret = "2XXXXXXC";
//switch the format to string in order to be request-ready
content = JSON.stringify(jsonContent);
System.debug("Content of request : " + content);
2°) We launch the request to the URL : https://OURinstance.service-now.com/oauth_token.do
//prepare request
var inParamtersValues = [];
var request = restOperation.createRequest(inParamtersValues, content);
//set the request content type
request.contentType = "application/x-www-form-urlencoded";
System.debug("Request : " + request);
System.debug("Request URL : " + request.fullUrl);
//execute request
var response = request.execute();
//prepare output parameters
System.debug("Response : " + response);
statusCode = response.statusCode;
wsResponse = response.contentAsString;
System.debug("Raw answer : " + wsResponse);
var jsonWsResponse = JSON.parse(wsResponse);
Result :
Raw answer : {"error_description":"access_denied","error":"server_error"}
Do you have try to get Token for serviceNow from vRO please ?
Thx for your help.
Hi
I wonder if the problem is that you're setting the Request.contentType as form-encoded but trying to POST JSON in the body
You could try specifying the data as key/value pairs like this
"grant_type=password_credentials&username=" + username + "&password=" + password + "&client_id=4e88edc1992XXXXXXXXX38567&client_secret=2XXXXXXC"
- from here - https://www.servicenow.com/community/developer-blog/oauth-2-0-with-inbound-rest/ba-p/2278926
Looking at the info on that page, it makes no mention of JSON so wondering if this might be the problem?
Hello nobody use vRealize Orchestrator to request serviceNow api's?
Hi,
Looking at the image there where you define the content, it seems like you have literal space characters embedded & if I understand correctly these will cause a problem for the server
I've put the red boxes over the areas where you have those spaces. If you remove those and try that again?
Also, what are the values of response.statusCode and response.content when you make this request?