AnsweredAssumed Answered

Using a token to access AGOL data

Question asked by dogdaynoon on Jun 20, 2018
Latest reply on Sep 18, 2018 by geofyadmin

I would like to run a python script to access and update a table that is part of a feature service in AGOL. 

I am successful in retrieving a token but I am having a hard time finding any documentation on how to use that token to access the data in AGOL. 

The examples that I have seen only use a username/password combination to access data. This does not work to access an endpoint to a specific layer.


Any help or an example would be much appreciated. I am essentially  lost at line 21...

from arcgis.gis import GIS
import requests
from arcgis.features import FeatureLayerCollection
client_id = "My App ID from AGOL"
client_secret = "My Client Secret from App in AGOL"
def get_token(client_id, client_secret):
params = {'client_id': client_id,
'client_secret': client_secret,
'grant_type': "client_credentials"
request = requests.get('', params=params)
response = request.json()
token = response["access_token"]
return token
token = get_token(client_id, client_secret)
token_params = {
'f': 'json',
'token': token
service_url = ""
#data =, params=token_params)
gis = GIS(service_url + token)
lyr_result ='title:StormGateInfo')