Is it possible to use the endpoint https://a.klaviyo.com/api/profiles/ to get profiles but to also include the lists/segments the given profile belongs too when the profiles are returned? For example, the return JSON (converted to an array) might look like this, notice the [lists]. Is that a thing?
[0] => Array
(
[type] => profile
[id] => 01JG48MC57BDNNTM48P4802M2Z
[attributes] => Array
(
[email] => john@yahoo.com
[phone_number] => 289-821-1111
[lists] => SZsV82,X5xDmn,etc.
[first_name] => John
[last_name] => Doe
Get profiles but with the lists they are included on?
Best answer by Christiannoerbjerg
Hi
Thank you for posting in the Community!
Yes, it is possible to retrieve a profile's list and segments using Klaviyo's API, though it requires additional steps beyond fetching the profile's basic information. Here's how you can achieve this:
Step 1: Retrieve profile information:
Use the https://a.klaviyo.com/api/profiles/{profile_id}/
endpoint to get the basic profile information. Replace {profile_id}
with the actual merge tag for the profile ID. This will return details like email, phone number, first name, last name, etc., but not the lists or segments.
Step 2: Retrieve lists:
To find out which lists a profile belongs to, use the https://a.klaviyo.com/api/profiles/{profile_id(Merge tag)}/relationships/lists/
endpoint. This will provide the lists for the specified profile.
Step 3: Retrieve segments:
Similarly, to get the segments a profile is part of, use the https://a.klaviyo.com/api/profiles/{profile_id(Merge tag)}/relationships/segments/
endpoint. This will return the segments for the profile.
Combining the data:
After fetching the list and segments, you can combine this information with the profile details to create a comprehensive data structure. Your final JSON might look like this:
{
"type": "profile",
"id": "Merge tag (Profile ID)",
"attributes": {
"email": "E-mail (Merge tag)",
"phone_number": "Phone Number (Merge tag)",
"first_name": "First name (Merge tag)",
"last_name": "Last name (Merge tag)",
"lists": ["List_ID_1", "List_ID_2"],
"segments": ["Segment_ID_1", "Segment_ID_2"]
}
}
Hope that helps or else, let me know! :-)
Christian Nørbjerg Enger
Partner & CPO
Web: Segmento.dk
LinkedIn: @christianfromsegmento
Voldbjergvej 22b, 8240 Risskov
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.