RE: Trying to identify correct call to generate token to access feature layer

522
4
Jump to solution
08-02-2021 03:27 PM
Labels (1)
GreggTurnbull
New Contributor II

I am attempting to make a call against a FeatureLayer:

https://services.arcgis.com/4Y5FNypV9g2Wgf92/ArcGIS/rest/services/mobilehomes07232021/FeatureServer/...

 

I can generate a token using python:

import requests
tokenurl = "https://larimer.maps.arcgis.com/sharing/generateToken/"
data = {'f':'json','username':'username','password':'password','client':'referrer'}
r = requests.post(tokenurl, data=data)
return r.json()

When I attempt to make the service call above I get the 498, invalid token error.

I've tried this with token url set to our portal home (as above) and https://www.arcgis.com/sharing/generateToken. both tokens still fail to make the call.

Any help would be greatly appreciated.

0 Kudos
1 Solution

Accepted Solutions
Peter_Klingman
Esri Regular Contributor

Hi @GreggTurnbull - taking a second look it looks like you're missing the referer parameter from your data dictionary since you have client:referer. If you add 'referer: https://larimer.maps.arcgis.com' to data{} I expect this will work. 

Also I think you may need to spell referer with one 'r' to specify the right parameter: https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm

Thanks,

-Peter

 

View solution in original post

0 Kudos
4 Replies
Peter_Klingman
Esri Regular Contributor

Hi @GreggTurnbull do you see the same result from https://www.arcgis.com/sharing/rest/generateToken - it looks like the /rest portion was omitted from the URLs. 

Thanks,

-Peter 

GreggTurnbull
New Contributor II

Good morning Peter - It appears it works without the rest sub as well, but I reran the call:

https://www.arcgis.com/sharing/rest/generateToken/?f=json // along with credentials in the body, received an updated token,

Made the call:
https://services.arcgis.com/4Y5FNypV9g2Wgf92/ArcGIS/rest/services/mobilehomes07232021/FeatureServer/...

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

Am I generating the token on the right server, I've tried: www.arcgis.com and our portal larimer.maps.arcgis.com.

Again thank you for the insights.

0 Kudos
Peter_Klingman
Esri Regular Contributor

Hi @GreggTurnbull - taking a second look it looks like you're missing the referer parameter from your data dictionary since you have client:referer. If you add 'referer: https://larimer.maps.arcgis.com' to data{} I expect this will work. 

Also I think you may need to spell referer with one 'r' to specify the right parameter: https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm

Thanks,

-Peter

 

0 Kudos
GreggTurnbull
New Contributor II

That was it Peter - did have one more hiccup as I had to remove the reference to client=requestip in the token generation step, client should be set to referer .. or omitted. 

Cheers and Thank you!