Upload Service Definition (Server)

Summary

Uploads and shares a web layer, locator, web tool, or service to ArcGIS Online, ArcGIS Enterprise, or ArcGIS Server.

Usage

  • This tool uploads and shares a web layer, locator, web tool, or service based on the input service definition.

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

  • Web tools can only be shared to ArcGIS Enterprise. Geoprocessing services can only be published to ArcGIS Server.

  • Locators can only be shared to ArcGIS Enterprise. Geocode services can only be published to ArcGIS Server.

Parameters

LabelExplanationData Type
Service Definition

The service definition file (.sd) that contains all the information needed to share a web layer, web tool, or service.

File
Server

The server type. The following server types are supported:

  • My Hosted Services—Use when sharing a hosted web layer to ArcGIS Online or ArcGIS Enterprise. Enter My Hosted Services for the server connection. Capitalize the first letter of each word and include a space between each word.
  • HOSTING_SERVER—Use when sharing a hosted web layer to ArcGIS Online or ArcGIS Enterprise.
  • URL to the ArcGIS Enterprise portal federated server—Use when sharing a web tool or map image layer to an ArcGIS Enterprise portal federated server.
  • ArcGIS Server connection—Use when sharing a map or geoprocessing service to ArcGIS Server. You can use ArcGIS Server connections listed under the Servers node in the Project window, or you can browse to a folder where server connection files are stored.
  • URL to ArcGIS Server—Use when sharing a map or geoprocessing service to ArcGIS Server. You can specify the URL to ArcGIS Server provided a publisher connection to ArcGIS Server has been added to the ArcGIS AllSource project, and you're opening the project in the script or you're running the tool in ArcGIS AllSource.

ServerConnection
Service Name
(Optional)

The service name that will override the current service name specified in the service definition.

String
Cluster
(Optional)

The cluster name that will override the current cluster to which the service has been assigned. You must choose from clusters on the specified server.

Legacy:

Clusters are deprecated at ArcGIS Enterprise 10.5.1. This parameter will be ignored for servers that do not support multiple clusters.

String
Folder Type
(Optional)

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

  • NewA new folder will be created.
  • ExistingAn existing folder on the server will be used.
  • From Service DefinitionThe folder in the service definition will be used. This is the default.
String
Folder
(Optional)

The folder that will be used for the web layer or service. If no folder is provided, the folder specified in the service definition will be used. If you specified New for Folder Type, use this parameter to provide a folder name. If you specified Existing for Folder Type, you can choose from the existing folders on the server.

String
Start service immediately
(Optional)

Specifies whether the service will be started after sharing.

  • Checked—The service will be started after sharing. This is the default.
  • Unchecked—The service will not be started after sharing.
Boolean
Override service definition sharing properties
(Optional)

Specifies whether the sharing properties set in the service definition will be overridden. These properties define if, and how, you are sharing the web layer or web tool with ArcGIS Online or ArcGIS Enterprise. Sharing the web layer exposes it for others to use.

  • Checked—The sharing properties set in the service definition will be overridden.
  • Unchecked—The sharing properties set in the service definition will not be overridden; they will be used. This is the default.

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

This parameter is not honored when sharing to ArcGIS Server.

Boolean
Share on ArcGIS Online
(Optional)

Specifies whether web layers and web tools will be shared.

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

  • Checked—The web layer or web tool will be shared on ArcGIS Online or ArcGIS Enterprise. The web layer or web tool will be listed under My Content.
  • Unchecked—The web layer or web tool 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. This is the default.

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

This parameter is not honored when sharing to ArcGIS Server.

Boolean
Share With Everyone (Public)
(Optional)

Specifies whether the web layer or web tool will be available to the public.

  • Checked—The web layer or web tool will be available to the public.
  • Unchecked—The web layer or web tool will not be available to the public. This is the default.

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

This parameter is not honored when sharing to ArcGIS Server.

Boolean
Share With Your Organization
(Optional)

Specifies whether the web layer or web tool will be shared with your organization.

  • Checked—The web layer or web tool will be shared with your organization.
  • Unchecked—The web layer or web tool will not be shared with your organization. This is the default.

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

This parameter is not honored when sharing a map or geoprocessing service to ArcGIS Server.

Boolean
Share With These Groups
(Optional)

Specifies whether the web layer or web tool will be shared with specified groups in your organization.

  • Checked—The web layer or web tool will be shared with specified groups.
  • Unchecked—The web layer or web tool will not be shared with specified groups.

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

This parameter is not honored when sharing to ArcGIS Server.

String

Derived Output

LabelExplanationData Type
SOAP Service URL

The SOAP URL of a service published to the server.

String
REST Service URL

The REST URL of a service published to the server.

String
Hosted Map Service Item ID

The Item ID of the map image layer shared to the portal.

String
Hosted Feature Service Item ID

The Item ID of the hosted feature service layer shared to the portal.

String
Cached Service

An image service or a map service with caching enabled.

Image Service; Map Server
Feature Service URL

The REST URL of a hosted feature layer shared to the portal.

String
Map Service URL

The REST URL of a map image layer shared to the portal.

String
Layer ID

The published layers and their respective IDs in the format Layer1|ID1;Layer2|ID2; and so on.

String
Service URL

The published stand-alone tables and their respective IDs in the format Table1|ID1;Table2|ID2; and so on.

String
Hosted Vector Tile Service Item ID

The Item ID of the vector tile service.

String
Vector Tile Service URL

The REST URL of the vector tile service.

String

arcpy.management.UploadServiceDefinition(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})
NameExplanationData Type
in_sd_file

The service definition file (.sd) that contains all the information needed to share a web layer, web tool, or service.

File
in_server

The server type. The following server types are supported:

  • My Hosted Services—Use when sharing a hosted web layer to ArcGIS Online or ArcGIS Enterprise. Enter My Hosted Services for the server connection. Capitalize the first letter of each word and include a space between each word.
  • HOSTING_SERVER—Use when sharing a hosted web layer to ArcGIS Online or ArcGIS Enterprise.
  • URL to the ArcGIS Enterprise portal federated server—Use when sharing a web tool or map image layer to an ArcGIS Enterprise portal federated server.
  • ArcGIS Server connection—Use when sharing a map or geoprocessing service to ArcGIS Server. You can use ArcGIS Server connections listed under the Servers node in the Project window, or you can browse to a folder where server connection files are stored.
  • URL to ArcGIS Server—Use when sharing a map or geoprocessing service to ArcGIS Server. You can specify the URL to ArcGIS Server provided a publisher connection to ArcGIS Server has been added to the ArcGIS AllSource project, and you're opening the project in the script or you're running the tool in ArcGIS AllSource.

ServerConnection
in_service_name
(Optional)

The service name that will override the current service name specified in the service definition.

String
in_cluster
(Optional)

The cluster name that will override the current cluster to which the service has been assigned. You must choose from clusters on the specified server.

Legacy:

Clusters are deprecated at ArcGIS Enterprise 10.5.1. This parameter will be ignored for servers that do not support multiple clusters.

String
in_folder_type
(Optional)

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

  • NEWA new folder will be created.
  • EXISTINGAn existing folder on the server will be used.
  • FROM_SERVICE_DEFINITIONThe folder in the service definition will be used. This is the default.
String
in_folder
(Optional)

The folder that will be used for the web layer or service. If no folder is provided, the folder specified in the service definition will be used. If you specified NEW for in_folder_type, use this parameter to provide a folder name. If you specified EXISTING for in_folder_type, you can choose from the existing folders on the server.

String
in_startupType
(Optional)

Specifies whether the service will be started after sharing.

  • STARTEDThe service will be started after sharing. This is the default.
  • STOPPEDThe service will not be started after sharing.
Boolean
in_override
(Optional)

Specifies whether the sharing properties set in the service definition will be overridden. These properties define if, and how, you are sharing the web layer or web tool with ArcGIS Online or ArcGIS Enterprise. Sharing the web layer or web tool exposes it for others to use.

  • OVERRIDE_DEFINITIONThe sharing properties set in the service definition will be overridden.
  • USE_DEFINITIONThe sharing properties set in the service definition will not be overridden; they will be used. This is the default.

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

This parameter is not honored when sharing to ArcGIS Server.

Boolean
in_my_contents
(Optional)

Specifies whether web layers and web tools will be shared.

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

  • SHARE_ONLINEThe web layer or web tool will be shared on ArcGIS Online or ArcGIS Enterprise. The web layer or web tool will be listed under My Content.
  • NO_SHARE_ONLINEThe web layer or web tool 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. This is the default.

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

This parameter is not honored when sharing to ArcGIS Server.

Boolean
in_public
(Optional)

Specifies whether the web layer or web tool will be available to the public.

  • PUBLICThe web layer or web tool will be available to the public.
  • PRIVATEThe web layer or web tool will not be available to the public. This is the default.

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

This parameter is not honored when sharing to ArcGIS Server.

Boolean
in_organization
(Optional)

Specifies whether the web layer or web tool will be shared with your organization.

  • SHARE_ORGANIZATIONThe web layer or web tool will be shared with your organization.
  • NO_SHARE_ORGANIZATIONThe web layer or web tool will not be shared with your organization. This is the default.

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

This parameter is not honored when sharing to ArcGIS Server.

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

A list of group names with which the web layer or web tool will be shared.

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

This parameter is not honored when sharing to ArcGIS Server.

String

Derived Output

NameExplanationData Type
out_soap_svc_url

The SOAP URL of a service published to the server.

String
out_rest_svc_url

The REST URL of a service published to the server.

String
out_mapServiceItemID

The Item ID of the map image layer shared to the portal.

String
out_featServiceItemID

The Item ID of the hosted feature service layer shared to the portal.

String
out_cached_service

An image service or a map service with caching enabled.

Image Service; Map Server
out_featureServiceURL

The REST URL of a hosted feature layer shared to the portal.

String
out_mapServiceURL

The REST URL of a map image layer shared to the portal.

String
out_LayerIDMap

The published layers and their respective IDs in the format Layer1|ID1;Layer2|ID2; and so on.

String
out_standaloneTableIDMap

The published stand-alone tables and their respective IDs in the format Table1|ID1;Table2|ID2; and so on.

String
out_vectorTileServiceID

The Item ID of the vector tile service.

String
out_vectorTileServiceURL

The REST URL of the vector tile service.

String

Code sample

UploadServiceDefinition example 1 (stand-alone script)

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 AllSource.

import arcpy
import 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 Definition Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)

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

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

print("Successfully Uploaded service.")
UploadServiceDefinition example 2 (stand-alone script)

The following script uploads an existing service definition and uses optional parameters to modify properties of the service.

import arcpy

# Set environment settings
arcpy.env.workspace = "C:/data"

# Set local variables
inSdFile = "myMapService.sd"
inServer = "myServerConnection.ags"
inServiceName = "newServiceName"
inCluster = "myCluster"
inFolderType = "NEW"
inFolder = "newFolder"
inStartup = "STOPPED"

# Run UploadServiceDefinition
arcpy.server.UploadServiceDefinition(inSdFile, inServer, inServiceName, 
                                     inCluster, inFolderType, inFolder, 
                                     inStartup)
UploadServiceDefinition example 3 (stand-alone script)

The following script uploads an existing service definition to either ArcGIS Online or ArcGIS Enterprise and uses optional parameters to modify properties of the service.

import arcpy

# Set environment settings
arcpy.env.workspace = "C:/data"

# Set local variables
inSdFile = "myMapService.sd"
inServer = "HOSTING_SERVER"
inServiceName = "newServiceName"
inCluster = "myCluster"
inFolderType = "EXISTING"
inFolder = "existingFolder"
inStartup = "STOPPED"
inOverride = "OVERRIDE_DEFINITION"
inMyContents = "SHARE_ONLINE"
inPublic = "PRIVATE"
inOrganization = "NO_SHARE_ORGANIZATION"
inGroups = ["My Group", "MyGroup 2"]

# Run UploadServiceDefinition
arcpy.server.UploadServiceDefinition(inSdFile, inServer, inServiceName, 
                                     inCluster, inFolderType, inFolder, 
                                     inStartup, inOverride, inMyContents, 
                                     inPublic, inOrganization, inGroups)

Environments

This tool does not use any geoprocessing environments.