brevo-node icon indicating copy to clipboard operation
brevo-node copied to clipboard

After update to 2.x, ApiClient.instance is not defined anymore

Open nicokaiser opened this issue 1 year ago • 1 comments

Previously, a default API client could be used to only once set authentication data when using multiple endpoints:

const Brevo = require('@getbrevo/brevo');

const defaultClient = Brevo.ApiClient.instance;
defaultClient.authentications['api-key'].apiKey = apiKey;
const instance = new Brevo.TransactionalEmailsApi();
...

However, Brevo.ApiClient.instance is not defined anymore since the update to v2.x.

There is no documentation about the 1.x -> 2.x transition, which – I'm sorry to say – is absolutely horrible and frustrating developer experience.

nicokaiser avatar Apr 23 '24 13:04 nicokaiser

Furthermore, it now does not seem to be necessary to wrap recipient addresses (!) in object instances anymore. So at least one can get rid of this ridiculous construction:

  const sendSmtpEmail = new Brevo.SendSmtpEmail();
  sendSmtpEmail.templateId = templateId;
- const to = new Brevo.SendSmtpEmailTo();
- to.email = email;
- sendSmtpEmail.to = [to];
+ sendSemtpEmail.to = [{ email }];

However I cannot seem to find any documentation about this transformation.

nicokaiser avatar Apr 23 '24 14:04 nicokaiser

Hi @nicokaiser Sorry, the documentation was not updated since long, though it should have been. I understand your pain. Here I have updated the Readme.md with some examples, hope it helps: https://github.com/getbrevo/brevo-node?tab=readme-ov-file#we-have-two-options

shubhamUpadhyayInBlue avatar Jun 11 '24 14:06 shubhamUpadhyayInBlue

Thanks for the update. I since replaced the SDK with a very simple HTTP call to the REST API. Since we only need one specific endpoint this vastly reduces the complexity and makes the project independent from SDK changes.

nicokaiser avatar Jun 18 '24 10:06 nicokaiser