Select to view content in your preferred language

how to get all item id's for ArcGIS Online

838
11
Jump to solution
08-21-2025 06:08 AM
L77
by
Frequent Contributor

I am updating my data backup script and don't want to go through everything I have published in ArcGIS Online individually.

How do I get a list or a spreadsheet that includes the item id, and the corresponding Title or file name?

I would like to get everything that is published online, (feature services, web maps, and apps).

0 Kudos
1 Solution

Accepted Solutions
CodyPatterson
MVP Regular Contributor

Hey @L77 

I see I see, I still think the permissions should be given to you, but for now I see where you're trying to get, for my script, you may want to use it as informational rather than creating a CSV, there may be an issue with your permissions and programmatically creating things:

from arcgis.gis import GIS
import pandas as pd
from datetime import datetime

gis = GIS("home")

item_types = ["Feature Service", "Web Map", "Web Mapping Application"]
items_list = []

for item_type in item_types:
    query = f"owner:{gis.users.me.username} type:{item_type}"
    search_results = gis.content.search(query=query, max_items=1000) # May need to adjust this
    for item in search_results:
        filename = item.get("name", "N/A")
        items_list.append({
            "Item ID": item.id,
            "Title": item.title,
            "Item Type": item.type,
            "Filename": filename,
            "Last Modified": datetime.fromtimestamp(item.modified / 1000).strftime('%Y-%m-%d %H:%M:%S')
        })

df = pd.DataFrame(items_list)

for item in items_list:
    print(item)

Cody

View solution in original post

11 Replies
CodyPatterson
MVP Regular Contributor

Hey @L77 

You can go through the Organization -> Status -> Reports page to get all the items in your organization into an excel sheet like this here:

CodyPatterson_0-1755782054020.png

CodyPatterson_1-1755782077242.png

 

Cody

0 Kudos
RichardHowe
Frequent Contributor

GeoJobe's free admin tools are also very useful for constructing and downloading different tables of your content, including itemID, size, last viewed etc.:

GeoJobe Admin Tools 

0 Kudos
L77
by
Frequent Contributor

I don't think my administrator would let me use it, because it is a third party tool.

0 Kudos
L77
by
Frequent Contributor

@CodyPatterson I don't have that as an option in my account, it may have been disabled by our administrator.

Do you know of another way to get the information?

L77_0-1755782397150.png

 

0 Kudos
CodyPatterson
MVP Regular Contributor

Hey @L77 

I would definitely recommend to your administrator that this access be given to you, this is easily the best built-in method to get this information, otherwise, you can do it through Python or an ArcGIS Notebook through this script here:

from arcgis.gis import GIS
import pandas as pd
from datetime import datetime

gis = GIS("home")

item_types = ["Feature Service", "Web Map", "Web Mapping Application"]
items_list = []

for item_type in item_types:
    query = f"owner:{gis.users.me.username} type:{item_type}"
    search_results = gis.content.search(query=query, max_items=1000) # May need to adjust this
    for item in search_results:
        filename = item.get("name", "N/A")
        items_list.append({
            "Item ID": item.id,
            "Title": item.title,
            "Item Type": item.type,
            "Filename": filename,
            "Last Modified": datetime.fromtimestamp(item.modified / 1000).strftime('%Y-%m-%d %H:%M:%S')
        })

df = pd.DataFrame(items_list)

display(df)

output_path = f"Item_List_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv"
df.to_csv(output_path, index=False)

csv_item_properties = {
    "title": f"ArcGIS Online Items List {datetime.now().strftime('%Y%m%d_%H%M%S')}",
    "type": "CSV"
}
gis.content.add(item_properties=csv_item_properties, data=output_path)

Edit: Added the wrong script at first, you will need administrative privileges in your environment to access all user added information. Edit again: reverted to the original script since you mentioned it's for you

At the very end you will get a link to a CSV which you can then download!

Cody

0 Kudos
L77
by
Frequent Contributor

@CodyPatterson Getting basic permissions here is difficult.

I ran the script you gave me and this was the result:

L77_0-1755783278579.png

 

This is my backup script I have been using below.

I want to download everything that is currently in my account that I am the owner of one time, Then I would like to get a list of the item names and corresponding ID's so I can go through and pick which item id's I want to put in my backup script moving forward.

from arcgis.gis import GIS
import datetime as dt
import os

def download_as_fgdb(item_list, backup_location):
skipped_items = []

for item in item_list:
try:
if item is None:
print("Item is None, skipping...")
skipped_items.append("NoneType")
continue
if 'View Service' in item.typeKeywords:
print(item.title + " is a view service, not downloading")
skipped_items.append(f"{item.title} (View Service)")
else:
print("Downloading " + item.title)
result = item.export(item.title, "File Geodatabase")
result.download(backup_location)
result.delete()
print("Successfully downloaded " + item.title)
except Exception as e:
print(f"An error occurred downloading {item.title if item else 'Unknown'}: {e}")
skipped_items.append(f"{item.title if item else 'Unknown'} (Error: {e})")

if skipped_items:
print("\nThe following items were skipped:")
for skipped_item in skipped_items:
print(skipped_item)
else:
print("\nAll items were processed successfully.")

print("The function has completed")

username = input("Input your username: ")
gis = GIS("https://arcgis.com", username)


# Hard-code the item IDs
selected_ids = [
"7b745ada01b944fea4b033d828a7fb64","fe994d4f1ec74c78aab15ce28aaa6993","0e61846a1b15469eaa2e5c9f06b6d3df","033b2d07baa142f6a42f33f26ce39d82",
"6b4b9c313a97451a95e64c44d4ed1a95","48078e36f8d340f4aa7d04cd06006dcb","b2cc28307b984a8093b0819cb2b43fb0",
"d34e06c01a6243a896b73220f3698d61","f52fcbdeb2e244f28ebd59d5b4a82cc1","a5e42605877c43d48666deacab9b32f5",
"bcf2178c3c5b4108bd361e5a56473dda","e5bd12a81bac419ea5e50183c711960d","a8cfe5064e0249d1884b5957fc858c8d",
"ac764e1346c24be8aa31124543fb0246","ba07294d3b1b43218ecc37bf356086bc","1f69cf82cebe49bfbb5108819ff79e34",
"5f65347b84c440a6972fa33d60f88bd5","be284e4b2b364f6d8abc823e6ff587d9","295b604233f6449aaa1cc8727a603b10",
"7baaf392a7df453ca503b70d9d1b6eff","a810e02302c74ffa8fa55aa1a7616506","5d4f98aca4804d35bce0f5ce26cf0435",
"ccdb9803cec84b9ebf8286eee2f625af","8515d95e52904961a09f7e6eeeffdb45","a75950a6b7c343f9855e1766a2438127",
"d15b7d60ec5b4d179f5b2369c2e020d9","7d6b171ee037479098dc46afb69ef205","2718692bf7e145f9a4d84f60250166ed",
"47e6eaa3241f432b959a7541e957193c","c9fd8c420cb142eca4336139414d2592","eecf6a01fa3748ee9e1eda08c96f9885",
"881cf6906bc64138988b379647e1f2ff","89571c9117ab400093d8b76cf3ff35f0"
]

# Fetch items directly using the hard-coded IDs
selected_items = [gis.content.get(item_id) for item_id in selected_ids]

base_backup_path = "Z:\\General GIS\\!1_Projects\\Backups_From_Arc_GIS_Online\\Lorraine_Backup_Script"
current_date = dt.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") # Updated to include hours, minutes, and seconds
backup_folder = f"ArcGIS_Online_Backup_{current_date}"
folder_path = os.path.join(base_backup_path, backup_folder)

# Create a new folder with the format ArcGIS_Online_Backup_YYYY_MM_DD_HH_MM_SS
if not os.path.exists(folder_path):
os.mkdir(folder_path)

download_as_fgdb(selected_items, folder_path)

0 Kudos
CodyPatterson
MVP Regular Contributor

Hey @L77 

I see I see, I still think the permissions should be given to you, but for now I see where you're trying to get, for my script, you may want to use it as informational rather than creating a CSV, there may be an issue with your permissions and programmatically creating things:

from arcgis.gis import GIS
import pandas as pd
from datetime import datetime

gis = GIS("home")

item_types = ["Feature Service", "Web Map", "Web Mapping Application"]
items_list = []

for item_type in item_types:
    query = f"owner:{gis.users.me.username} type:{item_type}"
    search_results = gis.content.search(query=query, max_items=1000) # May need to adjust this
    for item in search_results:
        filename = item.get("name", "N/A")
        items_list.append({
            "Item ID": item.id,
            "Title": item.title,
            "Item Type": item.type,
            "Filename": filename,
            "Last Modified": datetime.fromtimestamp(item.modified / 1000).strftime('%Y-%m-%d %H:%M:%S')
        })

df = pd.DataFrame(items_list)

for item in items_list:
    print(item)

Cody

L77
by
Frequent Contributor

@CodyPatterson That worked, thank you!

AustinAverill
Frequent Contributor

Here is a pretty compact script that should retrieve all non-view layers and then store them as a dictionary (helps get around file permissions issues and such). 

from arcgis.gis import GIS

gis = GIS(url, un, pw)

userManager = gis.users
users = userManager.search("*")

#empty dict to store results in
items_dict = {}

#view keywords to reference
excluded = ['View Service', 'View Layer']

#loop through all users and query items they own
for user in users:
    query = user.username
    user_items = gis.content.search(query=f"owner:{query}",
                       item_type = "Feature Layer",
                       max_items = 2000)
    for item in user_items:
        if any(item in item.typeKeywords for item in excluded):
            print(f"{item.name} is view, skipped")
        else:
            items_dict[item.id] = item.name
            print(f"{item.name} added to dict")

You could then loop through the dictionary to return the item id for each.