Update item properties reset back to no value (null)

268
1
12-04-2019 12:51 PM
KarreemAli1
Esri Contributor

I'm building a test script that will change an item's property value (accessInformation), and then reset that property back to no value (Null) in the ArcGIS API for Python. I've tried passing None/False into the dict to update with no luck. Even a empty string would be favorable then my current workaround ("Null")

Please help.

-K

0 Kudos
1 Reply
AnttiKajanus
New Contributor III

I noticed that None or empty string doesn't make any changes to the item when updated as well. I think is due REST api behavior which has a parameter to set when clearing fields is applied (clearEmptyFields) and I cannot find that from the Python API. 

I gave it a go and tried if I can get the removing values working and it looks like following actually works. It will use the update endpoint and set description to empty. 

import requests
import json

call ='http://{}/sharing/rest/content/users/{}/items/{}/update?f=json&token={}&description=&clearEmptyFields=True'.format(
            gis.properties.urlKey + "." + gis.properties.customBaseUrl,
            gis.users.me.username, 
            copy_to_item.id,
            gis._con.token)

request = requests.post(call)
json_data = json.loads(request.text)
json_data
# {'success': True, 'id': 'db9db040d6184e989e1aac253df840cb'}

It's a bit weird that the ArcGIS Python API doesn't support this out of the box. Or if it does, it would be nice to know since I couldn't figure it out.

0 Kudos