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?
Might give this method a try arcgis.gis.Item.share when you upload it.
Should be something like youritem.share(everyone=True)
Thanks. Would my item be the service ID? I tried service name, but it won't accept a string.
... 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"})
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"})
Is anyone able to update these settings with Python?
I will open a support ticket on this
I have the same issue. It always sets sharing to 'private'.
@LeviCecil has there been any update on your ticket?
Thanks!
Chris
I did not end up opening a ticket, as I stopped regular updates of the locator.
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