Content
You are here:
API Access with Python
Added by Joseph O. over 8 years ago
All,
Any and all help from everyone is very appreciated!
I’ve been trying to do some performance metrics based upon tasks in my project. I’ve written the following code which pulls the work packages by project.
theParams = {"pageSize": 1, "offset": 1, } r = requests.get('http://myurl.com/api/v3/projects/myID/work_packages/', auth=('apikey', 'mySuperFakeAPIKey12345'), params=theParams) print (r.json())
I really could use some assistance here. While I’m able to retrieve, I’d really could use some help regarding the syntax needed to filter the work packages by date. I’d like to pull only the last months worth of data back or all work packages between two dates.
Thanks for your assistance!
Joseph
Replies (5)
Hey Joseph,
I fully understand your need for assistance. Our own APIv3 queries in the work packages still uses the syntax from a previous API and filtering work packages is not really documented in our APIv3 documentation.
You can observe the GET requests to
/api/experimental/projects/<project>/work_packages
to receive information on the filter syntax in themeta.query
response of that object.A typical query filters object will look something like:
and means
Filter attribute "status" by operator "open"
(no value required) ANDFilter attribute "type" for ID=1
.There are numerous operators and filters that I don’t know by heart. The method
Query#sql_for_field
contains a joyful case statement with some 20+ possible values.Unfortunately, the APIv3 doesn’t accept the filter string as above, but needs to be slightly modified to the syntax
attribute: { operator: X, values: Y }
To list work packages that were created in the last 30 days, you can use the following APIv3 filter URL
http://myurl.com/api/v3/work_packages?filters=[{"createdAt": {"operator": ">t-" ,"type": "date_past", "values":["30"]}}]
.Best,
Oliver
Oliver! You’re assistance is great appreciated.
I’ve done experimentation this morning and it looks like the “values” parameter is the number of days. Hence my query looks something like this to pull back the last 30 days worth:
http://myurl.com/api/v3/work_packages?filters=[{"createdAt": {"operator": ">t-" ,"type": "date_past", "values":["30"]}}]
Would you happen to have an example for filtering on “createdAt” which falls between two dates? This would be extremely useful if I needed to calculate metrics by “week” such that I were calculated between May 16 and May 23 as an example.
Thanks!
Joseph
Hey Joseph,
Unfortunately, there seems to be no between filter operator for dates.
Best,
Oliver
Hi all,
any news about searching between two dates?
Thanks
Hi Anto,
Yes! Good news, with OpenProject 7.0.,its possible to search for a
between
range of dates and datetimes.See this example for a filter of tickets updated in the last week:
Best,
Oliver