API to Get Item Usage

1138
5
11-05-2018 04:56 AM
CameronMcCormick
Occasional Contributor

Good Morning,

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.

My python:

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.

errors

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!!


Cameron

0 Kudos
5 Replies
JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos
CameronMcCormick
Occasional Contributor

Yes both the 6 months and 1 year queries work in AGOL

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

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:

startTime: 1512283405000
endTime: 1517467405000

startTime: 1517467405000
endTime: 1522655005000

startTime: 1522655005000
endTime: 1527839005000

startTime: 1527839005000
endTime: 1533023005000

startTime: 1533023005000
endTime: 1538207005000

startTime: 1538207005000
endTime: 1543387405000

startTime: 1543387405000
endTime: 1543819405000

Convert these timestamp (in milliseconds) to datetime, you'll find the regularity:

For example:

time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1512283405))
'2017-12-03 17:13:25'
This is a bug for the API if the document clearly states it can take 6m and 1y as the date range. 
0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Cameron,

I was led here by your  post in GitHub, and I also commented there. 

item.usage() errors · Issue #321 · Esri/arcgis-python-api · GitHub 

Hope it makes sense.

Simo

simoxu
by MVP Regular Contributor
MVP Regular Contributor

This specific issue has been address in the new release of 1.5.2.

arcgis-python-api/release-notes.ipynb at master · Esri/arcgis-python-api · GitHub 

0 Kudos