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":[]}}
Hi Joe,
Here is an example on how to do this using python:
<SPAN class="keyword token">import</SPAN> requests<SPAN class="punctuation token">,</SPAN> json tokenURL <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2FgenerateToken" target="_blank">https://www.arcgis.com/sharing/rest/generateToken</A><SPAN>'</SPAN></SPAN> params <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'pjson'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'username'</SPAN><SPAN class="punctuation token">:</SPAN> username<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'password'</SPAN><SPAN class="punctuation token">:</SPAN> password<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'referer'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com" target="_blank">http://www.arcgis.com</A><SPAN>'</SPAN></SPAN><SPAN class="punctuation token">}</SPAN> response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>post<SPAN class="punctuation token">(</SPAN>tokenURL<SPAN class="punctuation token">,</SPAN> data <SPAN class="operator token">=</SPAN> params<SPAN class="punctuation token">,</SPAN> verify <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> token <SPAN class="operator token">=</SPAN> response<SPAN class="punctuation token">.</SPAN>json<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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 <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> response<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>json<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 14px;">'token'</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN>
Can you format the JSON response to just have the token and no other text?
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?
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<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Figured it out. Used the following URL: https://www.arcgis.com/sharing/rest/generateToken?f=pjson&username=myUserName&password=myPW&referer=http://www.arcgis.com
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
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.