HOW TO
The REST endpoint of an ArcGIS Online item contains useful information. However, manually obtaining the REST URL can be time-consuming if there are many items. Using ArcGIS API for Python, information such as the REST URL for each item can be generated in an Excel file. This article provides the workflow to retrieve the REST URL and other details of the ArcGIS Online items using ArcGIS API for Python.
from arcgis.gis import GIS import datetime import os, re, csv import pandas as pd
gis = GIS('https://www.arcgis.com', 'USERNAME', 'PASSWORD')
search_result = gis.content.search(query = 'owner:OWNER_NAME', item_type="Feature Service", max_items=NUMBER OF ITEMS) #(search_result) # list to record items
list_of_items = list() list_of_items.append(['title', 'id', 'views', 'created', 'owner', 'size', 'access', 'url'])
for i in search_result: try: if hasattr(i, 'url'): #source = i.sourceUrl unix_date =i.created # unix ms second date/time normal_date = datetime.datetime.fromtimestamp(unix_date / 1e3) list_of_items.append([i.title, i.itemid, i.numViews, normal_date, i.owner, i.size, i.access, i.url]) except: continue
df = pd.DataFrame(list_of_items) df.to_excel(r'<FOLDER LOCATION>\<FILE NAME>.xlsx') print('Item details are saved in the excel file.')
The code block below shows the full script for the 20 searched hosted features owned by TestUser.
from arcgis.gis import GIS import datetime import os, re, csv import pandas as pd gis = GIS('https://www.arcgis.com', 'USERNAME123', 'PASSWORD123') search_result = gis.content.search(query = 'owner:TestUser', item_type='Feature Service', max_items=20) list_of_items = list() list_of_items.append(['title', 'id', 'views', 'created', 'owner', 'size', 'access', 'url']) for i in search_result: try: if hasattr(i, 'url'): unix_date =i.created # unix ms second date/time normal_date = datetime.datetime.fromtimestamp(unix_date / 1e3) list_of_items.append([i.title, i.itemid, i.numViews, normal_date, i.owner, i.size, i.access, i.url]) except: continue df = pd.DataFrame(list_of_items) df.to_excel(r'C:\Users\USER\Desktop\Download Folder\item details.xlsx') print('Item details are saved in the excel file.')
Get help from ArcGIS experts
Download the Esri Support App