Use ArcGIS REST API from a backend service, scripts, api proxy, cron jobs etc..

382
1
03-03-2023 01:13 AM
Jort
by
New Contributor

For a client I need to be able to add attributes to a feature server. I identified 2 endpoints that works except I don't understand how the authentication works from a internal system.

endpoint 1: POST /arcgis/rest/admin/services/<service>/FeatureServer/<layer>/addToDefinition

endpoint 2: POST arcgis/rest/services/<service>/FeatureServer/<layer>/updateFeatures

How can I authenticate these requests in a internal system like a cron job, script etc...?

I tryed the api key  but doesn't seem to work. 

I could just use https://www.arcgis.com/sharing/rest/generateToken with username and password. Store the token and refetch if expired but that doesn't seem like a best practice.

0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor

Hi Jort,

I recommend generating the token each time you are making a post request.  Python Ex:

import requests, json

# Generate Token
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
r = requests.post(tokenURL, data = params, verify=False)
response = json.loads(r.content)
token = response['token']

# Post Request
.....