getbrevo / brevo-php

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

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

Open johnkhansrc opened 4 months ago

johnkhansrc commented 4 months ago

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 = 'example@example.com';
            $updateContact = new UpdateContact();
            $updateContact['attributes'] = ['EMAIL'=>'example2@example2.com', '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?

Farrusc0 commented 4 months ago

Hello! I'm not sure if this will help, but I use the following approach, and it works like a charm.

try {

            $identifier = 'example@example.com'; // string | Email (urlencoded) OR ID of the contact

            $updateContact = new \Brevo\Client\Model\UpdateContact();

            $updateContact->setAttributes( ['EMAIL'=>'example2@example2.com', 'FIRSTNAME'=>'John Doe']);

            $this->instance->updateContact($identifier, $updateContact);

        } catch (Exception $e) {

            $this->Log->content(["Exception in ", __METHOD__, $e->getMessage(), PHP_EOL])->saveToFile()->andExit();

        }