Generating token for ArcGIS Online hosted service

29297
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

22 Replies
Jay_Gregory
Occasional Contributor III

Did you ever solve this - getting the same issue.

0 Kudos
ArthurXiao
New Contributor II

Thank you @RamunasKraujutis for your post and I can generate token now, but the token is cut off which is shorter than the one got from URL after sign in , so when use it to query got failed message "Invalid Token". So do you know why the token is cut off? Thanks.

0 Kudos
iHack
by
New Contributor III

Hello @RamunasKraujutis,

I was referred to this thread by @IsmaelChivite

I'm trying this method in order to obtain a token; so, I may update a feature layer in Make (formerly Integromat).  I seem to be getting a token in the output data of my generateToken request; however, I would like to know how to pass the token generated from this output to my updateFeatures HTTP Make a request module.

I selected the output Data field from the generateToken request to be used as the token field value in the subsequent updateFeatures request; but, it seems to insert the full response with all of the parameters from the generateToken request.  I just need to pull the one token parameter from the previous generateToken request into the token field for the following updateFeatures request.

Does anyone know how this can be done?

 

Thanks

0 Kudos
iHack
by
New Contributor III

@RamunasKraujutis  I selected the Parse response (fig. 1) in the generateToken request.  It is now pulling the token into the updateFeature token field input; however, I'm getting an error for the output (fig. 2):

Data
{"error":{"code":498,"message":"Invalid token.","details":["Invalid token."]}}
 
fig. 1
iHack_0-1670273747492.png
 
fig. 2
iHack_1-1670273780340.png

 

Do you think the ArcGIS Online security settings for the user whose credentials are being used to generate the token have anything to do with this.  For example, do they need to be an administrator?

0 Kudos
iHack
by
New Contributor III

I was able to resolve this issue of receiving the error code {"error":{"code":498,"message":"Invalid token.","details":["Invalid token."]}} in Make [formerly known as Integromat], which is mentioned by others in this thread; but, I had not seen a resolution for it.

Methodology:

  • Generate Token HTTP Request Module:
    • Module Configuration:
    • Added HTTP Make a Request Module to generateToken before updateFeature HTTP Make a Request Module
  • Update Features HTTP Request Module:
    • Used URL to secured feature layer
    • Set field Key to token; value to parsed token data output of the Generate Token module

 

The main thing that made a difference for me in generating a token that would not cause the error was to set the client parameter to refer instead of requestip; then set the refer parameter to the base URL of the feature layer that I'm updating.

0 Kudos
AppmartIntegrated
New Contributor

I can get the token, but when I try to use it for actions like adding to a feature layer (applyedits) it keeps saying,

{"error":{"code":498,"message":"Invalid token.","details":["Invalid token."]}}

 

iHack
by
New Contributor III

@AppmartIntegrated 

I'm not sure if this will help you; but, I had a similar issue that was resolved by setting the client parameter to referer; and setting the referer parameter to my feature service's base URL, which in your case may be  https://services3.arcgis.com/ViXXHj2TcfxwEXHV.

This reference was useful for me:

https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm

0 Kudos
RamunasKraujutis
New Contributor III

@ArthurXiaoif you generated your token from one IP address and trying to use from different IP address, then it's normal, that you get "Invalid token" error. Also, there is no problem with "." (dot) at the end of token.

 

Please see documentation at https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm and check other options when generating token.

 

 

0 Kudos
ArthurXiao
New Contributor II

Thank you for your response.

I used "requestip" for parameter "client", so looks is not the problem of client IP. Do you mean I requested token from "https://www.arcgis.com/sharing/rest/generateToken?" but used to query service on "https://services3.arcgis.com/ViXXHj2TcfxwEXHV/arcgis/rest/services/"?
If that's the case, then how to request token from "https://services3.arcgis.com"? I tried 

https://services3.arcgis.com/sharing/rest/generateToken?
https://services3.arcgis.com/generateToken?
https://services3.arcgis.com/sharing/generateToken?

But none of them works.

The link you pointed to is for portal, but we tried to get token from ArcGIS online.

Any idea will be appreciated.

0 Kudos
RamunasKraujutis
New Contributor III

"/rest/info?f=json" (in your case - https://services3.arcgis.com/ViXXHj2TcfxwEXHV/arcgis/rest/info?f=pjson ) gives information where tokens should be generated (https://www.arcgis.com/sharing/generateToken).

0 Kudos