getbrevo / brevo-php Goto Github PK
View Code? Open in Web Editor NEWA fully-featured PHP API client to interact with Brevo.
Home Page: https://developers.brevo.com/
License: MIT License
A fully-featured PHP API client to interact with Brevo.
Home Page: https://developers.brevo.com/
License: MIT License
As stated in the title running the library with php 8.1 trigger an unexpected behavior with \GuzzleHttp\Psr7\Stream::getContents
.
For instance in ContactApi::requestContactExportWithHttpInfo
this code:
if ($returnType === '\SplFileObject') {
$content = $responseBody; //stream goes to serializer
} else {
**$content = $responseBody->getContents();**
if ($returnType !== 'string') {
$content = json_decode($content);
}
}
return a $content = ""
.
I didn't go into details, but I found that might be a stream issue.
If I cast $responseBody into a string it works as expected since $content turn to be something like {"processId":90}
thank to magic method GuzzleHttp\Psr7\Stream::__toString
.
$content = (string) $responseBody;
Maybe it's a guzzle http issue, not a brevo php sdk issue.
Thanks in advance
Hi,
In the API docs
https://developers.brevo.com/reference/getdomainconfiguration
there is a return for the dmarc_record as well as the brevo_code and the dkim_record. But the SDK only returns the dkim_record and the brevo_code.
vendor/getbrevo/brevo-php/lib/Model/CreateDomainModelDnsRecords.php
For my project I need to create daily automated campaigns. All recipients are on a single Contact List and have set preferred delivery days/language in attributes. During creation I'm required to set additional conditions/filters to get my desired situation.
In app.brevo.com
While managing a Email Campaign, in the Recipients section under 'Advanced options', the additional conditions can be added. A few server-requests to '...recipient-count-new' suggests the next structure (extracted irrelevant parts):
(extracted)
"filter_fe_query":{
"or":[
{
"and":[
{
"contact":{
"field":"LANGUAGE",
"dataType":"text",
"operator":"equals",
"value":[
"(language code)"
]
},
"isValidated":true
},
(another 2 conditions having 'contact' object)
]
}
]
}
(extracted)
By API (client) / docs
As seen in the docs, only listIds
, exclusionListIds
and segmentIds
are supported in the CreateEmailCampaignRecipients model. Above structure is ignored, even after renaming snake_case to pascalCase and assigning the recipients by not using the model - as part of 'hidden functionality guessing'.
Requested
First, API-server support to handle the json-snippet - as working in the app.brevo.com environment - or just publish the right instructions to achieve it.
Seconds, API-client support for adding conditions.
Note
Verify all offered operators are functional(!). For me it doesn't make sense to just have the equals
.
Hi,
I have found using this PHP library (version 2.0) the following error, callling the getSmsEvents method that calls the API endpoint /transactionalSMS/statistics/events
Invalid value for 'event', must be one of 'bounces', 'hardBounces', 'softBounces', 'delivered', 'sent', 'accepted', 'unsubscription', 'replies', 'blocked', 'rejected'
I have managed to find the event that is not on that list of possible event types that the library expects. It is 'skipped'. This is the example that i have.
{
"phoneNumber": "11169581298",
"date": "2024-06-19T12:34:52.000-03:00",
"messageId": "22136031729812",
"event": "skipped"
}
Is this a bug or something that wasn't updated yet?
Thanks!
I'm using the RequestContactImport class but the disableNotification parameter is not yet implemented.
Could it be added ?
in the documentation its stating an array. The API is requiring an int.
I have a straightforward piece of code designed to retrieve contacts from a segment. It functions as intended when the segment contains contacts. However, if the segment is empty, I encounter an error like this [524] Server error: GET https://api.brevo.com/v3/contacts?limit=10&offset=0&segmentId=1
resulted in a 524
response: error code: 524
try {
$result = $this->instance->getContacts($limit , $offset, null, null, null, $segmentId);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ContactsApi->getContacts: ', $e->getMessage(), PHP_EOL;
}
The event API explained here : https://developers.brevo.com/reference/createevent is missing from this SDK.
Could you please add this API ? It could be very convenient.
When using the SendSmtpEmailAttachment.php to send a PDF, sometimes the preg_match on line 266 fails without reason. Please remove this preg check or fix it. I am using a base_64 encoded PDF and it works fine to send it if I comment out the preg_match.
Hello !
This is not a bug, but a feature request.
Some times, when sending a request (like sending a transactional email), the request is rejected by the server because some fields are present but empty. I think it would be very beneficial in such case to have a sanitation pass to null some optional elements.
Here are two causes of rejection I faced when sending a transactional :
Would be great to have the Brevo package that do that bit extra validation/sanitation.
Thank you !
When adding the library to our code, static analysis reported a parse error in this lib/model/Pipelines.php
.
I pasted it into https://3v4l.org/d2FJ0 and it does indeed reference parent::
in line 191, but it never extends anything. I'm not sure whether the class is a leftover or a WIP. Could someone clarify?
When I update the attributes of a Brevo contact as described in the documentation (https://developers.brevo.com/reference/updatecontact) PHPStan reports the following violation :
Cannot assign offset 'attributes' to Brevo\Client\Model\UpdateContact.
try {
$identifier = '[email protected]';
$updateContact = new UpdateContact();
$updateContact['attributes'] = ['EMAIL'=>'[email protected]', 'FIRSTNAME'=>'John Doe'];
$this->contactEndpoint->updateContact($identifier, $updateContact);
} catch (\Exception $e) {
$this->brevoLogger->error('Error while updating contact on SendinBlue', ['exception' => $e]);
}
What is the correct way to modify a contact's attributes?
Hi,
The package requires a minimum of PHP 5.x, but Guzzle 7 is required which has a minimum of PHP 7.2:
Dropped PHP 5 support—the minimum PHP version is now 7.2
I'm on a project where Guzzle 6 is still used, which fits better with the PHP version constraint in this package. I don't think there's any major changes, especially in the way the package is used here - so maybe this package can be opened up for v6 as well?
As reported in sendinblue php repo , we can't batch update contacts as if an error occurs on 1 contact in the batch, it returns an API error with no update at all.
The API is unusable.
Any plan to fix this soon as it has been reported 5 month ago ?
Hello,
I've encountered an issue with the global variable named "version" in the Brevo PHP package. This global variable is causing conflicts in my project.
To resolve this, I propose changing the variable name to something more specific to the Brevo package. This would help avoid potential conflicts with other packages or user-defined variables.
Here's a proposed patch to address this issue:
--- a/lib/Configuration.php
+++ b/lib/Configuration.php
@@ -38,7 +38,7 @@
* @link https://github.com/swagger-api/swagger-codegen
*/
-$GLOBALS['version'] = '2.0.0';
+$GLOBALS['version-brevo'] = '2.0.0';
class Configuration
{
@@ -120,7 +120,7 @@
public function __construct()
{
$this->tempFolderPath = sys_get_temp_dir();
- $this->userAgent = 'brevo_clientAPI/v' . $GLOBALS['version'] . '/php';
+ $this->userAgent = 'brevo_clientAPI/v' . $GLOBALS['version-brevo'] . '/php';
}
This change makes the variable name more specific to the Brevo package, reducing the likelihood of conflicts with other code.
Please review this pull request and let me know if you need any further information or if you'd like me to make any adjustments to this proposed change.
Thank you for your consideration.
CreateUpdateProduct In EcommerceApi Creating products and can view in https://developers.brevo.com/reference/getproducts but not showing in https://app.brevo.com/ecommerce/products
I successfully instantiated a Brevo\Client\Api\DealsApi
object. Calling crmPipelineDetailsAllGet()
on it, as suggessted in an example in DealsApi.md
, triggers the following error:
Cannot use "parent" when current class scope has no parent
in brevo-php/lib/Model/Pipelines.php
on line 190
May be related: #8
Example
https://developers.brevo.com/reference/getcontactinfo-1
$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR API KEY');
$apiInstance = new SendinBlue\Client\Api\ContactsApi...
"SendinBlue"?
function triggerTrackEvent($email, $event, $maKey) {
$client = new \GuzzleHttp\Client();
$data = [
'email' => $email,
'event' => $event,
];
$headers = [
'accept' => 'application/json',
'content-type' => 'application/json',
'ma-key' => $maKey,
];
$response = $client->request('POST', 'https://in-automate.sendinblue.com/api/v2/trackEvent', [
'body' => json_encode($data),
'headers' => $headers,
]);
echo $response->getBody();
}
Currently Im writting trackevent for my brevo automation.
I have a loop calling triggerTrackEvent
passing each client for brevo automation, but only first POST request can trigger brevo automation, the 2nd, 3rd... could not trigger
do you know any idea why? sorry for my english
Hello there, just a simple question: is createDoiContact
ContactsApi method supposed to return response as createContact
does, or is it right as it is?
Hi.
I've just installed the Brevo sdk.
All work great, but when the API v3 returns a bad request, this triggers a fatal error by Guzzle
here is my log example
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://api.brevo.com/v3/contacts` resulted in a `400 Bad Request` response:
{"code":"duplicate_parameter","message":"Unable to update contact, SMS or WHATSAPP are already associated with another C (truncated...)
and here is my code
$response = $this->client->request('POST', 'https://api.brevo.com/v3/contacts', [
'body' => json_encode($contact),
'headers' => [
'accept' => 'application/json',
'api-key' => BREVO_API_KEY,
'content-type' => 'application/json',
],
]);
try {
$statusCode = $response->getStatusCode();
$responseBody = $response->getBody();
$responseArray = json_decode($responseBody,true);
if( $statusCode == 201){
return array('success' => true, 'message' => $responseArray);
} else {
return array('success' => false, 'message' => $responseArray['message']);
}
} catch (ClientException $e) {
write_log('client exception');
write_log($e->getMessage());
}catch (RequestException $e) {
write_log('request exception');
write_log($e->getMessage());
} catch (Exception $e) {
write_log($e->getMessage());
}
Does anyone can help me to catch this error ?
thank you
It would be great, if there are some additional filters at Brevo\Client\Api\ContactsApi->getContacts() [endpoint GET api.brevo.com/v3/contacts
]. For instance , if it is able to filter with brevo contact "attributes"
, then it avoids additional processing based on "attributes"
, once all the contacts are fetched.
The composer.lock seems outdated and does not correspond to composer json
For ex :
"guzzlehttp/guzzle": "^7.4.0" VS "version": "6.3.3" in lock
https://github.com/getbrevo/brevo-php/blob/main/composer.json#L25C9-L25C38
https://github.com/getbrevo/brevo-php/blob/main/composer.lock#L11
This is minor but create issues with multiple security tools such as snyk
The filename is written with a lowercase a and the classname is written with a capital A.
As far as I know this is not PSR-4 compliant.
Edit: created pull request: #4
Hello,
Today after updating my Composer dependencies, my tests reported that the Brevo API client was failing:
Call to undefined method Brevo\Client\Api\TransactionalEmailsApi::smtpLogMessageIdDelete()
After inspecting this repository, I understood that it had been renamed to smtpLogIdentifierDelete
in version 1.0.3
.
API reference in v1.0.2
: https://github.com/getbrevo/brevo-php/blob/v1.0.2/docs/Api/TransactionalEmailsApi.md#smtpLogMessageIdDelete.
API reference in v1.0.3
: https://github.com/getbrevo/brevo-php/blob/v1.0.3/docs/Api/TransactionalEmailsApi.md#smtpLogIdentifierDelete.
I understand that this change was made automatically by Swagger, but this is a (very) bad practice to ship breaking changes in a patch-level version.
I created this issue too to help other developers understand and find a fix more quickly.
Hello,
I want to geSegments via ContactsAPI, but when i call this function, i get :
{ 'segments': {}, // empty array 'count': 33 // ok and it is really the total number of segments }
When i pass without the function of lib, i get the segments with parameters.
Can you resolve it ? Thank you !
When I put attributes on CreateContact instance they're skipped and not imported.
Following my partial code:
$attribs = new \stdClass();
$attribs->FNAME = "Roger";
$attribs->LNAME = "White";
$createContact = new \Brevo\Client\Model\CreateContact();
$createContact->setEmail('[email protected]');
$createContact->setListIds([2]);
$createContact->setAttributes($attribs);
$createContact->setUpdateEnabled (true);
try {
$result = $apiInstance->createContact($createContact);
print_r($result);
} catch (Exception $e) {
print_r($e);
echo 'Exception when calling ContactsApi->createContact: ', $e->getMessage(), PHP_EOL;
}
the contact creation was successfully but without attributes. I only see the email in Brevo dashboard.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.