Skip To Content

Upload Service Definition

Summary

Uploads and shares a hosted web layer to ArcGIS Online or ArcGIS Enterprise.

Usage

  • This tool uploads and shares a web layer based on the input service definition. Whenever you share a web layer using ArcGIS Pro, this tool is run, and you will see an entry in the Geoprocessing History item in the Catalog pane.

  • This tool does not upload and share service definition draft (.sddraft) files. If you have a service definition draft, you can convert it to a staged service definition by using the Stage Service tool.

Syntax

UploadServiceDefinition_server (in_sd_file, in_server, {in_service_name}, {in_cluster}, {in_folder_type}, {in_folder}, {in_startupType}, {in_override}, {in_my_contents}, {in_public}, {in_organization}, {in_groups})
ParameterExplanationData Type
in_sd_file

The service definition (.sd) contains all the information needed to share a web layer.

File
in_server

You can use ArcGIS Server connections listed under the Servers node in the Project window, or you can browse to a different folder where server connection files are stored.

Enter My Hosted Services for the server connection, with each word capitalized and a space between each word.

ServerConnection
in_service_name
(Optional)

Use this option to override the service name currently specified in the service definition with a new name.

String
in_cluster
(Optional)

Use this option if you want to change the cluster to which the service has been assigned. You must choose from clusters that are available on the specified server.

String
in_folder_type
(Optional)

The folder type used to determine the source for the folder. The default is to get a folder from the service definition. You can also choose to get a list of folders already existing on the specified online server, or you can specify a new folder to be created once you share this web layer.

  • NEWCreates a new folder.
  • EXISTINGSpecifies a folder that exists on the server.
  • FROM_SERVICE_DEFINITIONThe folder already specified in the service definition. This is the default.
String
in_folder
(Optional)

Use this option to specify the folder for the web layer. The default is to use the folder specified in the service definition. If you chose New folder type, use this parameter to enter a new folder name. If you chose Existing folder type, you can choose from the existing folders on the server.

String
in_startupType
(Optional)

Use this option to determine the start or stop state of the service immediately after sharing.

  • STARTEDThe service starts immediately after sharing.
  • STOPPEDThe service does not start after sharing. You will need to start the service manually.
Boolean
in_override
(Optional)

Use this parameter if you want to override the sharing properties set in the service definition. These properties define if, and how, you are sharing your service with ArcGIS Online or ArcGIS Enterprise. Sharing your web layer exposes it for others to use.

  • OVERRIDE_DEFINITIONOverride the sharing properties set in the service definition with new values.
  • USE_DEFINITIONThe sharing properties currently set in the service definition will be used when the web layer is shared. This is the default.

You must be logged in to ArcGIS Online or ArcGIS Enterprise to override sharing properties.

Boolean
in_my_contents
(Optional)

All shared web layers are available through My Content. Even if you only want to share with a specific group in your organization, the web layer will also be shared through My Content.

  • SHARE_ONLINEShares the web layer on ArcGIS Online or ArcGIS Enterprise. The web layer will be listed under My Content.
  • NO_SHARE_ONLINEThe web layer will not be shared on ArcGIS Online or ArcGIS Enterprise and will be inaccessible to other ArcGIS Online or ArcGIS Enterprise users and clients on the web.

You must be logged in to a portal to override sharing properties.

Boolean
in_public
(Optional)

Choose whether or not your service will be available to the public.

  • PUBLICShare the web layer with the public.
  • PRIVATEDo not share the web layer with the public.

You must be logged in to ArcGIS Online or ArcGIS Enterprise to override sharing properties.

Boolean
in_organization
(Optional)

You can share your web layer with your organization.

  • SHARE_ORGANIZATIONShare the web layer with your organization.
  • NO_SHARE_ORGANIZATIONDo not share the web layer with your organization.

You must be logged in to ArcGIS Online or ArcGIS Enterprise to override sharing properties.

Boolean
in_groups
[group_name,...]
(Optional)

A list of group names with which to share the web layer.

You must be logged in to ArcGIS Online or ArcGIS Enterprise to override sharing properties.

String

Code sample

The following script publishes a list of layers from a map as a web tile layer to either ArcGIS Enterprise or ArcGIS Online. Portal information is obtained from the Portals page in ArcGIS Pro.

import arcpy, os

# Set output file names
outdir = r"C:\Project\Output"
service = "TileSharingDraftExample"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps("World")[0]
lyrs = []
lyrs.append(m.listLayers('cities')[0])
lyrs.append(m.listLayers('counties')[0])

# Create TileSharingDraft and set service properties
sharing_draft = m.getWebLayerSharingDraft("HOSTING_SERVER", "TILE", service, lyrs)
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My Tags"
sharing_draft.description = "My Description"
sharing_draft.credits = "My Credits"
sharing_draft.useLimitations = "My Use Limitations"

# Create Service Defintion Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)

# Stage Service
sd_filename = service + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Uploading Service Definition...")
arcpy.UploadServiceDefinition_server(sd_output_filename, "My Hosted Services")

print("Successfully Uploaded service.")

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • ArcGIS Desktop Basic: Yes
  • ArcGIS Desktop Standard: Yes
  • ArcGIS Desktop Advanced: Yes

Related topics