Skip to main content
Solved

Adding a profile to a list

  • July 13, 2024
  • 1 reply
  • 40 views

Forum|alt.badge.img+2

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);
    
    


?>

Best answer by jason-myers

This looks like a duplicate -- answered over here: 

 

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

1 reply

Forum|alt.badge.img+1
  • Klaviyo Employee
  • 10 replies
  • Answer
  • July 13, 2024

This looks like a duplicate -- answered over here: