Question

How can I add a new email to a list using API?

  • 30 April 2024
  • 1 reply
  • 32 views

Badge

I’m trying to build a custom form and I’m trying to capture emails for a newsletter. I want to add all the new captured emails to a specific list but I can’t seem to do with the Add Profile To List endpoint. The reason being because I don’t have the profile ID yet which this api requires.

Seems like in the last version, it was possible because I had to provide emails, not IDs for the endpoint to work.


1 reply

Badge +1

Hi @harishash,

The best way you can do this is to make another api call that is Get Profiles API with a filter specifying the email id which can give you the exact profile which will get you the id of the profile. This can be used to use Add Profile To List API using profile id.

To get profile using Get Profiles API you can use this:

GET https://a.klaviyo.com/api/profiles/=equals(email%2C%22testemail%klaviyo.com%22)

Here filter should have the email as first param and the value (encoded) as second value.

Example of this encoding used:

This will return you an array of objects that has id in every object.

And the filter syntax for reference:

 

Reference:

  1. Get Profiles API: https://developers.klaviyo.com/en/reference/get_profiles
  2. Filtering - https://developers.klaviyo.com/en/docs/filtering_

Reply