Token Generation

rna
Kilo Explorer

I am trying to generate the access token for an application which I have deployed over serviceNow,

Referred the link: http://wiki.servicenow.com/index.php?title=REST_API

Rest API : https://<InstanceName>.service-now.com/oauth_token.do

Request Body:

{"grant_type":"password","client_id":"33eb1705c75f3154400b1237989343b5","client_secret":4gE[IT#5qk,

"username":"UserName",

"password":"Password"}

Response:

        Status Code: 401 Unauthorized

        {

            "error": "server_error",

            "error_description": "access_denied"

        }

Am I missing anything?

20 REPLIES 20

silas1
ServiceNow Employee
ServiceNow Employee

Hi Rohit,



You need to use form parameters in your request. Here's an example using curl:



curl "https://<instance>.service-now.com/oauth_token.do" -XPOST --data "grant_type=password&client_id=33eb1705c75f3154400b1237989343b5&client_secret=4gE%5BIT%235qk&username=UserName&password=Password" -v



Note that I have URL-encoded the client secret you provided as it must contain only URL-safe characters.



Hope this helps,


Silas


Silas Smith Great tip with the URL-encoding for the client_secret!


Pankaj Katoch1
Mega Contributor

Token username need to be send in Header of request.



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


And I'm not sure what you mean with the /username Pankaj, all I get when trying to use this is a "Page not found"… have you tested this? And could you elaborate how to use it?