Using tokens in arcgis rest api queries

2678
2
Jump to solution
08-07-2018 12:42 PM
AhmadSALEH1
Occasional Contributor III

Hello,

I have a web page that takes a query then submits it the the ArcGIS server rest end point,

http://myserver/arcgis/rest/services/myService/MapServer/0/query 

the web page looks like the following image and I sucessfully pass the parameters and receive  the results. 

My issue is that I am reading from a secured service and every time I hit the button "Get the Map" it asks me to login   the arcgis server. 

I know that I can use a token to get the results, but unfortunately I couldn't figure out how to include it in the submit button.  

 <form name="sdform2" 

action="http://MyServer:6080/arcgis/rest/services/MyService/MapServer/1/query" 

method="post">


<tr valign="top">
<p hidden>
<td>Where:</td>
<td>
<input type="text" Name="where" Id=whereNodes value="NID=&#39;test&#39;" size="45">
</p>
<br>
<br>
 <table border=".1">
<tr align="center">
<td width="120">Title</td>



<td>
<p hidden>
<input type="text" id="outNodeFields" name="outFields" value="*" size="75">
<select name="f">
<option value="kmz">KMZ</option>
<option value="json">json</option>
</select>
</p>
</td>

<td>

<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Any help is highly appreciated. 

Thank you,

Ahmad

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

I haven't taken the approach that you have, but I would try something like the following.  You will need to log in at some point to get a token, and it will time out eventually, but you can reuse it a number of times.  If the layer is publicly shared, a token may not be required.

<form ......>

<input type="hidden" id="token" name="token" value="your token goes here">

<input type="submit" value="Submit">
</form>‍‍‍‍‍‍‍

View solution in original post

2 Replies
RandyBurton
MVP Alum

I haven't taken the approach that you have, but I would try something like the following.  You will need to log in at some point to get a token, and it will time out eventually, but you can reuse it a number of times.  If the layer is publicly shared, a token may not be required.

<form ......>

<input type="hidden" id="token" name="token" value="your token goes here">

<input type="submit" value="Submit">
</form>‍‍‍‍‍‍‍
AhmadSALEH1
Occasional Contributor III

Thank you Randy for your input, I changed my approach a little bit, and used your hint, the action link was changed to 

http://myserver/arcgis/rest/services/myservice/MapServer/0/query?where=NID=%27test%27&f=json&token=T... here

and I removed all other variables from the form.

Thank you,

Ahmad 

0 Kudos