Skip to main content
Solved

How to subscribe a user with API and save their name?


Forum|alt.badge.img+1

I want to subscribe a user with email and their name, but it gives this error: 'first_name' is not a valid field for the resource 'profile'.

Im using the Klaviyo PHP SDK.

It works if i just remove first_name and last_name from attributes… But i want to include the name.
Code:

$klaviyo->Profiles->subscribeProfiles([
    "data" => [
        'type'          => 'profile-subscription-bulk-create-job',
        'attributes'    => [
            'custom_source' => 'Marketing Event',
            'profiles'      => [

                'data' => [
                    [
                        'type'       => 'profile',

                        'attributes' => [
                            'email'         => 'email@email.com',
                            'first_name'=>'firstname',
                            'last_name'=>'lastname',
                            'subscriptions' => [
                                'email' => [
                                    'marketing' => [
                                        'consent' => 'SUBSCRIBED',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
        'relationships' => [
            'list' => [
                'data' => [
                    'type' => 'list',
                    'id'   => 'MYLISTID',
                ],
            ],
        ],
    ],
]);

Best answer by KeviSunshine

Hey there @AlexVjm,

 

I thought you must have a syntax error or something but no! It doesn’t work! I can confirm that adding a first_name (or $first_name, firstName, $firstName, properties: { first_name }, etc.) does not work for the bulk-subscribe endpoint.

You are returned the following error:

{
    "errors": [
        {
            "id": "d121de2f-710b-4d2f-a6cb-d0723610ed93",
            "status": 400,
            "code": "invalid",
            "title": "Invalid input.",
            "detail": "'$firstname' is not a valid field for the resource 'profile'.",
            "source": {
                "pointer": "/data/attributes/profiles/data/0/attributes/$firstname"
            },
            "meta": {}
        }
    ]
}

The documentation reflects this: the only attributes available are email, phone, and subscriptions.

But this can’t be right…

 

Anyone else know how to include profile properties on the bulk subscribe endpoint?

 

Cheers,

Kevin.

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

3 replies

KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 159 replies
  • Answer
  • December 1, 2023

Hey there @AlexVjm,

 

I thought you must have a syntax error or something but no! It doesn’t work! I can confirm that adding a first_name (or $first_name, firstName, $firstName, properties: { first_name }, etc.) does not work for the bulk-subscribe endpoint.

You are returned the following error:

{
    "errors": [
        {
            "id": "d121de2f-710b-4d2f-a6cb-d0723610ed93",
            "status": 400,
            "code": "invalid",
            "title": "Invalid input.",
            "detail": "'$firstname' is not a valid field for the resource 'profile'.",
            "source": {
                "pointer": "/data/attributes/profiles/data/0/attributes/$firstname"
            },
            "meta": {}
        }
    ]
}

The documentation reflects this: the only attributes available are email, phone, and subscriptions.

But this can’t be right…

 

Anyone else know how to include profile properties on the bulk subscribe endpoint?

 

Cheers,

Kevin.


  • Contributor I
  • 1 reply
  • March 12, 2024

Why is this marked as 'solved’?


Forum|alt.badge.img
  • Contributor I
  • 3 replies
  • May 29, 2024

Hi @AlexVjm 
maybe late but hope it could be usefull for similar task.
latest api version revision: 2024-05-15 show that you need to create profile to add user details
 

{
  "data": {
    "type": "profile",
    "attributes": {
      "email": "sarah.mason@klaviyo-demo.com",
      "phone_number": "+15005550006",
      "first_name": "Sarah",
      "last_name": "Mason",
      "organization": "Example Corporation",
      "title": "Regional Manager",
      "image": "https://images.pexels.com/photos/3760854/pexels-photo-3760854.jpeg",
      "location": {
        "address1": "89 E 42nd St",
        "address2": "1st floor",
        "city": "New York",
        "country": "United States",
        "region": "NY",
        "zip": "10017",
        "timezone": "America/New_York",
        "ip": "127.0.0.1"
      },
      "properties": {
        "newKey": "New Value"
      }
    }
  }
}

so easier way is Create Profile details, store klaviyo Profile ID and then subscribe to list using email or ID just generate
 

​​​​​​​$klaviyo->Profiles->createProfile($body);
$klaviyo->Profiles->subscribeProfiles($body);