ServiceNow Integration with HP Order Status (OSS) API

Hitesh_Mourya
Tera Guru

Hello Everyone,
we are currently experiencing difficulties with authenticating our ServiceNow token before invoking the HP Order Status API. We are using the OAuth2 client credentials flow with the API key, secret ID, and client ID. Despite creating the application registry and profile, our authentication attempts are failing with an error message. Has anyone encountered a similar issue or has insights on troubleshooting this authentication problem? Your assistance and expertise would be greatly appreciated!

Link to the HP OrderStatus (OSS) API: HP OrderStatus (OSS) API

8 REPLIES 8

Hi @Rajesh Chopade1  and @Community Alums 

we are able to get token in post main using O Auth2.0 but same we are setting up in ServiceNow we are receiving error.
Here's the screenshot of error message.
image (2).png

Regards,
Hitesh Mourya

means issue in the OAuth setup within ServiceNow.

Verify the points which already i have mentioned above, I hope that resolved your issue.

Hi @Rajesh Chopade1 ,
Thanks for providing verification points, I have checked each points and we have provided all the information correctly but still facing same error. could you please suggest any other way to get auth token.

Regards, 
Hitesh Mourya

Community Alums
Not applicable

Hi @Hitesh_Mourya 

 

Try below code in background script and then share me of output.


Don't forgot to replace the client id and secret id and url,

 

 

var clientId= "add_the_clientid";
var clientSecret = "add_the_clientSecret";
var appUri = "add_the_appUri";

var url = "https://login.microsoftonline.com/oauth2/v2.0/token";
var payload = "grant_type=client_credentials&client_secret=" + clientSecret + "&client_id=" + clientId + "&scope=" + appUri + "/.default";  // Replace the URL 

        var request = new sn_ws.RESTMessageV2();
        request.setEndpoint(url);
        request.setHttpMethod('POST');
        request.setRequestHeader("Accept", "application/x-www-form-urlencoded");
        request.setRequestBody(payload);
        var response = request.execute();
        if (response && response.getStatusCode() === 200) {
          gs.info(JSON.parse(response.getBody()).access_token);
        } else {
            gs.error("Error generating auth token: " + response.getBody());
             gs.info('null');
        }

 

 

Regards,

Krishna