Anyone have a curl example for the generateToken REST?

6930
3
Jump to solution
09-10-2014 11:31 AM
ThomasGagne
New Contributor II

The documentation is unclear exactly how to send the username, password, and other parameters in the REST POST.

 

The documentation is here : <ArcGIS REST API >

 

I've tried

 

curl -X POST https:///www.arcgis.com/sharing/rest/generateToken?username=me&password=XX&client=ip&ip=aa.bb.cc.dd

 

curl -X POST -d username=me -d password=XX -d client=ip -d ip=aa.bb.cc.dd https://www.arcgis.com/sharing/rest/generateToken

 

curl -X POST -d @ebody https://company.maps.arcgis.com/sharing/rest/generateToken

where ebody is a file containing

username=me

password=XX

client=ip

ip=aa.bb.cc.dd

 

and variations on all of them.

 

Does anyone have a working example, or explain what to use for the base url?  Does it matter?

 

Sometimes I'll get a 404, other times I get an HTML response:

 

<html>

<head>

<title>ArcGIS Portal Directory</title>

<link href="https://community.esri.com/sharing/rest/files/gw.css" rel="stylesheet" type="text/css"/>

</head>

<body>

<br/>

<div class="gwDiv">

<table class="navTable" width="100%"><tr><td class="breadcrumbs">ArcGIS Portal Directory</td></tr></table>

<tr valign="top">

<br/><br/>

<b>

<a href="http://resources.arcgis.com/en/help/arcgis-rest-api/" >API Reference</a>

</b>

 

</tr>

</table>

 

</div>

 

</body>

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ThomasGagne
New Contributor II

Well, the ultimate trick was providing an "f=json" parameter.  I was really close.

curl -X POST -d username=me -d password=XX -d referer=www.company.com f=json https://www.arcgis.com/sharing/rest/generateToken

Which finally returned the response....

{"token" : "-DZuy32O7y40jlKNOTREALLYnorCerffLl5THECGSTy1tUO6zpReAl8nMVb1pI8ccn1lYkR-CEPsDgaSTaZF1U49aoC9B1aObUToKEn2fQJ_ZVYRf_0CSkS-2p1eTIpigoI548k7AVWAQ4x21l-0RHdQQnB1pslpXhpSE.","expires" : 1410382414882,"ssl" : true}

View solution in original post

0 Kudos
3 Replies
ThomasGagne
New Contributor II

Well, the ultimate trick was providing an "f=json" parameter.  I was really close.

curl -X POST -d username=me -d password=XX -d referer=www.company.com f=json https://www.arcgis.com/sharing/rest/generateToken

Which finally returned the response....

{"token" : "-DZuy32O7y40jlKNOTREALLYnorCerffLl5THECGSTy1tUO6zpReAl8nMVb1pI8ccn1lYkR-CEPsDgaSTaZF1U49aoC9B1aObUToKEn2fQJ_ZVYRf_0CSkS-2p1eTIpigoI548k7AVWAQ4x21l-0RHdQQnB1pslpXhpSE.","expires" : 1410382414882,"ssl" : true}

0 Kudos
MBgislab
New Contributor

How to test an existing token with curl?

Examples:

1) Token with IP Address or IP address of this request's origin

curl.exe -v  "http://xxx/arcgis/rest/services/one/one_mapservice/MapServer/export?bbox=2606311.7,1183257.7,2609357..."

2) Token with HTTP Referer:

curl.exe -v  --header "referer: http:referer-url" "http://xxx/arcgis/rest/services/one/one_mapservice/MapServer/export?bbox=2606311.7,1183257.7,2609357..."

Note: With header HTTP_REFERER: Getting '498 - Invalid Token' 

curl.exe -v  --header "HTTP_REFERER: http:referer-url" "http://xxx/arcgis/rest/services/one/one_mapservice/MapServer/export?bbox=2606311.7,1183257.7,2609357..."

CarlosNantes
New Contributor III
# Get token for the request ip
curl -X POST http://domain/arcgis/tokens/generateToken -H 'content-type: application/x-www-form-urlencoded' -d "f=json&username=USER&password=PASSWORD&client=requestip&encrypted=false"

# Get token for the specified referer 
curl -X POST http://domain/arcgis/tokens/generateToken -H 'content-type: application/x-www-form-urlencoded' -d "f=json&username=USER&password=PASSWORD&client=referer&referer=http://example.com.br&encrypted=false"

# Get token for some other IP of you choice
curl -X POST http://domain/arcgis/tokens/generateToken -H 'content-type: application/x-www-form-urlencoded' -d "f=json&username=USER&password=PASSWORD&client=ip&ip=XXX.XXX.XXX.XXX&encrypted=false"
# Testing the token
0 Kudos