I've been trying to add a Group Layer to ArcGIS Online using the Python API, but my attempts have only been partly succesful. Below you'll find some code similar to what I've been doing. I've used the Group Layer spec as shown here.
from arcgis import GIS
import json
gis = GIS(url = AGO_URL, username = AGO_USER, password = AGO_PASS)
itemProperties = {
'type': 'Group Layer',
'description': 'Some Description',
'title': 'Some Title',
'tags': ['Tag1', 'Tag2'],
'snippet': 'Some Snippet',
'accessInformation': 'Some Access Information',
'licenseInfo': 'Some License Info',
'commentsEnabled': False,
'access': 'org',
'text': json.dumps(
{
"id": "groupLayer",
"layerType": "GroupLayer",
"title": "US Census",
"layers": [
{
"id": "Census_6999",
"title": "Census - states",
"url": "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3",
"layerType": "ArcGISFeatureLayer"
},
{
"id": "Census_616",
"title": "Census - Detailed Counties",
"url": "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2",
"layerType": "ArcGISFeatureLayer"
}
]
}
)
}
gis.content.add(
item_properties = itemProperties,
thumbnail = 'Some thumbnail url',
metadata = None,
owner = None,
folder = None
)
This will successfully add the item as a Group Layer to ArcGIS Online, with title, description, etc. all working. The 2 layers will also show up as layers in the item. However, if I open the item in the Map Viewer, no layers will be shown.
Please advise.