Select to view content in your preferred language

cloning a public story map with the 2.4.2 Python API, issues

410
5
a month ago
TrebinMT
Occasional Contributor

So, 

I'm attempting to clone a public story map to my ArcGIS Online org using clone_items.

I'm giving this a test on a public story map owned by Esri.   Running this from a standard Notebook in ArcGIS Online using the 13.0 runtime (which has the 2.4.1 ArcGIS for Python API)

This is the public Story Map:  https://storymaps.arcgis.com/stories/0f6f051fba32481cba12e8565e8681a0

Code seems to hang.   I've tried to just clone the webmap that's within the Story Map, but that seems to hang too.

https://www.arcgis.com/apps/mapviewer/index.html?webmap=b5cebe00555444c08b13d15a00100b16

 

I thought clone items would copy what it needed, and Living Atlas layers and such would still be referenced?

Is there an issue with my code?

from arcgis.gis import GIS
# -------------------------------------------------------------------
# CONFIGURE THESE VALUES
# -------------------------------------------------------------------
public_storymap_item_id = "0f6f051fba32481cba12e8565e8681a0"   # replace with the public StoryMap item ID

target_folder = "test"             # optional; set to None if you do not want a folder
# -------------------------------------------------------------------

# Connect anonymously to access the public source item
source_gis = GIS()

# Connect to your ArcGIS Online organization
target_gis = GIS("home")

# Get the public StoryMap item
source_item = source_gis.content.get(public_storymap_item_id)

if source_item is None:
   raise ValueError("Could not find the public StoryMap item. Check the item ID.")
print(f"Source item found: {source_item.title} ({source_item.type})")

# Clone the item into your organization
cloned_items = target_gis.content.clone_items(
   items=[source_item],
   folder=target_folder,
   search_existing_items=True
)

# Report results
if cloned_items:
   cloned_item = cloned_items[0]
   print("Clone completed.")
   print(f"New item title: {cloned_item.title}")
   print(f"New item ID: {cloned_item.id}")
   print(f"New item URL: {cloned_item.homepage}")
else:
   print("No cloned items were returned.")

 

 

0 Kudos
5 Replies
Clubdebambos
MVP Regular Contributor

Hi @TrebinMT,

I haven't had a chance to test the clone but you can certainly save the WebMap to your organization. Feature Layers / Tables will still reference original sources.

 

from arcgis.gis import GIS
from arcgis.map import Map

## access your org ArcGIS Online
agol = GIS("home")

## get the WebMap Item object
wm_item = agol.content.get("b5cebe00555444c08b13d15a00100b16")

## convert to a Map object
wm_obj = Map(wm_item)

## the required properties when saving
item_properties = {
    "title" : "New WebMap",
    "snippet" : "Summary is required",
    "tags" : ["tags", "are", "required"]
}

## save the Map object as a new Item
wm_obj.save(
    item_properties = item_properties,
    folder = "test"
)

 

I hope that helps for now. I'll check out cloning when I get a chance.

All the best,

Glen

~ learn.finaldraftmapping.com
0 Kudos
PeterKnoop
MVP Regular Contributor

I don't think the issue is with your code. Rather, I think you may have run into a bug with the ArcGIS API for Python, and you've correctly tracked down the Web Map as the culprit.

The Web Map you are attempting to clone references a custom basemap, and I suspect there is a bug in the API that is getting triggered when it attempts to clone the Vector tile layers used in the custom basemap, which ends up hanging the process.

Based on running into this elsewhere very recently, a quick workaround should be to set use_org_basemap = True for clone_items(). It will replace references to the custom basemap with your orgs default basemap. (If you really need the custom basemap, then should be able to recreate it on your destination org first, and then use item_mapping during the cloning of the StoryMap.

0 Kudos
TrebinMT
Occasional Contributor

Thanks to @Clubdebambos and @PeterKnoop  for the advice and testing.  I'm currently running a script w/ Peter's advice.   Still hanging/running at this moment.

I'd just mess with the web map, but in our Org, we oftentimes need to transfer complicated items from another user's org to another.   We have a situation like that currently.    Dev/Tech summit had a great session on cloning complicated items and dependencies.   But I really wanted to put to the test clone_items() to see what it couldn't handle as the capabilities have been improved, supposedly for complicated/complex items like Story Maps, ExB Apps, etc.       Well, it seems I'm challenging it now with what I'd consider to be a fairly benign application...  

0 Kudos
TrebinMT
Occasional Contributor

Unfortunately, Peter's proposed fix wasn't the solution for me and this Story Map collection of items.   

clone_items hung the Notebook script and it never completed.

0 Kudos
Clubdebambos
MVP Regular Contributor

I also attempted to clone and it hung. I also attempted to just save() the StoryMap to my organization and also duplicate(). To duplicate, you need the contents list and the API failed to get that. I was returned a couple of different errors that suggested the Story Map is protected from being copied. I am not savvy enough with Story Maps to know how that was done. If you call get_data() on the item object you can see how the Story Map is created. I trued to create an empty story map update the with the get_data() response but that also did not take. There is probably some way to iterate through the information returned from get_data() and remake the Story Map, I just have the time at the moment to test that out.

~ learn.finaldraftmapping.com
0 Kudos