Select to view content in your preferred language

How to Update Portal Sharing Settings in Python

3370
13
02-04-2021 09:19 AM
LeviCecil
Frequent Contributor

I have a script that updates geocoders every month and publishes them to our enterprise portal. When this happens I have to manually change the sharing settings to "everyone" for it to be accessible in our public school finder. If I forget to to do this, I get emails saying that the app is asking users to log into the portal. Is there a way to set the sharing settings for a service in Python? 

0 Kudos
13 Replies
by Anonymous User
Not applicable

Might give this method a try arcgis.gis.Item.share when you upload it.

Should be something like youritem.share(everyone=True)

0 Kudos
LeviCecil
Frequent Contributor

Thanks. Would my item be the service ID? I tried service name, but it won't accept a string. 

0 Kudos
by Anonymous User
Not applicable

... might have gotten tripped up on 'item' and what what it is according to the Docs description.  If you are uploading layers, maybe the update method's item_properties parameter is where to set it.

yourItem.update(item_properties={"access" : "public"})

0 Kudos
LeviCecil
Frequent Contributor

Revisiting this issue. I'm following the docs, but it's not working. I run these lines at the end of my script, but the service still says "The Item is not shared" in the portal. 

portal = GIS("https://<ourserver>/arcgis", "user", "password")
locator = portal.content.get('<itemID>')
locator.update(item_properties={"access" : "public"})

 

0 Kudos
LeviCecil
Frequent Contributor

 Is anyone able to update these settings with Python?

0 Kudos
LeviCecil
Frequent Contributor

I will open a support ticket on this

0 Kudos
ChrisSchreiber
Occasional Contributor

I have the same issue. It always sets sharing to 'private'. 

@LeviCecil has there been any update on your ticket? 

 

Thanks!

 

Chris

0 Kudos
LeviCecil
Frequent Contributor

I did not end up opening a ticket, as I stopped regular updates of the locator. 

0 Kudos
ChrisSchreiber
Occasional Contributor

Thanks for the reply @LeviCecil ! 

 

I found a work around using the "shareItems" call. 

Here is my code:

#get the token from the 'gis' object
token = gis._con.token
#build the URL
url = '{0}/sharing/rest/content/users/<userWhoOwnsItem>/shareItems?f=json&token={1}'.format(gis.url, token)
#using the Python 'Requests" module, send the request to the REST API directly.
updateSharing = requests.post(url, data={"items": "<id(s) go here>", "org": "true"})

I hope this helps someone! 

 

Chris