Select to view content in your preferred language

Overwrite Experiences to Maintain IDs

494
6
02-18-2026 04:58 PM
Status: Open
Labels (1)
mpboyle
Honored Contributor

It's be nice to have the ability to easily swap or overwrite an experience with the config of another.

For example, if testing or developing a new experience, when complete, I'd like to have the ability to overwrite an existing experience config with the new one. This way I don't have to notify users of a new URL.

6 Comments
Zach-Williams

Do you have a url domain tied to a server? What I've done, especially with past WAB maps, I overwrite them by creating a virtual directory in IIS, and that's after downloading them through developer on the server. 

mpboyle

@Zach-Williams 

This is more for the hosted AGO version of ExB.  With Developer Edition, it's a lot easier to manipulate or copy/paste/replace the downloaded app with an existing one.

DougBrowning

We use redirect URLs which helps a bit but the issue is the redirect resolves to the arcgis URL, then the user bookmarks, which causes them to bookmark the arcgis with id URL.  So when we change it they are still pointing to the wrong spot.

Zach-Williams

@mpboyle I use AGO to build mine and then import through developer and then download. I'm not a coder so this was how we got our experiences under our municipality url that we use for our maps.

mpboyle

@DougBrowning 

Yep, I could see that being an issue, one of which the idea hopes to resolve...have a somewhat static URL for an app, but be able to import/load/swap a configuration from another experience.

mpboyle

Below is a a Python script that will overwrite the configuration of the "target" experience using the configuration from the "source" experience.

In my testing, I created a very basic experience as my "target", and overwrote it using the config from one of our developed experiences as the "source". 

After running the script, the "target" experience looked, behaved, and had all the components of the "source" experience.

This may be a way of easily updating one experience with another and not having to move URLs around.

 

Note: This does not update the "target" experience title, summary, description or any of its item properties.

 

!!! USE CAUTION AND BACKUP ANY ITEMS BEFORE TESTING !!!

 

In the code below, the following lines will need to be updated: 6, 7, 8, 11, 13, 15 (optional)

import arcgis
import json
from pathlib import Path

# portal variables
PORTAL_URL = r'...url...'
PORTAL_USER = '...user name...'
PORTAL_PASSWORD = '...user password...'

# source experience item id (load from)
ITEM_ID_SOURCE = '...item id...'
# target experience item id (load into)
ITEM_ID_TARGET = '...item id...'
# optional --- writes source experience config to file
WRITE_SOURCE_CONFIG = True


if __name__ == '__main__':

    # connect to portal
    portal = arcgis.GIS(url=PORTAL_URL,
                        username=PORTAL_USER,
                        password=PORTAL_PASSWORD)

    # get source experience item
    item_source = portal.content.get(itemid=ITEM_ID_SOURCE)
    # get target experience item
    item_target = portal.content.get(itemid=ITEM_ID_TARGET)

    # get source config
    config_source = item_source.get_data()
    # write source config?
    if WRITE_SOURCE_CONFIG:
        # construct config file path
        root_dir = Path(Path(__file__).parent).resolve()
        config_path = root_dir / f'config__{ITEM_ID_SOURCE}.json'
        # write source config
        with open(file=config_path, mode='w') as f:
            print(f'Attempting to write item "{ITEM_ID_SOURCE}" config')
            json.dump(obj=config_source, fp=f, indent=4)
            print(f'Successfully created "{config_path}"')
            print('-' * 50)

    # update target item config
    print(f'Attempting to update item "{ITEM_ID_TARGET}" config')
    item_target.update(data=config_source)
    print(f'Successfully updated item "{ITEM_ID_TARGET}" config')
    print('-' * 50)