Generating token for ArcGIS Online hosted service

29114
22
Jump to solution
02-26-2018 10:16 PM
SteveOchieng
New Contributor III

Hi guys,

I'd like to generate token for arcgisonline hosted service but I can figure out the endpoint and how to construct the request.

Is ithttps://www.arcgis.com/sharing/rest/generateToken?username=username&password=password&expiration=60 ...

What is the endpoint and how would I construct the parameters. I'm using Java HttpUrlConnection? #ArcGISREST

1 Solution

Accepted Solutions
RamunasKraujutis
New Contributor III

Request:

POST https://www.arcgis.com/sharing/generateToken HTTP/1.1
Host: www.arcgis.com
Content-Type: application/x-www-form-urlencoded

f=json&username=USERNAME&password=PASSWORD&client=requestip

Response:

HTTP/1.1 200 OK
Date: Thu, 01 Mar 2018 09:53:04 GMT
Content-Type: text/plain;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Origin
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Vary: Accept-Encoding, User-Agent
X-Robots-Tag: noindex

{"token":"TOKEN","expires":1519905184244,"ssl":false}

View solution in original post

22 Replies
shan_sarkar
Occasional Contributor III
0 Kudos
SteveOchieng
New Contributor III

I have seen this, and for ArcGIS Server this is okay. However, I'd like to know which endpoint does ArcGIS Online use to generate tokens for username and password based authentication.

I know there is this option Get an access token | ArcGIS for Developers  which is based on CLIENT_ID and CLIENT_SECRET. But I want to use my password and username to get the token from ArcGIS online.

0 Kudos
RamunasKraujutis
New Contributor III

Use POST instead of GET.

0 Kudos
SteveOchieng
New Contributor III

Yes I need to use POST. But what is the right endpoint?

RamunasKraujutis
New Contributor III

Request:

POST https://www.arcgis.com/sharing/generateToken HTTP/1.1
Host: www.arcgis.com
Content-Type: application/x-www-form-urlencoded

f=json&username=USERNAME&password=PASSWORD&client=requestip

Response:

HTTP/1.1 200 OK
Date: Thu, 01 Mar 2018 09:53:04 GMT
Content-Type: text/plain;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Origin
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Vary: Accept-Encoding, User-Agent
X-Robots-Tag: noindex

{"token":"TOKEN","expires":1519905184244,"ssl":false}
SteveOchieng
New Contributor III

Thank you ramunask I just tried in Postman and it works.

0 Kudos
joerodmey
MVP Alum

How do you include the post conditions into the URL? I keep getting the following error:

{"error":{"code":400,"messageCode":"GWM_0002","message":"Invalid URL","details":[]}}

My URL looks like this:
https://www.arcgis.com/sharing/generateToken HTTP/1.1?f=json&username=USERNAME&password=PASSWORD&client=requestip

0 Kudos
CuartaOportunidad_Local_IVC
New Contributor II

Hi dear all,

I been trying to do that request too, using postman but I get an error: {"error":{"code":400,"message":"Unable to generate token.","details":["POST request should not contain username and password in the query string."]}

Can anybody help me to solve this, please?

Best regards,