Hi @kenw222!
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