#!/usr/bin/env python # coding: utf-8 # ## Bulk service registration # A relatively common use case is when users have existing content published as web services that they want to register in ArcGIS Online. The following workflow takes a service with multiple layers and registers them as individual items, using layer properties to populate metadata fields. # In[1]: # import all the necessary modules from arcgis.gis import GIS from IPython.display import display import arcgis.features from getpass import getpass # In[2]: # login to an existing arcgis online organization gis = GIS("https://citygov.maps.arcgis.com/", "phammons_citygov", getpass()) # ### Point to an existing service # First we need to grab the url to an existing service, point it to our gis variable, and store that as a feature layer collection in another variable. We can do that with the FeatureLayerCollection method: # In[3]: url = 'https://maps.vcgi.vermont.gov/arcgis/rest/services/EGC_services/OPENDATA_VCGI_BOUNDARIES_SP_NOCACHE_v1/MapServer' boundaries = arcgis.features.FeatureLayerCollection(url, gis) # ### Create a folder # Then we create a folder for these layers to live in: # In[4]: gis.content.create_folder(folder = 'boundaries') # ### Register the layers # Now that we've finished our preliminary stuff, we can get to the fun part -- registering layers! The following block of code iterates through each layer in the service, populates some metadata fields with service properties (title, description, url), and defines others manually (tags, type). Finally all of this info is used to create the layer and move it to the folder we created in the previous step: # In[5]: for layer in boundaries.layers: layer_properties = { 'title': layer.properties['name'], 'description': layer.properties['description'], 'tags': 'chittenden, boundaries, bulk service registration, python api', 'type': 'Feature Service', 'url': layer.url } create_item = gis.content.add(item_properties=layer_properties, data=layer.url) create_item.move(folder= 'boundaries') # Now those layers are available as individual items in the ```boundaries``` folder: # In[6]: boundaries = gis.content.search(query="tags:bulk service registration") for layer in boundaries: display(layer)