Issues updating portal items with a python script

1050
4
04-22-2020 09:22 AM
MichaelHamsa
Occasional Contributor

Hello,

I've got a file geodatabase and a hosted feature layer published to our portal and we are trying to update the file geodatabase with a python script - something similar to this.

gis = GIS(portal, user, password)
sdItem = gis.content.search(query="title:" + item_name, item_type="File Geodatabase")[0]
print("Found SD: {}, ID: {} \n Uploading and overwriting...".format(sdItem.title, sdItem.id))
sd = "path-to-zip-file"
sdItem.update(data=sd)
fs = sdItem.publish(overwrite=True)
print("Complete!")

The items being updated by the script are not owned by the account (user/password) used to connect in this script. We've got a group setup in the portal, and group members are allowed to update all items. The account being used to connect in the script is a member of this group. The items we are attempting to update are in the group as well.

sditem.Update works.

sdItem.publish fails with this error:

You do not have permissions to access this resource or perform this operation.

Any ideas on how we can fix this?

mike...

0 Kudos
4 Replies
RachelSears
Occasional Contributor II

Hello Mike!

Unfortunately, the allow update capability granted by your group membership only applies to updating the item (for example, changing the metadata or directly editing the content). It does not give you permission to overwrite the hosted feature layer, which is why the script is returning the error. It is not an issue with the Python API; if you were to attempt to overwrite the layer manually using a desktop application such as ArcGIS Pro, you would have similar issues. 

Share items—Portal for ArcGIS | Documentation for ArcGIS Enterprise 

Hope this helps.

Rachel

0 Kudos
MichaelHamsa
Occasional Contributor

Thank you for the response – I guess the description is a little misleading.

Here’s what the group permissions say:

What items in the group can its members update? Members can update all items, including changing the item's description and content. This ability was defined when the group was created and can't be modified. Group membership is limited to the organization.

So at this point only the owner of an item can update the content?

Mike Hamsa

Chief Technology Officer - GeoSpatial Innovations, Inc.

P: 512-982-6735

0 Kudos
RachelSears
Occasional Contributor II

Hello Mike,

The documentation I linked above says this about the group permissions:

However, only the owner of the item or a portal administrator can perform the following actions on the item (not all actions apply to all item types): delete, share, move, change owner, change delete protection, publish, register an app, overwrite data in hosted feature layers, and manage tiles in hosted tile layers.

Unfortunately, at this time it seems that only an Administrator or Item Owner can overwrite the layer.

You are still able to "update" the content, but that means editing the features/attribute table; not overwriting. This can also be done with the Python API. You can loop through both datasets to determine what has changed, and update those records accordingly. It requires a few more steps and is a bit more complicated, but I found a sample script that walks you through an example workflow:

Updating features in a feature layer | ArcGIS for Developers 

0 Kudos
MichaelHamsa
Occasional Contributor

Thank you very much for the additional details. Exactly what I needed!

Mike Hamsa

Chief Technology Officer - GeoSpatial Innovations, Inc.

P: 512-982-6735

0 Kudos