Using PHP with the REST API. How does one use a date range to get time logs via querystring,. I’ve worked out a singular date using the filter in the querystring. Does it take 2 dates, a start point and duration?
Hi Chad,
Check out the “Operators and Arguments” here:
https://developer.shotgunsoftware.com/rest-api/#complex-filters
There are a few date operators which you can use depending on your need. Based on your description it sounds like between
would work best for you where you can specify two dates in the condition.
Confused, as the complex filters seems to want the filter sent in the request body, but it’s a GET request. But complex is what I would need as I’m trying to get Timelogs belonging to a specific user between 2 dates.
Hey Chad!
Sorry that you’ve had to wait for a response. Hopefully you’ve already figured it out, but in case you haven’t, here’s what I did:
I used a POST request (‘search all records’ is POST, vs ‘read all records’, which as you noted, is GET) pointed at /api/v1/entity/event_log_entries/_search
, with the following:
payload = {
'filters': {
'logical_operator': 'and',
'conditions': [
[
'created_at',
'between',
[
datetime.datetime(2020,1,1,0,0,0).strftime('%Y-%m-%dT%H:%M:%S.%f%z'),
datetime.datetime(2020,1,1,1,0,0).strftime('%Y-%m-%dT%H:%M:%S.%f%z')
]
],
[
'user',
'is',
{
'type':'HumanUser',
'id':24
}
]
]
},
'fields': [
'created_at',
'user'
]
}
Note that the date_time request needs to be in ISO8601 format, but you probably already got that part. And obviously, I’ve searched event log entries, where you’re looking for Timelogs (which will have different field names).
I hope that helps! Let me know if you have any other questions
Tony,
Thank you for that answer and my apologies for missing it. If I were to want to get time logs between a date range and a field other than the user, such as an attribute field of the time log.
Would something like
[
‘attribute’,
‘is’,
{
‘type’:‘fieldName’,
‘value’:‘some value’
}
]
Hi @chadworkman
The above example is for entity.
[
"field_code",
"is",
{
"type":"Entity Type",
"value":"some value"
}
]
If the field type isn’t an entity, you could use it like this.
[
"field_code",
"is",
"some value"
]
Revisiting. When I run the example payload the API returns
Query is not an Array: {"logical_operator"=>"and", "conditions"=>[["created_at", "between", ["2018-12-01T00:00:00", "2020-12-01T00:00:00"]], ["user", "is", {"type"=>"HumanUser", "id"=>24}]]}",
Not sure why though
Still cannot sort out why I get this error.
When using the complex filter, you should set Content-Type of header to ‘application/vnd+shotgun.api3_hash+json’ instead of ‘application/vnd+shotgun.api3_array+json’.