Setting Sharing Level "PUBLIC" Publishing Hosted Layer Using Python

90
2
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

2 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