Select to view content in your preferred language

How to generate token for RESTAPIs

481
2
Jump to solution
07-08-2024 12:29 AM
UJJWALSINGH
New Contributor

I generated a token by following the process mentioned in the developer documentation, using dummy URLs to check the APIs in Postman. However, when I try to make a GET request, it shows an invalid token. Can someone please help me on this or identify where I made mistake ?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
CodyPatterson
Frequent Contributor

Hey @UJJWALSINGH 

I typically use this function here in Python to generate the token:

def GetToken(username, password):

    url = f'https://www.arcgis.com/sharing/generateToken?f=json&username={username}&password={password}&referer=http://www.arcgis.com'

    json = requests.get(url+'&f=json').json()

    return json['token']

Once the token is returned, this is how I enter it into Postman to use for testing purposes:

CodyPatterson_0-1720437350794.png

Postman will need to take the token as a Bearer Token, once that is input, everything should work fine!

If that doesn't end up working, let me know and I'll see what I can find!

Cody

View solution in original post

2 Replies
CodyPatterson
Frequent Contributor

Hey @UJJWALSINGH 

I typically use this function here in Python to generate the token:

def GetToken(username, password):

    url = f'https://www.arcgis.com/sharing/generateToken?f=json&username={username}&password={password}&referer=http://www.arcgis.com'

    json = requests.get(url+'&f=json').json()

    return json['token']

Once the token is returned, this is how I enter it into Postman to use for testing purposes:

CodyPatterson_0-1720437350794.png

Postman will need to take the token as a Bearer Token, once that is input, everything should work fine!

If that doesn't end up working, let me know and I'll see what I can find!

Cody

UJJWALSINGH
New Contributor

Thank you! this is working 

0 Kudos