Coder Social home page Coder Social logo

brevo-php's People

Contributors

nik-sib avatar preetishishodia7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

brevo-php's Issues

Php 8 GuzzleHttp\Psr7\Stream::getContents stream is not getting the response content

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

[Feature Request] API support for attribute conditions/filters

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.

Event 'skipped' is not declared in API

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!

getContacts() -> error code: 524

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;
}

Base64 Encoded PDF Fails

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.

Sanitize value before sending the request

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 :

  • empty "name" for sender, etc. (the field shouldn't be empty if present),
  • empty "attachments" array

Would be great to have the Brevo package that do that bit extra validation/sanitation.
Thank you !

Parse Error in lib/model/Pipelines.php

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?

Cannot assign offset 'attributes' to Brevo\Client\Model\UpdateContact.

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?

Allow Guzzle v6?

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?

Global variable conflict: Rename 'version' to 'version-brevo'

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.

TrackEvent

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

Fatal error with Guzzle ClientException

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

Undefined method smtpLogMessageIdDelete ; breaking change in a patch version!

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.

GetSegments problem

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 !

Importing attributes failed on \Brevo\Client\Model\CreateContact()

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.