Created
September 12, 2022 13:29
-
-
Save alrnz/277f78ac1edae213fd15ec932da0829f to your computer and use it in GitHub Desktop.
Create User at sendinblue.com via sendinblue/APIv3-php-library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function create_user($sendinblueApiKey = '', $mail = '', $sendinblueLists = '1,2,3'){ | |
$config = \SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', $sendinblueApiKey); | |
$apiInstance = new \SendinBlue\Client\Api\ContactsApi( | |
new \GuzzleHttp\Client(), | |
$config | |
); | |
$listIds = []; | |
foreach (explode(',', $sendinblueLists) as $listId){ | |
$listIds[] = (int)trim($listId); | |
} | |
$createContact = new \SendinBlue\Client\Model\CreateContact([ | |
'email' => $mail, | |
'updateEnabled' => true, | |
'attributes' => | |
[ | |
'VORNAME' => 'name', /* Attribute name in sendinblue */ | |
'NACHNAME' => 'name', /* Attribute name in sendinblue */ | |
], | |
'listIds' => $listIds | |
]); | |
$result = $apiInstance->createContact($createContact); | |
if(\is_a($result, \SendinBlue\Client\Model\CreateContact::class )){ | |
$sendinblue_id = $result->getId(); | |
} else { | |
$user_info = $apiInstance->getContactInfo($lead->getEmail()); | |
$sendinblue_id = $user_info->getId(); | |
} | |
return $sendinblue_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment