Select to view content in your preferred language

Generating token for ArcGIS Online hosted service

35471
22
Jump to solution
02-26-2018 10:16 PM
SteveOchieng
Occasional Contributor

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
Occasional Contributor

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
Frequent Contributor
0 Kudos
SteveOchieng
Occasional Contributor

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.

RamunasKraujutis
Occasional Contributor

Use POST instead of GET.

0 Kudos
SteveOchieng
Occasional Contributor

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

RamunasKraujutis
Occasional Contributor

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
Occasional Contributor

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
SteveOchieng
Occasional Contributor
CuartaOportunidad_Local_IVC
Emerging Contributor

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,