AGOL Token String Length

1167
6
11-08-2018 08:34 AM
joerodmey
MVP Alum

Is there a fixed string length to an AGOL token or does it vary every time generateToken is called via REST?

Right now I'm using https://www.arcgis.com/sharing/rest/generateToken?f=pjson&username=MYUSERNAME&password=MYPASSWORD&re...

If not can the token, ssl, and expiry field and quotes be removed from the response?

0 Kudos
6 Replies
RandyBurton
MVP Alum

The AGOL token is a text string of consistent length.  I would use the python json module for extracting the token and other items in the response.  If you are using another method to extract the token, it will be quoted string following the word token.  If you use f=json, you will get json without formatting which may make it easier to parse.

0 Kudos
joerodmey
MVP Alum

Even with f=json I still get this:

{"token":"MYemaA7SAJJKcBjIeiGvyyvzoOlp06Q.","expires":1541711897609,"ssl":true
I'm using this response outside of python, so I don't have that option. I just want to only grab only the token without the quotes. Maybe regex or google sheets? Other ideas?
But if the string length doesn't change for the token, then I can use a substring method that is hardcoded with static start and end parameters
0 Kudos
RandyBurton
MVP Alum

Can you use an expression like mid(string, start, end)?  Or find the third " and select to the fourth ".

0 Kudos
joerodmey
MVP Alum

I'm using Integromat which has numerous string functions including substring. If the token string length doesn't change, I should be able to use that function.

0 Kudos
RonParis
Occasional Contributor

I'm hoping to rekindle this thread. Was there a solution for this? I'm having exactly the same issue whereby I want to extract the token itself, and none of the text either side of it in the response.

0 Kudos
RandyBurton
MVP Alum

While the json returned should be consistent in format, you may wish to search for "token":" and start your substring after its location.

0 Kudos