VMware Aria Automation Orchestrator

 View Only
  • 1.  vmWare vRO & serviceNow APi's with OAUth Get Token

    Posted Dec 14, 2022 03:40 PM

    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.



  • 2.  RE: vmWare vRO & serviceNow APi's with OAUth Get Token

    Posted Dec 14, 2022 04:47 PM

    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"

    eoinbyrne_0-1671036359112.png- 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?



  • 3.  RE: vmWare vRO & serviceNow APi's with OAUth Get Token

    Posted Feb 03, 2023 02:32 PM

    Thx ,

     

    I have already try this method :

     

    ymichalak_0-1675434667645.png

     

     

    ymichalak_1-1675434684985.png

     

     

    Without a big success :

     

     



  • 4.  RE: vmWare vRO & serviceNow APi's with OAUth Get Token

    Posted May 03, 2023 01:33 PM

    Hello nobody use vRealize Orchestrator to request serviceNow api's?



  • 5.  RE: vmWare vRO & serviceNow APi's with OAUth Get Token

    Posted May 07, 2023 12:31 PM

    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

    eoinbyrne_0-1683462580692.png

    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?



  • 6.  RE: vmWare vRO & serviceNow APi's with OAUth Get Token

    Posted Jan 30, 2025 02:06 PM

    Although it could depend on the ServiceNow release my Orchestrator action with JavaScript to retrieve the oauth2 is a bit different.

    I'm actually adding the content to the URL : 

    querystring = '/oauth_token.do?' + content

    Then i also pass the OAuth 2.0 with empty token in the authorization - if not you may see an access denied in the return,, so : 

    var auth = RESTAuthenticationManager.createAuthentication('OAuth 2.0', [' ', 'Authorization header'])

    transientHost.authentication = auth

    then i just do a createrequest with a POST and querystring and the content -> not sure the content is needed since it's a urlencoded contentType ...