I need to integrate the klaviyo API with an existing legacy php system such that when a customer successfully signs up for a service they are automatically added to a list in Klaviyo. I cannot include a signup form as would be normal because all of this is done server-side in the background.
I made a simple program for testing purposes using the PHP SDK but I am getting a response I do not understand. I am hoping someone can tell me where I am going wrong on this.
The program code is fairly simple:
<?php
require_once './includes/klaviyo_php_sdk_2.2.5.0/vendor/autoload.php';
use Klaviyo\Klaviyo as Klaviyo;
$addProfile = array(
array(
'email' => "dan@divinusinc.com",
'first_name' => "Test",
'last_name' => "Man",
'phone_number' => "(214) 555-1212",
'address' => "23 Skidoo Street",
'address_2' => "Dark Side of the Moon",
'city' => "Dallas",
'state' => "TX",
'country' => "USA",
'zip_code' => "75216",
'plan_type' => "Some-Random-Plan",
'start_date' => "03-21-2021",
'renewal_date' => "03-21-2022"
)
);
$client = new Klaviyo( 'MY_PUBLIC_KEY GOES HERE', 'my_private_key_goes_here' );
#Add members to list without affecting consent status
$client->lists->addMembersToList( 'My_List_ID_Goes_Here', $addProfile );
?>
but I am getting the following errors I do not understand;
[root@ip-172-31-3-105 Enroll]# php ./xCodeBlock.php
PHP Notice: Undefined index: $email in /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/KlaviyoAPI.php on line 454
Notice: Undefined index: $email in /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/KlaviyoAPI.php on line 454
PHP Fatal error: Uncaught Klaviyo\Exception\KlaviyoException: is not an instance of ProfileModel, You must identify the person by their email, using a $email key, or a unique identifier, using a $id. in /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/KlaviyoAPI.php:453
Stack trace:
#0 /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/Lists.php(225): Klaviyo\KlaviyoAPI->checkProfile(Array)
#1 /sites/dev/Enroll/xCodeBlock.php(27): Klaviyo\Lists->addMembersToList('UJLqnA', Array)
#2 {main}
thrown in /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/KlaviyoAPI.php on line 453
Fatal error: Uncaught Klaviyo\Exception\KlaviyoException: is not an instance of ProfileModel, You must identify the person by their email, using a $email key, or a unique identifier, using a $id. in /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/KlaviyoAPI.php:453
Stack trace:
#0 /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/Lists.php(225): Klaviyo\KlaviyoAPI->checkProfile(Array)
#1 /sites/dev/Enroll/xCodeBlock.php(27): Klaviyo\Lists->addMembersToList('UJLqnA', Array)
#2 {main}
thrown in /sites/dev/Enroll/includes/klaviyo_php_sdk_2.2.5.0/vendor/klaviyo/php-sdk/src/KlaviyoAPI.php on line 453
[root@ip-172-31-3-105 Enroll]#
I am using root level access and it is apparent the program is finding the API source, but I just do not know where/why this is failing.
Any help would be appreciated.
Dan Davis