4

I want to integrate my application with ServiceNow using its REST API. For this, my app needs to get authorized using OAuth 2. I have searched for Authorization and Token endpoints in the wiki of ServiceNow, but could not find any.

Can anyone please post here those urls?

chenrui
  • 8,910
  • 3
  • 33
  • 43
Ram Bavireddi
  • 1,139
  • 1
  • 19
  • 43

2 Answers2

3

Starting with the Fuji release ServiceNow supports authenticating to REST endpoints using OAuth. First off, be sure to enable the OAuth plugin if it's not already enabled on the ServiceNow instance you are trying to integrate with. For information on how to do this and how to setup an OAuth endpoint check out these product docs.

Once you've created an OAuth endpoint in the application registry on your ServiceNow instance you'll need to generate tokens to use for authentication. You can find curl samples for generating tokens in the product docs. Review the response to the request you made to generate tokens and grab the 'access token'. The response from generating tokens should contain a JSON body similar to the following:

{"scope":"useraccount","token_type":"Bearer","expires_in":1800,"refresh_token":"w599voG89897rGVDmdp12WA681r9E5948c1CJTPi8g4HGc4NWaz62k6k1K0FMxHW40H8yOO3Hoe","access_token":"F0jh9korTyzd9kaZqZ0SzjKZuS3ut0i4P46Lc52m2JYHiLIcqzFAumpyxshU9mMQ13gJHtxD2fy"}

From the response you will want to record the 'access_token' and include it as a bearer token in subsequent requests to the ServiceNow REST API endpoints.

Sample request to REST Table API using the access token:

curl -H "Accept:application/json" -H "Authorization:Bearer 2wRlsRCT2SYjCCJP91kwo2EFzj5qg4O3I3aC09e0-0hz6Ib3YK7If-LMiNorNuglfqbkL4AfkYC92KYHUCcbpQ" "http://<instance>.service-now.com/api/now/table/incident"

Hope that helps!

Bryan
  • 551
  • 4
  • 9
  • I already went through the links you mentioned in your answer. They didn't give me Authorization and Token urls. Can you please post those? – Ram Bavireddi Jul 01 '15 at 04:41
  • https://instancename.service-now.com/oauth_token.do, where instancename is the name of your servicenow instance (e.g., demo001.service-now.com). – Bryan Jul 01 '15 at 13:10
  • While correct, this doesn't really answer the question. OP is looking to do Authorization Code grant type while ServiceNow only supports Password and Refresh Token grant types. – Nathanial Woolls Oct 05 '15 at 21:26
  • ServiceNow (istanbul at least) supports code grant flow. See here https://community.servicenow.com/message/1122997#1122997 for python example. – nmb.ten Apr 18 '17 at 13:20
0

It seems ServiceNow supports only password and refresh_token grant types. Please see here. Authorization and Token urls are for Authorization code grant type.

Ram Bavireddi
  • 1,139
  • 1
  • 19
  • 43