Skip to main content
Contributor I
February 7, 2023
Solved

Get Events API: is there a way to pass a date range

  • February 7, 2023
  • 4 replies
  • 359 views

I’m using the Get Events API (2023-01-24) and trying to get events using a filter that includes events that occurred greater than or equal to {{date 1}} and less than {{date 2}}.   I'm able to successfully get data using greater-than-equal, but as soon as I add “and” and the ‘less than’ date, I get a 400.  Could be the filter is incorrect.. but hoping someone has an example.  Here is what we are currently passing:

?filter=and(greater-or-equal(datetime,1970-01-01T12:00:00Z), less-than(datetime,2023-02-07T17:40:09.274Z))
    This topic has been closed for replies.
    Best answer by Brian Turcotte

    Hi@LoriM!

     

    I’m so sorry for the delay in response here!

     

    Unless I’m mistaking your intent, I don’t believe you need the “and” logic to include both the greater-or-equal and less-than modifiers. We did some testing, and a call in this format should yield the desired results:

    {{baseUrl}}/api/events/?filter=greater-or-equal(datetime,2022-04-01T11:30:00Z),less-than(datetime,2022-07-01T11:30:00Z)

     

    If you remove the and statement, does the error still persist?

     

    Thanks,

    Brian

    4 replies

    Brian Turcotte
    Klaviyo Alum
    February 8, 2023

    Hi @LoriM and welcome to the Community!

     

    From my perspective, it looks like the call is formatted correctly, so I am going to reach out to Engineering to see if they can provide some more context here. Especially since this other Community member mentioned the exact same issue on the same day, here:

     

    I will update the thread as soon as I learn more about what could be causing this. 

     

    Thanks for using the Community!

    - Brian

    LoriMAuthor
    Contributor I
    February 21, 2023

    Hi Brian - I was just curious if you had heard anything back on this one yet.  Thanks!

    Brian Turcotte
    Klaviyo Alum
    March 20, 2023

    Hi@LoriM!

     

    I’m so sorry for the delay in response here!

     

    Unless I’m mistaking your intent, I don’t believe you need the “and” logic to include both the greater-or-equal and less-than modifiers. We did some testing, and a call in this format should yield the desired results:

    {{baseUrl}}/api/events/?filter=greater-or-equal(datetime,2022-04-01T11:30:00Z),less-than(datetime,2022-07-01T11:30:00Z)

     

    If you remove the and statement, does the error still persist?

     

    Thanks,

    Brian

    LoriMAuthor
    Contributor I
    March 21, 2023

    yes, that worked, thank you Brian!