Hi
I have run into an issue, when trying to update the profile thru the api PATCH (https://developers.klaviyo.com/en/reference/update_profile)
I am trying to add some custom attributes on the profile, the data i send is build like this
$checkKlaviyo = json_decode($system->Klaviyo($env['klaviyo_api'], 'GET', $env['klaviyo_url'] . 'profiles/?filter=equals(email,"'.urlencode($orderData['recipient-email']).'")', false, false));if ( $checkKlaviyo->code == 200 && $checkKlaviyo->status == 'success' ) { $profileID = $checkKlaviyo->data[0]->id; $packageData = [ 'body' => [ 'data' => [ 'type' => 'profile', 'id' => $profileID, 'attributes' => [ 'properties' => [ 'PackageAmount' => $orderData['amount'], 'Packages' => $orderData['packages'] // an Array ] ] ] ] ]; $system->Klaviyo($env['klaviyo_api'], 'PATCH', $env['klaviyo_url'] . 'profiles/'.$profileID.'/', false, json_encode($packageData));}
the function
public function Klaviyo($appId, $method, $url, $data, $profileData){ $curl = curl_init(); switch ($method){ case "POST": curl_setopt($curl, CURLOPT_POST, 1); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; case "PUT": curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; case "PATCH": curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH'); if ($profileData) curl_setopt($curl, CURLOPT_POSTFIELDS, $profileData); break; default: if ($data) $url = sprintf("%s?%s", $url, http_build_query($data)); } // OPTIONS: curl_setopt($curl, CURLOPT_URL, $url); if ( $method == 'PATCH' ) { curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Authorization: Klaviyo-API-Key ' . $appId, 'accept: application/json', 'revision: 2023-12-15' )); } else { curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Authorization: Klaviyo-API-Key ' . $appId, 'accept: application/json', 'revision: 2023-12-15' )); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); // EXECUTE: $result = curl_exec($curl); curl_close($curl); if(!$result) { $content = []; $content['code'] = '000'; $content['status'] = 'error'; $content['message'] = 'Connection Failure'; $content['data'] = ''; } else { $result = json_decode($result, true); if ( !empty($result['data']) ) { $content = []; $content['code'] = '200'; $content['status'] = 'success'; $content['message'] = 'Connection Accepted'; $content['data'] = $result['data']; } else { $content = []; $content['code'] = '404'; $content['status'] = 'error'; $content['message'] = 'Could not fetch data'; $content['data'] = ''; } } return json_encode($content);}
but i recieve the following error
string(195) "{"errors":[{"id":"ac432953-de83-4bfa-95cb-2b0d1cc51aa4","status":400,"code":"invalid","title":"Invalid input.","detail":"An object with data is required","source":{"pointer":"/data"},"meta":{}}]}"
anyone who can point me on how to get my custom data over in Klaviyo? must be the dataset i create at
$packageData = [ 'body' => [ 'data' => [ 'type' => 'profile', 'id' => $profileID, 'attributes' => [ 'properties' => [ 'PackageAmount' => $orderData['amount'], 'Packages' => $orderData['packages'] // an Array ] ] ] ] ];
Due to the API can find the ID to update