Skip to content

Instantly share code, notes, and snippets.

@khibma
Created May 4, 2020 13:36
Show Gist options
  • Save khibma/e17c30f55b591c26f8557b4a44f64bed to your computer and use it in GitHub Desktop.
Save khibma/e17c30f55b591c26f8557b4a44f64bed to your computer and use it in GitHub Desktop.
Example that uses ArcGIS Python API to authenticate, but uses Requests to make calls to the backend REST service directly.
from arcgis.gis import GIS
import requests
import json
USER = "USER"
PASS = "PASSWORD"
g = GIS("https://www.arcgis.com", USER, PASS)
token = g._con.token
payload = {"where": "1=1",
"f":"json",
"token": token}
url = "https://services1.arcgis.com/orgID/ArcGIS/rest/services/p5000/FeatureServer/0"
p = {**payload, **{"returnCountOnly": "true"}}
response = requests.post(url + "/query", data = p)
r = json.loads(response.text)
print("Count before: {}".format(r))
p = {**payload, **{"async": "false"}}
response = requests.post(url + "/truncate", data = p)
r = json.loads(response.text)
print("Result of delete: {}".format(r))
p = {**payload, **{"returnCountOnly": "true"}}
response = requests.post(url + "/query", data = p)
r = json.loads(response.text)
print("Count after: {}".format(r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment