Select to view content in your preferred language

getWebLayerSharingDraft - sharing to a group?

840
2
03-09-2025 10:09 PM
MicZatorsky_AEC
Frequent Contributor

Does anyone know of a problem or bug getting getWebLayerSharingDraft to share to a defined group on ArcGIS Online using arcpy, as shipped with ArcGIS Pro 3.4.2.

My code effectively has a single group:

sddraft.sharing.groups = "Flood Modeling - Working GP"

The service is being successfully published, but it has not been shared with the specified group. I'm not seeing any errors or warnings.

Is there a bug?  A problem with spaces or hyphens?  Does it need to be a Python list?   Are any other parameters causing a conflict? Unicode?

If the service exists, the overwriting is honoured, but the new item is effectively unshared when the overwrite occurs.

Here is a snippet of my code :

 

 

 

 

# Set publishing metadata and parameters
    service_type = "FEATURE"
    service_name = map_name

    credits = "X, Y"
    description = f"{map_name}.IFC"
    summary = f"Published by MZ {timestamp}"
    tags = "TEST"
    useLimitations = "None"
    portalFolder = "IFC_FL"
    featureCapabilities = "Query"
    useCIMSymbols = False  # most compatabile
    sharingLevel = "OWNER"
    groups = "Flood Modeling - Working GP"
    offline = True
    offlineTarget = "ONLINE"
    overwriteExistingService = True

    try:
        aprx = arcpy.mp.ArcGISProject(aprx_path)
        map_obj = aprx.listMaps(map_name)[0]
        sddraft = map_obj.getWebLayerSharingDraft(server_type, service_type, service_name)

        # update sdraft parameter values
        sddraft.credits = credits
        sddraft.description = description
        sddraft.summary = summary
        sddraft.tags = tags
        sddraft.useLimitations = useLimitations
        sddraft.portalFolder = portalFolder
        sddraft.featureCapabilities = featureCapabilities
        sddraft.useCIMSymbols = useCIMSymbols
        sddraft.sharing.sharingLevel = sharingLevel
        sddraft.sharing.groups = groups
        sddraft.offlineTarget = offlineTarget
        sddraft.overwriteExistingService = overwriteExistingService
        sddraft.offline = offline

        # Export, Stage & Upload
        sddraft.exportToSDDraft(sddraft_path)
        arcpy.server.StageService(sddraft_path, sd_path)
        arcpy.server.UploadServiceDefinition(sd_path, server_type)

 

 

 

 

 

0 Kudos
2 Replies
BeheerderCRE
New Contributor

Hi,

Have you found a solution for this? I have a similar problem where the feature layer is indicated as being within the group, but when the map is opened, the featurelayer does not load.

The feature layer is only displayed for admin users. Subsequent adjustments to permissions also have no effect. The code is below.

I am using Pro 3.6.0

import arcpy
import os

# Sign in to portal
arcpy.SignInToPortal()

# Set output file names
outdir = r"P:\Tekening-ArcGIS\CRE online portal\ArcGIS projecten voor AGO kaarten\Kabels en leidingen totaal OPENBAAR AGO\Output"
service_name = "Kabels_en_leidingen_openbaar_WFL1"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

# Reference map to publish
#Past hieronder locatie van project aan
aprx = arcpy.mp.ArcGISProject(r"P:\Tekening-ArcGIS\CRE online portal\ArcGIS projecten voor AGO kaarten\Kabels en leidingen totaal OPENBAAR AGO\Kabels en leidingen totaal OPENBAAR AGO.aprx")
m = aprx.listMaps('Map')[0]

# Create FeatureSharingDraft and set overwrite property
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.credits = "These are credits"
sddraft.description = "Kabels en leidingen data van de TU Delft Campus."
sddraft.summary = "Kabels en leidingen totaal overzicht binnen de TU Delft campus. Deze kaart geeft een beperkte weergaven van de details van objecten in de pop-up."
sddraft.tags = "riool, persleiding, vuilwater, hemelwater ,grondwater, oppervlaktewater, gemengd riool, WKO, MS, Laagspanning, Data, Water,Gas"
sddraft.useLimitations = "These are use limitations"
sddraft.portalFolder = "Kabels en leidingen Openbaar"
sddraft.featureCapabilities = "Extract"
sddraft.useCIMSymbols = True
sddraft.sharing.sharingLevel = "ORGANIZATION"
sddraft.sharing.groups = "Home pagina - aanbevolen content" # Group names = "group1,group2"
sddraft.overwriteExistingService = True

# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)

# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)

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

print("Finish Publishing")

 

0 Kudos
BeheerderCRE
New Contributor

I have found the solution. The credits and limitation need to be set to "None". That way, the Feature Layers will load.

Create FeatureSharingDraft and set overwrite property
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.credits = "None"
sddraft.description = "Kabels en leidingen data van de TU Delft Campus."
sddraft.summary = "Kabels en leidingen totaal overzicht binnen de TU Delft campus. Deze kaart geeft een beperkte weergaven van de details van objecten in de pop-up."
sddraft.tags = "riool, persleiding, vuilwater, hemelwater ,grondwater, oppervlaktewater, gemengd riool, WKO, MS, Laagspanning, Data, Water,Gas"
sddraft.useLimitations = "None"
sddraft.portalFolder = "Kabels en leidingen Openbaar"
sddraft.featureCapabilities = "Extract"
sddraft.useCIMSymbols = True
sddraft.sharing.sharingLevel = "ORGANIZATION"
sddraft.sharing.groups = "Home pagina - aanbevolen content" # Group names = "group1,group2"
sddraft.overwriteExistingService = True

0 Kudos