Solved

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

  • 1 December 2023
  • 2 replies
  • 241 views

Badge

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',
                ],
            ],
        ],
    ],
]);

icon

Best answer by KeviSunshine 1 December 2023, 13:25

View original

2 replies

Userlevel 4
Badge +7

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.

Why is this marked as 'solved’?

Reply