$body payload structure
tictok opened this issue · comments
Hi - hope someone can help. I suspect I'm making a fairly basic error.
I'm attempting to use the klaviyo-api-php library to add subscribers and update profiles.
I've already successfully used the php library to retrieve info on profiles i.e. using $klaviyo->Lists->getListProfiles($list_id, $fields_profile, $filter);
However I'm now really stuck when trying to subscribe a profile to list.
Error message returned is:
"status":400,"code":"invalid","title":"Invalid input.","detail":"The payload provided in the request is invalid.","source":{"pointer":"/data"},"meta":{}}]}
I can't figure out how to structure the data in the request $body.
I know it needs to be an associative array and have tried various options, but everything I try fails.
Below is my $body payload. (list_id removed)
I'd be really grateful if anyone could help me structure or format it correctly. I can't see where I'm going wrong!
Many thanks
$body = array(
'list_id' => 'LIST_ID',
'profiles' => array(
array(
'email' => 'user@example.com',
'properties' => array(
'$first_name' => 'John',
'$last_name' => 'Doe',
),
),
),
);
$klaviyo->Profiles->subscribeProfiles($body);
GitHub docs:
## Positional Arguments
# $body | associative array
$klaviyo->Profiles->subscribeProfiles($body);
Klaviyo API docs:
https://developers.klaviyo.com/en/v2022-10-17/reference/subscribe_profiles
Hi - Brandon @ Klaviyo support kindly helped me out with this one so thought I’d share an example of a working $body payload. Obviously LIST_ID needs replacing with your list ID.
Thanks
$body = array(
"data" => array(
"type" => "profile-subscription-bulk-create-job",
"attributes" => array(
"subscriptions" => array(
array(
"email" => "user@example.com",
)
),
"list_id" => "LIST_ID"
)
)
);
$klaviyo->Profiles->subscribeProfiles($body);