HOW TO

Copy metadata from an existing service to a new item through a REST endpoint using ArcGIS API for Python

Last Published: April 23, 2021

Summary

An existing service metadata can be copied to a new item in ArcGIS Online or ArcGIS Enterprise using the ArcGIS API for Python. This can be particularly helpful to maintain uniformity throughout the whole organization in when multiple data is involved. 

Procedure

The following procedure describes how to copy the metadata from an existing service. There are two ways to copy the metadata, from a feature layer, and from a map service. 

Using Feature layer

  1. Import the necessary modules.
import arcgis
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
  1. Specify the the FeatureLayer() class to get the items from the service endpoint.
gis = GIS("https://arcgis.com", "Username", "Password")
url = '<Feature Layer Service URL>'
layer = FeatureLayer(url)
  1. Set the metadata from the service to the respective variables. 
itemTags = layer.properties.documentInfo.Keywords
itemDescription = layer.properties.serviceDescription
itemSnippet = layer.properties.documentInfo.Subject
itemTitle = layer.properties.documentInfo.Title
  1. Create a new item in ArcGIS Online with the information from the existing service.
wmsUrl = '<URL to the service>'
props = {'title': itemTitle, 'type': 'Feature Service', 'url': '<URL to the service>', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet}
wmsItem = gis.content.add(item_properties=props, data=wmsUrl)
The following shows a sample of the full script:
import arcgis
from arcgis.gis import GIS
from arcgis.features import FeatureLayer

gis = GIS("https://arcgis.com", "Username", "Password")
url = 'https://services.arcgis.com/Wl7Y1m92PbjtJs5n/arcgis/rest/services/workers_dec6d6e11b564e338fb3254626cee2f0/FeatureServer'
layer = FeatureLayer(url)

itemTags = layer.properties.documentInfo.Keywords
itemDescription = layer.properties.serviceDescription
itemSnippet = layer.properties.documentInfo.Subject
itemTitle = layer.properties.documentInfo.Title

wmsUrl = 'https://domain.esri.com:6443/arcgis/rest/services'
props = {'title': itemTitle, 'type': 'Feature Service', 'url': 'https://domain.esri.com:6443/arcgis/rest/services', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet}
wmsItem = gis.content.add(item_properties=props, data=wmsUrl)
Using Map Service
  1. Import the necessary modules.
import arcgis
from arcgis.gis import GIS
from arcgis.mapping import MapImageLayer
  1. Specify the MapImageLayer() class to get the items from the service endpoint
gis = GIS("https://arcgis.com", "Username", "Password")
url = '<Map Service URL>'
layer = MapImageLayer(url)
  1. Set the metadata from the service to the respective variables.
itemTags = layer.item_info['tags']
itemDescription = layer.item_info['description']
itemSnippet = layer.item_info['summary']
itemTitle = layer.item_info['title']
itemTumbnail = layer.thumbnail()
  1. Create a new item with the information from the existing service.
wmsUrl = '<URL to the service>'
props = {'title': itemTitle, 'type': 'Map Service', 'url': '<Url to the service>', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet}
wmsItem = gis.content.add(item_properties=props, data=wmsUrl, thumbnail= itemTumbnail)
The following shows a sample of the full script:
import arcgis
from arcgis.gis import GIS
from arcgis.mapping import MapImageLayer

gis = GIS("https://arcgis.com", "Username", "Password")
url = 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/MapServer'
layer = MapImageLayer(url)

itemTags = layer.item_info['tags']
itemDescription = layer.item_info['description']
itemSnippet = layer.item_info['summary']
itemTitle = layer.item_info['title']
itemTumbnail = layer.thumbnail()

wmsUrl = 'https://domain.esri.com:6443/arcgis/rest/services'
props = {'title': itemTitle, 'type': 'Map Service', 'url': 'https://domain.esri.com:6443/arcgis/rest/services', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet}
wmsItem = gis.content.add(item_properties=props, data=wmsUrl, thumbnail= itemTumbnail)

Article ID:000019020

Software:
  • ArcGIS Online
  • ArcGIS Server
  • ArcGIS API for Python 1 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic