Skip to main content
popsmash
Active Contributor III
Active Contributor III
March 2, 2023

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

  • March 2, 2023
  • 12 replies
  • 552 views

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

    KeviSunshine
    Expert Problem Solver III
    Expert Problem Solver III
    March 3, 2023

    Hi @popsmash,

     

    Great question. I love the + trick for emails–I use it all the time and I know I’ve triggered events via the API with profiles with a  + in their email.

     

    I gave this a go with the link you shared (thanks for that, didn’t know about that filter syntax) and although it’s not working with a +, it’s working for me when I URL encode it to %2B. Try URL encoding again!! I didn’t encode the whole email address–just the +.

     

    Request URL: https://a.klaviyo.com/api/profiles?filter=equals(email,"testing%2B123@example.com")

     

    Cheers,

    Kevin.

    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    March 3, 2023

    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...

    POPSMASH: Making marketing personal at https://www.popsmash.com
    Klaviyo Employee
    March 3, 2023

    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 ?

    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    March 4, 2023

    @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
    March 6, 2023

    @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
    March 6, 2023

    @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
    popsmash
    Active Contributor III
    popsmashAuthor
    Active Contributor III
    June 27, 2023

    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
    Brian Turcotte
    Klaviyo Alum
    June 27, 2023

    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
    June 27, 2023

    Thanks @Brian Turcotte, we appreciate it!

    POPSMASH: Making marketing personal at https://www.popsmash.com
    Kim Strauch
    Klaviyo Employee
    Klaviyo Employee
    August 19, 2023

    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.