Skip to main content

Hi - I’ve been using APIv2 without issue, however have recently started playing around wit the new beta API and beta PHP SDK.

It's probably really simple, but I’m really struggling to figure out the correct syntax for the $filter  argument when using the beta php sdk.

No issue setting up the SDK, or running operations without any filters, but as soon as I try and add a filter…. well I'm obviously doing something very wrong.

The SDK docs indication $filter requires a string.

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $fields_profile | string|]
# $filter | string
# $page_cursor | string

client->Lists->getListProfiles($list_id, $fields_profile=$fields_profile, $filter=$filter, $page_cursor=$page_cursor);
 

In this instance, how would I use ?filter=equals(last_name,"Smith") filter (the first example here: https://developers.klaviyo.com/en/v2022-09-07.pre/docs#filtering )

 

Many thanks

 

Hi @Stef,

Thanks for sharing this question with us.

I can see you’re in touch with a member of our support staff on this question. When you reach a resolution, it would be helpful if you could provide a quick update here for anyone else following along.

Thanks for being a community member.


Hi - I shared what I was trying to achieve with support, and think I’ve figured it out in the meantime (edit: which has just been confirmed as I type this!)

 

Using the beta API, I was trying to see if an email address had a profile in a specific list.
All the filter operators and arguments I was trying returned various 400 errors.

 

I misunderstood the docs, thinking that I could use the ‘equals’ filter operator with email. In fact it needs to be the ‘any’ operator for email addresses.


This is what was NOT working:

GET https://a.klaviyo.com/api/lists/{{list_id}}profiles/?filter=equals(email,"jane@doe.com")

 

This is what DOES work:
GET https://a.klaviyo.com/api/lists/{{list_id}}/profiles/?filter=any(email,?"jane@doe.com"])

 

or if using the PHP SDK: $filter = "any(email,i\"jane@doe.com\"])";

 

Also, what caught me out was the filtering by email address seems to require an array, even if only 1 email address is used. Notice on the working example that the email address is wrapped in square array brackets. This could easily return multiple profiles for multiple email addresses, like:
?filter=any(email,/“jane@doe.com","john@buck.com"]).  This is not currently shown on the beta filter reference docs. (no spaces between the addresses though!).

 

Probably really obvious for most, but took me a little while!  :)

 


Reply