Skip to main content
Contributor I
February 16, 2023
Solved

Invalid filter provided when filtering profiles

  • February 16, 2023
  • 2 replies
  • 757 views

Hi, Im trying to use the new API to check for the existence of a profile before creating a new one. (I miss the old way of it automatically updating existing profiles if they already existed when adding to a list). I’ve tried invoking the profiles endpoint from curl and python without success. The following is an example generated from the documentation:

import requests

url = "https://a.klaviyo.com/api/profiles/?fields[profile]=email&filter=testuser"

headers = {
"accept": "application/json",
"revision": "2023-01-24",
"Authorization": "Klaviyo-API-Key MY_PRIVATE_KEY_HERE"
}

response = requests.get(url, headers=headers)
print(response.text)

It doesn't matter what field I choose for the profile whether phone number, first name, etc. The result is always:

{"errors":[{"id":"54d8f624-127d-48db-b568-cfb3d6abeb1b","status":400,"code":"invalid","title":"Invalid input.","detail":"Invalid filter provided.","source":{"parameter":"filter"},"meta":{}}]}

 

Thanks for any guidance.

    This topic has been closed for replies.
    Best answer by Brian Turcotte

    Hi @dan fellow and welcome to the Community!

     

    This is the correct endpoint, but one thing that I was able to notice is that fields[profile]=email&filter=testuser is actually not a valid filter. To search for an email (which is what I understand you’re looking to do there), I recommend you implement this filtering logic:
     

    In this case, ?fields[profile]=email would be a sparse fieldset, and you would only get an email back, but the filter should be filter=equals(profile.email,%22testuser%22) (substituting “testuser” for a valid email address).

     

    I hope this helps, and thanks for using the Community!

    - Brian

    2 replies

    Brian Turcotte
    Klaviyo Alum
    February 17, 2023

    Hi @dan fellow and welcome to the Community!

     

    This is the correct endpoint, but one thing that I was able to notice is that fields[profile]=email&filter=testuser is actually not a valid filter. To search for an email (which is what I understand you’re looking to do there), I recommend you implement this filtering logic:
     

    In this case, ?fields[profile]=email would be a sparse fieldset, and you would only get an email back, but the filter should be filter=equals(profile.email,%22testuser%22) (substituting “testuser” for a valid email address).

     

    I hope this helps, and thanks for using the Community!

    - Brian

    Contributor I
    February 21, 2023

    Thanks a lot. Somehow I was never able to find that documentation when searching for the proper syntax. Works great now.