I'm wondering why usage values are not returned for certain item types, specifically hosted tile layers, when using the Python API? When viewing the Usage tab for these items, counts appear. However, when using the Python API, either the counts are way off, or not even returned.
Is this a known limitation based on item type?
Below are a few examples:
Example 1: Hosted Tile Layer
Item usage via the item page
Item usage via the Python API. The usage values ("num") are not close.
Example 2: Hosted Vector Tile Layer
Item usage via the item page
Item usage via the Python API. The data key is an empty list.
Example 3: Hosted Feature Layer
Item usage via the item page
Item usage via the Python API --- matches the item page
@mpboyle just wondering if you found a resolution to this issue?
I am experiencing the same issue when trying to get usage statistics for hosted tile layers, using the .usage() method from the arcgis api for python the code works fine for other service types but for hosted tile layers the dataframe is empty and no statistics are retrieved.
@DeirdreSmyth
Nope, it's super frustrating. We have multiple hosted tile layers containing imagery projects that we'd like to be able to easily track usage on, but these item types (Map Service) don't return any usage data even though the Usage tab on the item page does.
Hosted vector tile layers are another item type that doesn't return any usage data through the Python API. Again, super frustrating as we use hosted vector tiles for our organizational base maps and we'd like to be able to track usage on those items too.
Below are some examples. We're a County government, our items are open to the public. Item identifiers provided for testing.
Hosted Tile Layer example
Hosted Vector Tile Layer example
Perhaps someone associated with Esri can provide some insight why these particular item types don't return any data through the Python API...?
@ShareUser @KellyGerrow @JakeSkinner
Hi @mpboyle ,
I have not been able to get the .usage method to work but I did find some information on using the usage REST endpoint - https://community.esri.com/t5/arcgis-online-questions/how-to-get-credit-usage-by-an-application-usin... this call is about credits but you can do the same for usage.
Essentially it uses the same usage url that the Usage page of an service.
url = "https://your_portal/sharing/rest/portals/<portalid>/usage?"
The you append parameters for the start and end date etc., you can do it with setting parameters and using the urllib
#set parameters of request
params = {
'f': 'json',
'startTime': int(start.timestamp() * 1000), # Adjust start time as needed (e.g., in epoch milliseconds)
'endTime': int(end.timestamp() * 1000),
'period':'1d',
'vars':'num', #gets the usage statistics, can be num, credits or bandwidth(bw)
'groupby': 'name',
'etype':'svcusg',
'name':item.name,
'stype':'tiles',
'token': gis._con.token
}
# 3. Make the API request
encoded_params = urllib.parse.urlencode(params).encode('utf-8')
req = urllib.request.Request(url, data=encoded_params)
response = urllib.request.urlopen(req)
or in the call above he's constructed the url from variables:
reportURL = f'https://[your-org].maps.arcgis.com/sharing/rest/portals/[portalID]/usage?startTime={round(enddate.timestamp()*1000)}&endTime={round(enddate.timestamp()*1000)}&period=1h&appId={app_id}&vars=credits,num,bw&groupBy=etype,stype&f=json&token={the_token}'