English

How To: Convert URLs from HTTP to HTTPS in Esri Story Maps or other web applications using ArcGIS API for Python

Summary

All URLs in Esri Story Maps must use HTTPS, as described in Story Maps: Frequently Asked Questions. There are circumstances that may require a URL conversion from HTTP to HTTPS within a Story Map or other web applications. The URL can be updated manually, but this is tedious through the User Interface, especially with Story Maps containing a large number of linked items. ArcGIS API for Python provides a quick workflow to do this (for single web applications).

Procedure

One option is to convert the URL of a Story Map or other web applications from HTTP to HTTPS using the full code as a standalone script. To do so, copy the full script (found at the end of this article) into a text editor, for example, Notepad++, and save the file as a .py file. To run the code, right-click the .py file, and select Edit with IDLE > Select Run > Run Module.

The other option is to convert the URL using the replace() function. To do so, follow the steps below:

Note: Both options convert all URLs in the application to HTTPS.
  1. Import the necessary libraries.
    from arcgis.gis import GIS, Item
  2. Create a connection to the desired ArcGIS Online or Portal for ArcGIS user.
    user = "<user>"  # enter desired user
    password = "<password>"  # enter password
    url = "https://www.arcgis.com"  # change Portal URL if needed
    gis = GIS(url , user, password)
    Note: To use an active Portal for ArcGIS login from ArcGIS Pro, if enterprise logins are used, replace the "gis" parameter with the following: 
    gis = GIS("pro")
  3. Specify the item ID of the desired application.
    itemid = "<item id>" #Set the item ID 
  4. Retrieve the application data.
    app = Item(gis, itemid)
    appdata = app.get_data(False)
  5. Run the script to replace HTTP with HTTPS in the application data.
    new_appdata = appdata.replace("http://", "https://")
  6. Update the item with the specified URL in step 5, and print a closing statement.
    app.update({"text": new_appdata})
    
    print("Successfully updated item " + itemid)

    The following is the full code:
    from arcgis.gis import GIS, Item
    
    user = "username"  
    password = "password"
    url = "https://www.arcgis.com"
    
    itemid = "abc123"
    gis = GIS(url , user, password)  
    
    app = Item(gis, itemid)
    appdata = app.get_data(False)
    
    new_appdata = appdata.replace("http://", "https://")
    
    app.update({"text": new_appdata})
    
    print("Successfully updated item " + itemid)

 

Related Information