- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2018 09:07 PM
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>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2018 05:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2018 09:40 PM
Randy,
OAuth can be a rabbit hole sometimes. Please try the below method.
Your body/query should be
grant_type=authorization_code&code=<code>&redirect_uri=<uri>&scope=useraccount
You should also use an Autherization header that is a base64 encode of your client ID and Client Secret as shown below
Authorization: Basic base64clientinfo
In the above line replace base64clientinfo with the value obtained from the below line
GlideStringUtil.base64Encode('<client_id>:<client_secret>');
I hope this helps.
References:
https://community.servicenow.com/community?id=community_question&sys_id=55054f2ddbd8dbc01dcaf3231f9619b6
https://community.servicenow.com/community?id=community_blog&sys_id=0f5de629dbd0dbc01dcaf3231f9619ca
http://www.john-james-andersen.com/blog/service-now/easy-base64-encoding-in-servicenow.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2018 01:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2018 04:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2018 05:00 AM