getbrevo / brevo-php

A fully-featured PHP API client to interact with Brevo.
https://developers.brevo.com/
MIT License
49 stars 22 forks source link

Updated Model to accept unlinkListIds #18

Closed OrangePixelLtd closed 7 months ago

OrangePixelLtd commented 10 months ago

For removal of contact from List(s) during updateContact() API call.

What type of PR is this? (select all that apply)

🐛 Bug Fix

As shown in the API documentation https://developers.brevo.com/reference/updatecontact the method accepts 'unlinkListIds' (an array of int64s).

I was working on a project where this was needed and found a bug where it wasn't being accepted. I updated the Model and it all seems to be working now.

Example:

$contact = $api->getContactInfo($email);

$contact['unlinkListIds'] = [$listId];

try {
  $api->updateContact($contact['email'], $contact);
} catch (Exception $e) {
  Log::error('Exception when calling ContactsApi->updateContact: ' . $e->getMessage() . PHP_EOL);
}
sonarcloud[bot] commented 10 months ago

Quality Gate Failed Quality Gate failed

Failed conditions

20.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

preetishishodia7 commented 7 months ago

Hi @OrangePixelLtd

The unlinkListIds method is supported in this route (https://developers.brevo.com/reference/updatecontact).

Please refer to the sample example below to see how you can utilize it: -

<?php
require_once(__DIR__ . '/vendor/autoload.php');

$config = Brevo\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR_API_KEY');

$apiInstance = new Brevo\Client\Api\ContactsApi(
    new GuzzleHttp\Client(),
    $config
);
$identifier = 'example2@example2.com';
$updateContact = new \Brevo\Client\Model\UpdateContact();

$updateContact['attributes'] = array('EMAIL'=>'example@domain.com', 'FIRSTNAME'=>'John Doe');
$updateContact['unlinkListIds'] = array(9);

try {
    $apiInstance->updateContact($identifier, $updateContact);
} catch (Exception $e) {
    echo 'Exception when calling ContactsApi->updateContact: ', $e->getMessage(), PHP_EOL;
}
?>

If you encounter any further issues, please feel free to inform me, and I will investigate further to assist you.

Thank you for your cooperation and understanding!