Select to view content in your preferred language

Setting Sharing Level "PUBLIC" Publishing Hosted Layer Using Python

1508
5
Jump to solution
09-28-2022 11:13 AM
Labels (1)
AshadAlif1
New Contributor

 

Hi Guys, 
I have a python code to publish and overwrite a hosted feature layer to AGOL from my ArcGIS Pro project. The Problem is when i run the code to overwrite the Hosted Feature Layer with Updated Data, The Sharing Level of that Feature layer in AGOL becomes "Organization only". I need to go to the AGOL organization and manually i need to set the sharing level to Public every time. Since i am using that layer for a public web map and Web App , the layer needs to be public. My codes are as following:

 

# Create FeatureSharingDraft and set overwrite property
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.overwriteExistingService = True
sddraft.credits = "These are credits"
sddraft.description = "This is description"
sddraft.summary = "This is summary"
sddraft.tags = "tag1, tag2"
sddraft.useLimitations = "These are use limitations"
sddraft.portalFolder = "01 My DevOps"
sddraft.allowExporting = False
sddraft.enable_sync = True
print("~~Metadata Updated Done~~ Overwrite Enabled")


# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
print("SD draft File Creation Done")


# Stage Service
print("Staging Started ...")
sddraft.overwriteExistingService = True
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
print("~~Staging Done~~")

# Share to portal
print("Uploading Started...")
arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)

print(" Done! ~~ Hosted Layer Re - Published ~~Congrats")

 

I assume if inthe sddraft  there could be a function to solve this. I did not find any documentation on this searching the ArcGIS Python documentation or arcpy. Is there a Solution?

My Goal is to overwrite the hosted feature layer as a publicly shared feature layer. 

--best

Ashad

0 Kudos
1 Solution

Accepted Solutions
JonahLay
Esri Contributor

Hi @AshadAlif1,

You can use the Upload Service Definition tool to set the sharing settings. There is also a way to set sharing in the sddraft by modifying the XML file. We are working on documenting how to do this in the help topics at an upcoming release.

Best,

Jonah

View solution in original post

5 Replies
JonahLay
Esri Contributor

Hi @AshadAlif1,

You can use the Upload Service Definition tool to set the sharing settings. There is also a way to set sharing in the sddraft by modifying the XML file. We are working on documenting how to do this in the help topics at an upcoming release.

Best,

Jonah

AshadAlif1
New Contributor

Hi @JonahLay 

Thanks for the help. I was able to sort it out with documentation you shared.

best
Ashad

0 Kudos
MattCashen
Regular Contributor

Hi @JonahLay ,

Is there a way to accomplish this if you are sharing this to your own Portal?  I noticed in the Upload Service Definition documentation that it says the Share with Everyone parameter will not be honored if you're sharing to ArcGIS Server.   I'm guessing this is why even if I set these parameters my locator I'm overwriting isn't shared with everyone after the script completes.  Is there a way to make this work on ArcGIS server? 

0 Kudos
MarkMankins
Emerging Contributor
0 Kudos
NicolasRojas
Occasional Contributor

Unfortunetly the question that you are linking has no solution whereas this one does and is exactly what the user was asking for (and also me hehe).

-N
0 Kudos