Skip to main content
popsmash
Active Contributor III
Active Contributor III
Mar 2, 2023 11:42 PM UTC

Bug: Unable to filter emails containing "+" character in API

While attempting to get a profile by email I discovered that filtering is broken for emails containing a “+” character.

URL-encoding the + to %2B also doesn’t seem to work.

Works

?filter=equals(email,"user@popsmash.com")

== RESPONSE ==

{
"data": [
{
"type": "profile",
"id": "01GT84QJYY1DMSR8J9JY454Z86",
"attributes": {
"email": "user@popsmash.com"
}
}
]
}

Does not work

?filter=equals(email,"user+test@popsmash.com")
?filter=equals(email,"user%2Btest@popsmash.com") // URL encoded "+"

== RESPONSE ==

{
"data": []
}

 

    This topic has been closed for replies.

    12 replies

    Kim Strauch
    Klaviyo Employee
    Klaviyo Employee
    Aug 20, 2023 9:52 PM UTC

    Interesting. I think the API request application you’re using is additionally URI encoding the entire request URL that is causing some problems here. I was able to look up the error ID you included and it seems the URL that’s being requested here is https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields%5Bprofile%5D=email&filter=any(email%252C%255B%2522fjarrett%252B47%2540gmail.com%2522%255D)

    When I request the URL shared above it works for me and I don’t run into an invalid filter error. 

    If you use one of our Postman collections, you can update the value for the filter param and then select the text and hit “Encode URI Component” to encode it properly. Here’s a link to our latest Postman collection you can use, and some screenshots showing the steps I used. 
     


     

     

    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    Aug 20, 2023 6:03 PM UTC

    @Kim Strauch thanks for the message. When I use the URL format you are suggesting it results in a filter input error. Is it working for you?

    {
    "errors": [
    {
    "id": "9ca07d48-74f3-4026-9306-e64fbd86c724",
    "status": 400,
    "code": "invalid",
    "title": "Invalid input.",
    "detail": "Invalid filter provided.",
    "source": {
    "parameter": "filter"
    },
    "meta": {
    }
    }
    ]
    }

     

     

    POPSMASH: Making marketing personal at https://www.popsmash.com
    Kim Strauch
    Klaviyo Employee
    Klaviyo Employee
    Aug 19, 2023 8:42 PM UTC

    Hey @popsmash! I think you need to use encodeURIComponent (or your language’s equivalent) on the query param value in order to account for special characters like a “+”. 


    Given your example of 

    https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields[profile]=email&filter=any(email,["fjarrett+47@gmail.com"])
     

    Using Javascript, if you call encodeURIComponent(`any(email,["fjarrett+47@gmail.com"])`), you get `any(email%2C%5B%22fjarrett%2B47%40gmail.com%22%5D)`

     

    If you then append that to the query string, and call GET https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields[profile]=email&filter=any(email%2C%5B%22fjarrett%2B47%40gmail.com%22%5D), do you get the result you’re expecting?

    See  our guide on filtering as well as this SO post for more details on encoding. 

    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    Jun 27, 2023 6:30 PM UTC

    Thanks @Brian Turcotte, we appreciate it!

    POPSMASH: Making marketing personal at https://www.popsmash.com
    Brian Turcotte
    Klaviyo Alum
    Jun 27, 2023 9:04 AM UTC

    Hi @popsmash!

    I will forward this to our product team and get back to the thread as soon as possible!

     

    - Brian

    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    Jun 27, 2023 1:18 AM UTC

    For anyone else affected, this is still a bug in v2023-06-15 of the API:

     

    [1] https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields[profile]=email&filter=any(email,["fjarrett+47@gmail.com"])

    {
    "data": [
    ],
    "links": {
    "self": "https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields%5Bprofile%5D=email&filter=any(email,%5B%22fjarrett+47@gmail.com%22%5D)",
    "next": null,
    "prev": null
    }
    }

    [2] https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields[profile]=email&filter=any(email,["fjarrett%2B47@gmail.com"])

    {
    "data": [
    ],
    "links": {
    "self": "https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields%5Bprofile%5D=email&filter=any(email,%5B%22fjarrett%252B47@gmail.com%22%5D)",
    "next": null,
    "prev": null
    }
    }

     

    But we can see the email exists when querying the whole list:

    https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields[profile]=email

    {
    "data": [
    {
    "type": "profile",
    "id": "01GV92V6MQMSWMWYDVJQWGPP9K",
    "attributes": {
    "email": "fjarrett+47@gmail.com"
    },
    "relationships": {
    "lists": {
    "links": {
    "self": "https://a.klaviyo.com/api/profiles/01GV92V6MQMSWMWYDVJQWGPP9K/relationships/lists/",
    "related": "https://a.klaviyo.com/api/profiles/01GV92V6MQMSWMWYDVJQWGPP9K/lists/"
    }
    },
    "segments": {
    "links": {
    "self": "https://a.klaviyo.com/api/profiles/01GV92V6MQMSWMWYDVJQWGPP9K/relationships/segments/",
    "related": "https://a.klaviyo.com/api/profiles/01GV92V6MQMSWMWYDVJQWGPP9K/segments/"
    }
    }
    },
    "links": {
    "self": "https://a.klaviyo.com/api/profiles/01GV92V6MQMSWMWYDVJQWGPP9K/"
    }
    },
    ],
    "links": {
    "self": "https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields%5Bprofile%5D=email",
    "next": null,
    "prev": null
    }
    }

     

    Filtering emails that do not have a “+” character works perfectly fine:

    https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields[profile]=email&filter=any(email,["hello@popsmash.com"])

    {
    "data": [
    {
    "type": "profile",
    "id": "01GVCM533GG3VAFYB6R31NH9VT",
    "attributes": {
    "email": "hello@popsmash.com"
    },
    "relationships": {
    "lists": {
    "links": {
    "self": "https://a.klaviyo.com/api/profiles/01GVCM533GG3VAFYB6R31NH9VT/relationships/lists/",
    "related": "https://a.klaviyo.com/api/profiles/01GVCM533GG3VAFYB6R31NH9VT/lists/"
    }
    },
    "segments": {
    "links": {
    "self": "https://a.klaviyo.com/api/profiles/01GVCM533GG3VAFYB6R31NH9VT/relationships/segments/",
    "related": "https://a.klaviyo.com/api/profiles/01GVCM533GG3VAFYB6R31NH9VT/segments/"
    }
    }
    },
    "links": {
    "self": "https://a.klaviyo.com/api/profiles/01GVCM533GG3VAFYB6R31NH9VT/"
    }
    }
    ],
    "links": {
    "self": "https://a.klaviyo.com/api/lists/VFMwXV/profiles?fields%5Bprofile%5D=email&filter=any(email,%5B%22hello@popsmash.com%22%5D)",
    "next": null,
    "prev": null
    }
    }

     

    POPSMASH: Making marketing personal at https://www.popsmash.com
    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    Mar 6, 2023 3:18 PM UTC

    @saulblum lowercase %2b also does not work, still behaving like a bug for me. Are you using revision 2023-02-22?

    POPSMASH: Making marketing personal at https://www.popsmash.com
    Klaviyo Employee
    Mar 6, 2023 1:25 AM UTC

    @popsmash Odd, usually encoding a plus sign to %2b does the trick. I assume lowercase vs. uppercase B shouldn’t matter.

    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    Mar 4, 2023 4:27 PM UTC

    @saulblum oh that is a fake email posted here for demonstration purposes.

    Real examples below...

     

    Works

     

    Does not work

     

    Profile exists

     

    POPSMASH: Making marketing personal at https://www.popsmash.com
    Klaviyo Employee
    Mar 3, 2023 2:42 PM UTC

    Hey @KeviSunshine, thanks for hoping in and checking this!

    So wild that it still doesn’t work for me, even with %2B.

    I’ll have to think about what else could be going on here...

    Could you post a screenshot of Klaviyo profile page for the profile with email user+test@popsmash.com ?