You are here

public function SendinblueApiV3::createUpdateUser in SendinBlue 7.2

Create and update user.

Parameters

string $email: An email address of user.

array $attributes: An attributes to update.

array $blacklisted: An array of black user.

string $listid: A new listid.

string $listid_unlink: A link unlink.

Overrides SendInBlueApiInterface::createUpdateUser

File

includes/Api/SendinblueApiV3.php, line 261

Class

SendinblueApiV3
Sendinblue REST client.

Code

public function createUpdateUser($email, array $attributes = [], array $blacklisted = [], $listid = '', $listid_unlink = '') {
  $isContactExist = $this
    ->getUser($email) !== NULL;
  if ($isContactExist) {
    if ($this
      ->getUser($attributes['SMS'])) {
      unset($attributes['SMS']);
    }
    $updateContact = new UpdateContact([
      'attributes' => (object) $attributes,
      'emailBlacklisted' => (bool) $blacklisted,
      'listIds' => [
        (int) $listid[0],
      ],
      'unlinkListIds' => $listid_unlink,
    ]);
    $this->sibContactsApi
      ->updateContact($email, $updateContact);
  }
  else {
    $updateContact = new CreateContact([
      'email' => $email,
      'attributes' => (object) $attributes,
      'emailBlacklisted' => (bool) $blacklisted,
      'listIds' => [
        (int) $listid[0],
      ],
      'unlinkListIds' => $listid_unlink,
    ]);
    $this->sibContactsApi
      ->createContact($updateContact);
  }
}