Skip to main content
Contributor I
December 28, 2024
Solved

Get profiles but with the lists they are included on?

  • December 28, 2024
  • 2 replies
  • 80 views

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

    This topic has been closed for replies.
    Best answer by Christiannoerbjerg

    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

    2 replies

    MANSIR2094
    Expert Problem Solver IV
    Expert Problem Solver IV
    December 28, 2024

    Hello ​@kenw222 

    No, Klaviyo's /api/profiles/ endpoint does not include lists or segments the profile belongs to in its response by default. To retrieve that data, you would need to use additional calls to the /api/lists/ and /api/segments/ endpoints to cross-reference the profile's membership.

     

     

    Mansir Digital Portfolio
    Christiannoerbjerg
    Expert Problem Solver II
    2025 Champion
    December 29, 2024

    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