Hi
I am trying to add profiles to a list using the Add Profiles to List api. I get the following error :
Array ( [errors] => Array ( [0] => Array ( [id] => fc86f1de-4e38-4922-b52c-4756939fc34f [status] => 401 [code] => not_authenticated [title] => Authentication credentials were not provided. [detail] => Missing or invalid access token. [source] => Array ( [pointer] => /data/ ) ) ) )
Here is the code:
<?php
/* Testing */
$data = array();
/* Add Profile to List - ECOVIB2Ds Master List */
$email_add = "ecovib2d@live.com";
$apiKey="pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$id = "xxxxxxxx";
$first_name = "Adrian";
$last_name = "Tudini";
$data = [
[
"type" => "profile",
"api_key" => $apiKey,
"id" => $id,
"profiles" => array ('0' => array('first_name' => $first_name,'last_name' => $last_name,'email' => $email_add))
]
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://a.klaviyo.com/api/lists/xxxxxx/relationships/profiles/?api_key=".$apiKey,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer $apiKey",
"accept: application/json",
"content-type: application/json",
"revision: 2024-06-15",
),
));
$response = curl_exec($curl);
$response_details = json_decode($response,true);
print_r($response_details);
if ($response === false) {
$error = curl_error($curl);
curl_close($curl);
die('Curl error: ' . $error);
}
curl_close($curl);
?>