HOW TO
Web layers can be added to ArcGIS Online from an existing ArcGIS REST Services Directory through ArcGIS API for Python using the gis.content.add() function. However, if the desired layer contains a stored credential, the function is hindered and the process of adding the web layer fails.
The following steps describe how to add a web layer with stored credentials to ArcGIS Online using ArcGIS API for Python.
from arcgis.map import Map from arcgis.gis import GIS
gis = GIS('https://www.arcgis.com','username') token = gis._con.token
item_properties = { "title":"TestAdd2", #the same title "tags":"test", "url":"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer", "type":"Feature Service", "description":"Test Me", "serviceUsername":"username", "servicePassword":"password", "token":token }
gis.content.add(data="https://sample.arcgisonline.com/",owner="username",item_properties=item_properties)
The following shows the full code:
from arcgis.map import Map from arcgis.gis import GIS gis = GIS('https://www.arcgis.com','arch0000') token = gis._con.token item_properties = { "title":"TestAdd2", #the same title "tags":"test", "url":"https://sample.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer", "type":"Feature Service", "description":"Test Me", "serviceUsername":"username", "servicePassword":"password", "token":token } gis.content.add(data="https://sample.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer",owner="username",item_properties=item_properties)
Article ID: 000022504
Get help from ArcGIS experts
Download the Esri Support App