Skip to content

Instantly share code, notes, and snippets.

@alrnz
Created September 12, 2022 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alrnz/277f78ac1edae213fd15ec932da0829f to your computer and use it in GitHub Desktop.
Save alrnz/277f78ac1edae213fd15ec932da0829f to your computer and use it in GitHub Desktop.
Create User at sendinblue.com via sendinblue/APIv3-php-library
<?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