Cloning Classic Story maps from Portal to ArcGIS Online

11-30-2021 09:53 PM
New Contributor III


I'm involved in a task to clone classic story maps from Portal to arcgis online. I tried using the code mentioned in the link

When executing the code

web_maps = set([v['data']['itemId'] for k, v in story_map_json['resources'].items() \
if v['type'].lower().find('webmap')>-1])
express_maps = set([v['data']['itemId'] for k, v in story_map_json['resources'].items() \
if v['type'].lower().find('expressmap')>-1])

i'm getting error

NameError Traceback (most recent call last)
<ipython-input-24-40aa3fd3cb10> in <module>
----> 1 web_maps = set([v['data']['itemId'] for k, v in story_map_json[resources].items() \
2 if v['type'].lower().find('webmap')>-1])

NameError: name 'resources' is not defined

Could not track why its throwing this error.

Please suggest why i'm receiving this error.

0 Kudos
4 Replies
MVP Regular Contributor

the variable for "resources" isn't set?

Amanda Bishop, GISP
0 Kudos
New Contributor III

Thanks Amanda for your reply. I'm using the code as mentioned in the developers documentation. 

Can you help to set this variable in which part of the code!

0 Kudos
MVP Regular Contributor

Usually at the beginning of the code after you import the python module you would basically set the variable = "location of variable".

So like your code is calling out ['resources'].  You have to tell the code where to find it.  Like this:

resources= "C:\users\abishop\...."

I have pasted a sample code below that I use daily to update a hosted feature service in AGOL to help you better understand the structure.  Let me know if you have questions.

import arcpy
import os, sys
from arcgis.gis import GIS

### Set variables for project path
prjPath = r"I:\users\abishop\PY\FeatureServiceUpdates\AgUseParcels\AgUseParcels.aprx"

# Update the following variables to match:
# Feature service/SD name in, user/password of the owner account
sd_fs_name = "Agricultural_Use_Parcels"
portal = "" # Can also reference a local portal
user = "*********"
password = "*******"

# Set sharing options
shrOrg = True
shrEveryone = False
shrGroups = ""

### End setting variables

# Local paths to create temporary content
relPath = os.path.dirname(prjPath)
sddraft = os.path.join(relPath, "WebUpdate.sddraft")
sd = os.path.join(relPath, "")

# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj =
mp = prj.listMaps()[0], sddraft, sd_fs_name, "MY_HOSTED_SERVICES", "FEATURE_ACCESS","", True, True, allow_exporting=True)
arcpy.StageService_server(sddraft, sd)

print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)

# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal…")
sdItem ="{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title,
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)

if shrOrg or shrEveryone or shrGroups:
 print("Setting sharing options…")
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)

print("Finished updating: {} – ID: {}".format(fs.title,

#provide input to stop script - uncomment input below if you need to see the script final output in the command window
input('Press ENTER to exit') 


Amanda Bishop, GISP
New Contributor III

Thanks Amanda for your explanation. This gives a clear understanding.