I am trying to use the GenerateToken endpoint to generate a token for my AGOL user account, from which I can subsequently perform a GET request on a FeatureLayer that is hosted in AGOL and shared with my user account.
I'm successfully receiving a token from the following URL via POST request as indicated via docs
I then try to perform a GET request for my FeatureLayer, using the URL below and passing through the token I received from the previous POST
Unfortunately the response is {"error":{"code":498,"message":"Invalid token.","details":["Invalid token."]}}
I can confirm that I have permission to view the FeatureLayer, as I can log into AGOL via the same credentials and view the feature layer. When I click view, AGOL generates it's own token and if I was to use that token via
The expiry time of the token being returned is 2 hours from my current time.
Am I correct in assuming the token returned via /GenerateToken should enable me to perform GET requests on FeatureLayers/Services?
I'm not sure what else to try as there is minimal information in the error code.
Note: I cannot use the oAuth2 process here, hence using GenerateToken. Reason why is I'm writing some python scripts to automate some processing of data, and I need to have user credentials hard coded into the scripts.
what does your GET request look like / how are you sending the token?
I don't see in your request where you are including the token "...<featurelayer>/FeatureServer?f=json..."; but perhaps you are.
It looks like you might also be missing the layer id and the type of request. Here's my suggestion for the format:
https://services1.arcgis.com/<account info>/arcgis/rest/services/<feature layer name>/FeatureServer/<layerid>/query?where=&outFields=*&f=json&token=<token>
I'm also not sure if your token request is actually a post request as it looks like you may be appending your username and password to the url as in a get request. Difference between GET and POST method in HTTP I suggest you consider using only post requests for security.
I am having the same issue. I am generating the access token using generateToken REST API via POST. And then trying to access the secure folder using https://xxxxx/arcgis/rest/services/OSvC/?f=json&token=. But getting 'Invalid Token' error. I can access the same folder through the browser by manually providing the credentials to the rest/login page.