Rest API Date Range

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?

3 Likes

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.

2 Likes

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.

1 Like

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 :smiley:

2 Likes