Get Oauth access token return server_error access_denied

Randy25
Kilo Contributor

I am trying to connect to the REST API to get incidents in my service now instance using OAuth code grant flow as described below:

 

OAuth authorization code grant flow

 

I can get a code from the first step, but when I try to request the access and refresh tokens I get a 401 unauthorized response with the body:

{"error_description":"access_denied","error":"server_error"}

I use OAuthClient library to post request and my URL is :

https://<instance>.service-now.com/oauth_token.do

My body/query params are:

grant_type=authorization_code&code=<code>&redirect_uri=<uri>&client_id=<id>&redirect=<redirecturl>

 

1 ACCEPTED SOLUTION

And, your endpoint should just end with oauth_token.do All the parameters like code, redirect uri etc etc should be sent in the body Please send screen shots of Autherization Tab, Headers Tab and Body Tab from your Postman

View solution in original post

8 REPLIES 8

Randy25
Kilo Contributor

I tried the suggestion, the result is access_denied too. Here are screenshots of Authorization Tab, Headers Tab, and Body Tab.

find_real_file.png

find_real_file.png

find_real_file.png

Not sure why its not working. Its worth giving the below process a shot. They way to get the acess token seems very simple in the below link.

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

Randy25
Kilo Contributor

I read the attached process before and it worked with postman "Get New Access Token" function, but I need to find out how to get access token with URL request. My application uses URL request.

 

It confused me for days. ;(

Randy25
Kilo Contributor

Problem resolved. If I used postman to post request token URL directly, it will return access_denied. I used my application to redirect by web with the same request and got the access token successfully.

 

Thank you for the help 🙂