Skip to main content

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


popsmash
Active Contributor III
Forum|alt.badge.img+4
  • Active Contributor III
  • 22 replies

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": []
}

 

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

12 replies

KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 158 replies
  • 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
Forum|alt.badge.img+4
  • Author
  • Active Contributor III
  • 22 replies
  • 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...


Forum|alt.badge.img+7
  • Klaviyo Employee
  • 168 replies
  • March 3, 2023
popsmash wrote:

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
Forum|alt.badge.img+4
  • Author
  • Active Contributor III
  • 22 replies
  • March 4, 2023

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

Real examples below...

 

Works

 

Does not work

 

Profile exists

 


Forum|alt.badge.img+7
  • Klaviyo Employee
  • 168 replies
  • 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
Forum|alt.badge.img+4
  • Author
  • Active Contributor III
  • 22 replies
  • 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
Active Contributor III
Forum|alt.badge.img+4
  • Author
  • Active Contributor III
  • 22 replies
  • 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
  }
}

 


Brian Turcotte
Forum|alt.badge.img+37

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
Forum|alt.badge.img+4
  • Author
  • Active Contributor III
  • 22 replies
  • June 27, 2023

Thanks @Brian Turcotte, we appreciate it!


Kim Strauch
Klaviyo Employee
Forum|alt.badge.img+9
  • Klaviyo Employee
  • 91 replies
  • 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. 


popsmash
Active Contributor III
Forum|alt.badge.img+4
  • Author
  • Active Contributor III
  • 22 replies
  • August 20, 2023

@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": {
      }
    }
  ]
}

 

 


Kim Strauch
Klaviyo Employee
Forum|alt.badge.img+9
  • Klaviyo Employee
  • 91 replies
  • August 20, 2023

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.