Tryhing to generate an AGOL token using REST. WHat I have so far:
https://www.arcgis.com/sharing/generateToken HTTP/1.1?f=json&username=USERNAME&password=PASSWORD&client=requestip
Error I get:
{"error":{"code":400,"messageCode":"GWM_0002","message":"Invalid URL","details":[]}}
Solved! Go to Solution.
Hi Joe,
Here is an example on how to do this using python:
import requests, json
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
response = requests.post(tokenURL, data = params, verify = False)
token = response.json()['token']
Hi Joe,
Here is an example on how to do this using python:
import requests, json
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
response = requests.post(tokenURL, data = params, verify = False)
token = response.json()['token']
I don't have the option to use Python, I have to use REST directly. Reason being is that I'm using Integromat and webhooks
Figured it out. Used the following URL: https://www.arcgis.com/sharing/rest/generateToken?f=pjson&username=myUserName&password=myPW&referer=...
I'm not familiar with Integromat or webhooks, but I believe you need to create a POST request when generating a token. For example, you could use Postman to do this. Try this app and check to make sure your parameters are correct.
Have you tried adding it to the URL:
&token=yourtokenvalue
Is there an option to receive the expiry time in minutes instead of milliseconds?
How can you remove the word token and expiry from the JSON response?
Can you format the JSON response to just have the token and no other text?
In the python example I provided the response is a dictionary, so I can call the appropriate key ('token') to only receive that text.
token = response.json()['token']