how to use external client oAuth access token in inbound scripted REST API

Sagaya1
Giga Expert

Hi,

I have created the external client oAuth access token through https://<instance>.service-now.com/oauth_token.do.

How do i use this access token in scripted REST api script for authentication ?

 

Regards,

Sagaya.

1 ACCEPTED SOLUTION

@Sagaya 

Glad to know that it worked.

Please close the thread as answered by marking my response as correct and helpful If I was able to help/guide you.

Regards
Ankur

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

View solution in original post

24 REPLIES 24

Shubham Bongulw
Giga Guru

Hi Sagaya,

Please refer below link, as it will help you-

https://developer.servicenow.com/blog.do?p=/post/inbound-oauth-auth-code-grant-flow-part-1/

Warm Regards,

Shubham Bongulwar

Please mark helpful or correct if it helps!!!

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Can you explain your requirement?

You are consuming endpoint of ServiceNow instance or some 3rd party for OAuth.

Regards
Ankur

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

Sagaya1
Giga Expert

Hi ,

Let me explain the flow.

1. Create an OAuth API endpoint for external client

2. Created the scripted REST API for POST operation in service now. No authentication code written in the script.

3. In postman call https://<instance>.service-now.com/oauth_token.do and get the access token .

4. pass the access token in postman POST request API header and trigger the API

5.Response :

 responseBody:{"error":{"message":"User Not Authenticated","detail":"Required to provide Auth information"},"status":"failure"}

http response status_code: 401

 

Please help to resolve this issue.

 

 

@Sagaya 

So it means either of this

1) in the API call of step 4 you are not sending the Access Token received in step 3

2) or you didn't get the valid access token in step 3 because of invalid username/password

please check below blog from me and you should be able to achieve/test it using postman

OAuth 2.0 with Inbound REST

Regards
Ankur

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