Hi
With the help of MaxBuzz, I have written a script (curl) that will display the id, first name, last name and the email address of a profile.
Here is the code:
<?php
$userDetails = array();
/* $email = urlencode($email); */
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://a.klaviyo.com/api/profiles?filter=equals(email,%22$email%22)",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
'Authorization: Klaviyo-API-Key pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'accept: application/json',
'revision: 2024-06-15',
),
));
$response = curl_exec($curl);
if ($response === false) {
$error = curl_error($curl);
curl_close($curl);
die('Curl error: ' . $error);
}
curl_close($curl);
$userDetails = json_decode($response, true);
/* Display the results to the user */
echo "<center>";
echo "<br>";
echo $first_name."s data on Klaviyo ( Email Marketing Platform - www.klaviyo.com )";
echo "<br/>";
echo "<br/>";
echo str_repeat(" ",40)." Id ". str_repeat(' ', 40)."FirstName".str_repeat(' ',7)."LastName".str_repeat(' ',12)."Email Address";
echo "<br>";
echo str_repeat(".",115);
echo "<br/>";
/* Code to extract the data */
$items = count($userDetails);
if($userDetails){
echo str_repeat(" ",15).$userDetails['data'][0]['id'].str_repeat(" ",5);
echo str_repeat(" ",15).$userDetails['data'][0]['attributes']['first_name'].str_repeat(" ",10);
echo str_repeat(" ",3).$userDetails['data'][0]['attributes'] ['last_name'].str_repeat(" ",5);
echo str_repeat(" ",10).$userDetails['data'][0]['attributes']['email'];
echo "<br>";
}
echo str_repeat(".",115);
echo "</center>";
?>