-
Notifications
You must be signed in to change notification settings - Fork 34
Description
Bug Description
In version 2.0.7, the updateContact method is broken due to a parameter mix-up in the updateContactRequest method. The method is passing the UpdateContact object instead of the contact identifier to ObjectSerializer::toPathValue(), causing the
entire object to be serialized and URL-encoded into the API endpoint path.
Expected Behavior
The API should call:
PUT https://api.brevo.com/v3/contacts/[email protected]
Actual Behavior
The API is calling:
PUT https://api.brevo.com/v3/contacts/%7B%0A%20%20%20%20%22attributes%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22PRODUCT%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Ultiself%22%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%2
0%22listIds%22%3A%20%5B%0A%20%20%20%20%20%20%20%2010%0A%20%20%20%20%5D%0A%7D
When URL-decoded, this becomes the entire UpdateContact object JSON instead of the email address.
Root Cause
File: lib/Api/ContactsApi.phpLine: 8189
Commit: 5f2fa9c#diff-5d012404021893b1b156cc7f6683906f3fc6a4bb030a314806af5cb589678c0a
Error Messages
This results in 400 Bad Request errors like:
[400] Client error: `PUT https://api.brevo.com/v3/contacts/%7B...` resulted in a `400 Bad Request` response:
{"message":"Unexpected token in JSON at position 0"}
Reproduction
use Brevo\Client\Api\ContactsApi;
use Brevo\Client\Configuration;
use Brevo\Client\Model\UpdateContact;
$config = Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR_API_KEY');
$contactsApi = new ContactsApi(new \GuzzleHttp\Client(), $config);
$updateContact = new UpdateContact();
$updateContact->setAttributes((object)['TEST' => 'value']);
// This will fail with URL encoding error
$contactsApi->updateContact('[email protected]', $updateContact);
Affected Versions
- v2.0.7 (broken)
- v2.0.6 and earlier (working)
Workaround
Downgrade to v2.0.6:
composer require getbrevo/brevo-php:2.0.6