Select to view content in your preferred language

How to update a csv item in ArcGIS Online without using arcgis methods? (REST API)

775
1
Jump to solution
06-21-2021 01:39 PM
ChristianBischof
Esri Contributor

Hi,

I need to update a csv item in an ArcGIS Online Organization. For some reasones I need to do it without using arcgis python module.

The idea is basically to generate a token and update the item by using the python requests library (or urllib). Somehow I cannot make it work with the requests lib.

Help is appreciated!
Thanks in advance folks 🙂

 

token = arcpy.GetSigninToken()

url="https://myorganization.arcgis.com/sharing/rest/content/users/username/9d0a35bf33c24f289e626b51f9asdf4578/items/123456782345678itemId/update"

payload={
    'description': 'Rest Test',
    'overwrite': 'true',
    'async': 'true',
    'token': token['token'],
    'title': 'RestTestFile',
    'name': 'RestTestFile.csv',
    'type': 'CSV',
    'tags': 'RestTest',
    'typeKeywords': 'CSV'}
    files={
        'file': ('RestTestFile.csv', open(file_path_variable,'rb'), 'text/csv')
    }

# two kinds of requests with requests library
response = requests.request("POST", url, data=payload, files=files)
r = requests.post(url, data=payload, files=files)

 

0 Kudos
1 Solution

Accepted Solutions
ChristianBischof
Esri Contributor

Stupid me got it, just forgot the 'f' parameter -> set to JSON in this sample. Anyway wanted to provide you my solution.

token = arcpy.GetSigninToken()

url="https://myorganization.arcgis.com/sharing/rest/content/users/username/9d0a35bf33c24f289e626b51f9asdf4578/items/123456782345678itemId/update"

payload={
    # THIS PARAMETER MADE THE DIFFERENCE
    'f': 'json',
    'description': 'Rest Test',
    'overwrite': 'true',
    'async': 'true',
    'token': token['token'],
    'title': 'RestTestFile',
    'name': 'RestTestFile.csv',
    'type': 'CSV',
    'tags': 'RestTest',
    'typeKeywords': 'CSV'}
    files={
        'file': ('RestTestFile.csv', open(file_path_variable,'rb'), 'text/csv')
    }

# two kinds of requests with requests library
response = requests.request("POST", url, data=payload, files=files)
r = requests.post(url, data=payload, files=files)

View solution in original post

1 Reply
ChristianBischof
Esri Contributor

Stupid me got it, just forgot the 'f' parameter -> set to JSON in this sample. Anyway wanted to provide you my solution.

token = arcpy.GetSigninToken()

url="https://myorganization.arcgis.com/sharing/rest/content/users/username/9d0a35bf33c24f289e626b51f9asdf4578/items/123456782345678itemId/update"

payload={
    # THIS PARAMETER MADE THE DIFFERENCE
    'f': 'json',
    'description': 'Rest Test',
    'overwrite': 'true',
    'async': 'true',
    'token': token['token'],
    'title': 'RestTestFile',
    'name': 'RestTestFile.csv',
    'type': 'CSV',
    'tags': 'RestTest',
    'typeKeywords': 'CSV'}
    files={
        'file': ('RestTestFile.csv', open(file_path_variable,'rb'), 'text/csv')
    }

# two kinds of requests with requests library
response = requests.request("POST", url, data=payload, files=files)
r = requests.post(url, data=payload, files=files)