writing to a list
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);
  Â
  Â
?>
