OAuth Access Token Request

tjrigario
Kilo Contributor

Hello,

I believe that there is an error either in the product documentation or the OAuth implementation. Upon requesting an access token with valid credentials, I consistently receive a 401 Unauthorized message.

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

I've been unsuccessful at making the OAuth implementation work at all. Using the classic Authorization header method works just fine.

Chris

1 ACCEPTED SOLUTION

mayank3103
Giga Contributor

Replying to this post a bit late, so joining the party when this might be resolved. But might be helpful for others



I was also having a similar issue.


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



Steps taken:


1) Make sure Authorization is "No Auth"


find_real_file.png


2) Make sure the Body is x-www-form-encoded


curl -X POST \


  https:///instance.service-now.com/oauth_token.do \


  -H 'cache-control: no-cache' \


  -H 'content-type: application/x-www-form-urlencoded' \


  -H 'postman-token: 53f8a8f7-f286-607f-1e7e-8dab629081fb' \


  -d 'grant_type=password&client_id=ac0dd3408c1031006907010c2cc6ef6d&client_secret=bv4gg7o7akbc18jjy13m&username=admin&password=admin'


find_real_file.png


3) As a result you would see the Request Headers automatically pulled up as


find_real_file.png



Now use the access_token in subsequent requests. Adding the header as Authorization: Bearer <access_token>


curl -X GET \


  'https:///instance.service-now.com/api/now/table/sys_user?sysparm_display_value=true&sysparm_fields=n...' \


  -H 'authorization: Bearer Icru5EyU4ZrgngoB0ecHp_LcXJHm-nB1NBt2QXaEXhYoPZcd6ss6KS4mLGfApGDDsi6ka86zdabHMgKX8doeHA' \


  -H 'cache-control: no-cache' \


  -H 'postman-token: e2073e4f-d09e-f19b-b510-5779f9ba415a' \


find_real_file.png


View solution in original post

23 REPLIES 23

allwyn1
Kilo Explorer

Hi Venkat,



Using Rest API client (chrome extension) I can get successful response, but coming Oracle to servicenow it states Unauthorized (401)   so within Servicenow do I have to enable some properties to allow and authenticate and send success response from Servicenow.   That is what I am looking for.



Thanks


Allwyn


bryanbarnard
ServiceNow Employee
ServiceNow Employee

Hi Allwyn,



    I'm not familiar with using oracle plsql to make web service requests. If you have the request to get an oauth token working from a tool such as advanced rest client that helps you build and send web service requests then the next step I would suggest is to work on configuring oracle plsql to make the same web service request. Not being familiar with Oracle plsql I can't help you with syntax to do that but there may be someone else on the community that has done this before. My suggestion would be to create another separate post on the ServiceNow community and include what you are trying to do in the title something like 'requesting oauth token via plsql'. Having this in the title would make if more likely that someone with oracle plsql experience may find and respond to your post.



It may also be helpful to be able to see the http requests that are being made by your plsql code so you can compare the url, headers, payload with the request you are making from advanced rest client. A tool I've used in the past to help with this is RequestBin — Collect, inspect and debug HTTP requests and webhooks


Which allows me to make a request to a HTTP endpoint (hosted by requestbin) and then see exactly what my request looked like.



Hope that helps,


Bryan


Bryan,



Thanks for your response.   There is nothing wrong in plsql syntax at all,   I have used similar code to integrate Salesforce as well no issues at all,   I was able to get the SFDC access token and perfom subsequent calls,   we have verified it works in Chrome Advance REST API Client now we are passing on the same url from a Oracle database it fails with Unauthorized error message,   I have downloaded certificate and installed is there anything else needs to be done on the Dev instance?     I could open a new request on the community as well.



Thanks


Allwyn


nickbrisoux
Kilo Explorer

Hi,



I've been reading this thread. I'm experimenting a pretty similar issue but with a difference:



I do can get the access token performing a request to my dev instance, where I registered my app to get client ID and secret.


However when I try to perform a similar request to another service now instance, I get the error:


401


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



Should I register my app on the second service now instance in order to get new id/secret, in case I want to query data from that other different instance?



Thanks in advance!


mayank3103
Giga Contributor

Replying to this post a bit late, so joining the party when this might be resolved. But might be helpful for others



I was also having a similar issue.


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



Steps taken:


1) Make sure Authorization is "No Auth"


find_real_file.png


2) Make sure the Body is x-www-form-encoded


curl -X POST \


  https:///instance.service-now.com/oauth_token.do \


  -H 'cache-control: no-cache' \


  -H 'content-type: application/x-www-form-urlencoded' \


  -H 'postman-token: 53f8a8f7-f286-607f-1e7e-8dab629081fb' \


  -d 'grant_type=password&client_id=ac0dd3408c1031006907010c2cc6ef6d&client_secret=bv4gg7o7akbc18jjy13m&username=admin&password=admin'


find_real_file.png


3) As a result you would see the Request Headers automatically pulled up as


find_real_file.png



Now use the access_token in subsequent requests. Adding the header as Authorization: Bearer <access_token>


curl -X GET \


  'https:///instance.service-now.com/api/now/table/sys_user?sysparm_display_value=true&sysparm_fields=n...' \


  -H 'authorization: Bearer Icru5EyU4ZrgngoB0ecHp_LcXJHm-nB1NBt2QXaEXhYoPZcd6ss6KS4mLGfApGDDsi6ka86zdabHMgKX8doeHA' \


  -H 'cache-control: no-cache' \


  -H 'postman-token: e2073e4f-d09e-f19b-b510-5779f9ba415a' \


find_real_file.png