English

How To: List hosted items and the REST endpoint URLs using ArcGIS API for Python

Summary

Contents from a portal can be added to a different portal using ArcGIS API for Python with the add() function from the arcgis.gis.ContentManager module. Within the add() function, required parameters include the REST endpoint URL of the desired item. The REST endpoint URL is available in the following template:

http://<host name>/arcgis/rest/<ServiceName>

Retrieving the URL of all the items in a portal can be tedious when a large number of services is involved.

This article provides an automated process to retrieve the REST endpoint URL of all feature layers or web maps in a portal using the arcgis.gis module.

Procedure

  1. Import the necessary modules.
import arcgis
from arcgis.gis import GIS
  1. Specify the user credentials and connect to the portal.
user = "username"
password = "password1"
url = "https://< a portal url >"

gis = GIS(url, user, password)
  1. Search for all feature layers or web maps.
# for feature layers 
fcs = gis.content.search("owner:" + user, item_type="Feature Layer", max_items=10)
fcs

# for web maps
webmaps = gis.content.search("owner:" + user, item_type="Web Map", max_items=10)
webmaps
  1. Return the URLs.
# for feature layers
fcs.url
fc_layers = fcs.layers
fc_layers.url

# for web maps
web_map_obj = arcgis.mapping.WebMap(webmaps)
maplayers = web_map_obj['operationalLayers']
maplayers['url']

Related Information

Last Published: 8/27/2020

Article ID: 000016853

Software: ArcGIS API for Python 1.8.2, 1.8.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6, 1.5.3, 1.5.2, 1.5.1, 1.5, 1.4.1, 1.4, 1.3, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2, 1.0.1, 1.0 ArcGIS GeoAnalytics Server 10.8.1, 10.8, 10.7.1, 10.7, 10.6.1, 10.6 ArcGIS GeoEvent Server 10.8.1, 10.8, 10.7.1, 10.7, 10.6.1, 10.6 ArcGIS Image Server 10.8.1, 10.8, 10.7.1, 10.7, 10.6.1, 10.6 ArcGIS Online 8.2 ArcGIS Server 10.8.1, 10.8, 10.7.1, 10.7, 10.6.1, 10.6 Portal for ArcGIS 10.8.1, 10.8, 10.7.1, 10.7, 10.6.1, 10.6