I have been pulling some item usage data from AGOL using the Python API item.usage().
Seems to be working fine for a few of the queries, and not for others.
from arcgis.gis import GIS,Item gis = GIS("https://<organiztion>.maps.arcgis.com","<username>","<password>") item = Item(gis,"<itemid>") chartdata = item.usage("<daterange>",as_df=True) print(chartdata)
The chart below shows which ones work for me.
If I run the 6M range, it returns:
Error generating usage report. None Error generating usage report
If I run the 1Y range, it returns:
Traceback (most recent call last): File "<filepath>.py", line 12, in <module> chartdata = item.usage("1Y",as_df=True) File "<windowsuserfolder>\AppData\Local\ESRI\conda\envs\new-environment\lib\site-packages\arcgis\gis\__init__.py", line 6371, in usage raise ValueError("Invalid date range.") ValueError: Invalid date range.
It doesn't matter whether you return the Pandas DataFrame or the python dictionary for the result, same errors get generated.
Am I missing something somewhere?
It would be really nice to get the longer date ranges for my automated reporting I'm working on.
Thanks for any help on this!!
Are you able to run the queries for 6 and 12 months in AGOL's web page interface? It could be an AGOL issue and what you are seeing is a symptom of that non-Python issue.
It seems the maximum days in one request is restricted to 60 days.
I searched 1 year in AGOL, and the startTime and endTime in the requests sent by the browser to AGOL are:
Convert these timestamp (in milliseconds) to datetime, you'll find the regularity: