Generate token to query AGOL History API without using ArcGIS Python API

801
2
Jump to solution
11-10-2022 05:25 AM
Jay_Gregory
Occasional Contributor III

I would like to query my AGOL organization's History API (https://myorg.maps.arcgis.com/sharing/rest/portals/self/history) without using the ArcGIS Python API, just using Python requests library.  

My understanding is I would need to generate an admin token, and use that token to query the API.  However, I cannot figure out how to generate a token for this workflow. 

res=requests.post("https://myorg.maps.arcgis.com/sharing/rest/generateToken",params=params) returns the error: 

["POST request should not contain username and password in the query string."] 

Can someone please point me to a clear explanation of how to implement this process?

0 Kudos
2 Solutions

Accepted Solutions
John-Foster
Esri Contributor

Can you try it with this Postman REST request?

https://www.postman.com/arcgis-developer/workspace/arcgis-location-services/request/15786767-e94a9e8...

See if it works there or you get a similar error. 

--jf

View solution in original post

Jay_Gregory
Occasional Contributor III

Ah okay.  Worked in postman.  If I change my Python line from 

res=requests.post("https://myorg.maps.arcgis.com/sharing/rest/generateToken",params=params) to 

res=requests.post("https://myorg.maps.arcgis.com/sharing/rest/generateToken",data=params)

it works.  Got that from https://stackoverflow.com/questions/26615756/python-requests-module-sends-json-string-instead-of-x-w...

Thanks!

View solution in original post

2 Replies
John-Foster
Esri Contributor

Can you try it with this Postman REST request?

https://www.postman.com/arcgis-developer/workspace/arcgis-location-services/request/15786767-e94a9e8...

See if it works there or you get a similar error. 

--jf
Jay_Gregory
Occasional Contributor III

Ah okay.  Worked in postman.  If I change my Python line from 

res=requests.post("https://myorg.maps.arcgis.com/sharing/rest/generateToken",params=params) to 

res=requests.post("https://myorg.maps.arcgis.com/sharing/rest/generateToken",data=params)

it works.  Got that from https://stackoverflow.com/questions/26615756/python-requests-module-sends-json-string-instead-of-x-w...

Thanks!