How to get access token by using OAuth configuration using client credentials to make Outbound call?

KM SN
Tera Expert

When I click on Get OAuth token, I am getting OAuth flow successful and seeing access token in the OAuth Credentials but when I did same by going into the get token http method and testing the connection I am again getting the 401 error. I am not sure why this is happening?

 

If I want to leverage the access token produced by rest message how I need to get it for furthermore actions as I need to pass it as a header to make outbound call? 



R-1.png

R-2.png

R-3.png

1 ACCEPTED SOLUTION

Create an OAuth Profile:

Navigate to: System OAuth > Application Registry. If you haven’t already created an OAuth Profile, you need to do so. This profile will store the OAuth credentials, such as the Client ID, Client Secret, and other authentication details.

 

OAuth provider details. (this info you can see when you going to create OAuth application registry)

  • Name: A unique name.
  • Client ID: Client ID of application registered in third-party OAuth server.
  • Client Secret: Client secret of application registered in third-party OAuth server.
  • Refresh Token Lifespan: Time in seconds the Refresh Token will be valid.
  • Authorization URL: OAuth Server's auth code flow endpoint. Required only for Authorization Code grant type.
  • Token URL: OAuth Server's token endpoint.
  • Token Revocation URL: OAuth Server's token revocation endpoint.
  • Redirect URL: OAuth callback endpoint. Leave it empty for auto-generation.

Attach the OAuth Profile to the REST Message:

Navigate to: System Web Services > Outbound > REST Message.
Either create a new REST Message or edit an existing one.
In the Authentication tab, under OAuth 2.0, select the OAuth Profile you created earlier. This links the REST message to the OAuth Profile, which will automatically handle token management for you.
Token Management: ServiceNow will automatically fetch, refresh, and append the access token to the Authorization header for all REST API calls made using this REST Message.

 

Using the REST Message in Scripts (Flow/BR/Script Include/Sjob): Once the OAuth Profile is linked to the REST Message, you can simply call the REST message from a Flow, Business Rule (BR), Script Include, or Scheduled Job.

You do not need to manually pass the Authorization header in your API calls anymore.

Also you can refer following links for same :
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0693451

 


https://www.servicenow.com/docs/de-DE/bundle/vancouver-api-reference/page/integrate/outbound-rest/ta...

 

View solution in original post

14 REPLIES 14

Murthy Ch
Giga Sage

@KM SN 

Hope you added Authorization and Content-Type as a header in your HTTP method.

 

Thanks,
Murthy

No, I haven't added. Do I need to send authorization header when I am calling REST Message?

Ankur Bawiskar
Tera Patron
Tera Patron

@KM SN 

I believe when you use Test Run it's not fetching the correct credentials and hence unable to get access token

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I am able to get the access token however when I click on the test in http method, I am getting 403 with message {"error":{"code":"0x80072560","message":"The user is not a member of the organization."}}