Search code examples
python-2.7python-requestsesri

Updating ESRI Rest services with post


I am atempting to post a new url to a service on ESRI (I own it) with a post using Requests. After printing the line post_url the JSON is updated as I want it however when I post it nothing happens despite getting a 200 status. Is the issue with the post or the find / replace?

json_url = "https://www.arcgis.com/sharing/rest/content/items/serviceID?&token=XXX"
update_url = "https://www.arcgis.com/sharing/rest/content/users/USERNAME/folder/items/ServiceNumber/update?"

get_json = requests.get(json_url)
load_json = str(get_json.json())


find = "findme"
replace = "replace"

post_url = load_json.replace(replace, find)


a = requests.post(update_url, data={"url": post_url, "token": "XXXX", "f":"json"})
print a.status_code

Solution

  • The issue is with the post

    I changed the post to this: requests.request("POST", update_url, data={"url": post_url, "token": token, "f":"json"})

    update_url needs to be the API update endpoint: https://www.arcgis.com/sharing/rest/content/users/USERNAME/FOLDER/items/Endpoint /update?"

    post_url needs to be: "whatever you want" in my case It was a search and replace variable of the the existing URL in the JSON and update, because of a server migration.