# Rest API Date Range

**URL:** <https://community.shotgridsoftware.com/t/rest-api-date-range/8534>\
**Category:** Pipeline Integrations\
**Created:** [May 5, 2020, 11:42pm UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534 "2020-05-05T23:42:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chadworkman](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chadworkman](https://community.shotgridsoftware.com/u/chadworkman)\
**Post date:** [May 5, 2020, 11:42pm UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/1 "2020-05-05T23:42:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![brandon.foster](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/brandon.foster/32/91_2.png) [@brandon.foster](https://community.shotgridsoftware.com/u/brandon.foster)\
**Post date:** [May 7, 2020, 11:49am UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/2 "2020-05-07T11:49:44Z")

</div>

Hi Chad,

Check out the “Operators and Arguments” here:

[https://developer.shotgunsoftware.com/rest-api/#complex-filters](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.

---

<div class="post-metadata">

**Author:** ![chadworkman](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chadworkman](https://community.shotgridsoftware.com/u/chadworkman)\
**Post date:** [May 7, 2020, 9:11pm UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/3 "2020-05-07T21:11:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tony](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/tony/32/197_2.png) [@tony](https://community.shotgridsoftware.com/u/tony)\
**Post date:** [May 13, 2020, 7:24pm UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/4 "2020-05-13T19:24:47Z")

</div>

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](https://developer.shotgunsoftware.com/rest-api/?python#search-all-records) 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:

```auto
    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 😃

---

<div class="post-metadata">

**Author:** ![chadworkman](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chadworkman](https://community.shotgridsoftware.com/u/chadworkman)\
**Post date:** [September 12, 2020, 2:55am UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/7 "2020-09-12T02:55:35Z")

</div>

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’  
> }  
> ]

---

<div class="post-metadata">

**Author:** ![jing.liu](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/jing.liu/32/888_2.png) [@jing.liu](https://community.shotgridsoftware.com/u/jing.liu)\
**Post date:** [September 13, 2020, 11:24pm UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/8 "2020-09-13T23:24:31Z")

</div>

Hi @chadworkman

The above example is for entity.

```auto
[
    "field_code",
    "is",
    {
        "type":"Entity Type",
        "value":"some value"
    }
]

```

If the field type isn’t an entity, you could use it like this.

```auto
 [
      "field_code",
      "is",
      "some value"
]

```

---

<div class="post-metadata">

**Author:** ![chadworkman](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chadworkman](https://community.shotgridsoftware.com/u/chadworkman)\
**Post date:** [December 3, 2020, 9:59pm UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/9 "2020-12-03T21:59:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chadworkman](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chadworkman](https://community.shotgridsoftware.com/u/chadworkman)\
**Post date:** [December 16, 2020, 5:23am UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/10 "2020-12-16T05:23:05Z")

</div>

Still cannot sort out why I get this error.

> [@chadworkman](#):
>
> 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}]]}",

---

<div class="post-metadata">

**Author:** ![sichoi](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@sichoi](https://community.shotgridsoftware.com/u/sichoi)\
**Post date:** [January 11, 2022, 1:08am UTC](https://community.shotgridsoftware.com/t/rest-api-date-range/8534/12 "2022-01-11T01:08:42Z")

</div>

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’.
