Skip to main content
Solved

Campaign API multiple filters

  • August 23, 2024
  • 3 replies
  • 286 views

Forum|alt.badge.img+3
  • Partner - Platinum
  • 2 replies

Feels like a basic question but I can’t seem to stack multi filters to my campaign API request. I want to be able to get all email campaigns for this month so I have something like this:

 

and(equals(messages.channel,'email'),greater-or-equal(created_at,'2024-08-01T00:00:00-07:00'))

 

and the url request looks like

 curl --request GET \curl --request GET \
     --url 'https://a.klaviyo.com/api/campaigns/?filter=equals%28messages.channel%2C%27email%27%29%2Cgreater-or-equal%28updated_at%2C%272024-08-01T00%3A00%3A00-07%3A00%27%29' \
     --header 'Authorization: Klaviyo-API-Key XXXXXXXXX' \
     --header 'accept: application/json' \
     --header 'revision: 2024-07-15'

 

When running it though, I get invalid filter. I feel like this is a simple fix but i am not seeing it. Any assistance would be great.

Best answer by Kim Strauch

Hey @cLin

Try removing the quotes from the datetime in your filter, i.e. and(equals(messages.channel,'email'),greater-or-equal(created_at,2024-08-01T00:00:00-07:00))
 

Datetimes should be specified without quotes. See our guide on filters for some examples: https://developers.klaviyo.com/en/docs/filtering_ 

Ideally we can provide a more helpful error message for this in the future, as it’s tricky to catch otherwise! 

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

Kim Strauch
Klaviyo Employee
Forum|alt.badge.img+9
  • Klaviyo Employee
  • 91 replies
  • Answer
  • August 30, 2024

Hey @cLin

Try removing the quotes from the datetime in your filter, i.e. and(equals(messages.channel,'email'),greater-or-equal(created_at,2024-08-01T00:00:00-07:00))
 

Datetimes should be specified without quotes. See our guide on filters for some examples: https://developers.klaviyo.com/en/docs/filtering_ 

Ideally we can provide a more helpful error message for this in the future, as it’s tricky to catch otherwise! 


Forum|alt.badge.img+3
  • Author
  • Partner - Platinum
  • 2 replies
  • August 30, 2024

Ah...ok that makes sense. The filters are working now.


Forum|alt.badge.img+3
  • Author
  • Partner - Platinum
  • 2 replies
  • August 30, 2024
Kim Strauch wrote:

Hey @cLin

Try removing the quotes from the datetime in your filter, i.e. and(equals(messages.channel,'email'),greater-or-equal(created_at,2024-08-01T00:00:00-07:00))
 

Datetimes should be specified without quotes. See our guide on filters for some examples: https://developers.klaviyo.com/en/docs/filtering_ 

Ideally we can provide a more helpful error message for this in the future, as it’s tricky to catch otherwise! 

Is it the same for flows? I tried this and got a similar error, I also tried updated_at in case that was a misspelling.

 

 https://a.klaviyo.com/api/flows/?filter=greater-or-equal(updated,2024-08-01T00:00:00-07:00)` resulted in a `400 Bad Request` response:
{"errors":[{"id":"dc4f8e79-bf79-4801-8be7-500c59c18e5c","status":400,"code":"invalid","title":"Invalid input.","detail": (truncated...)