How do you even authenticate the requests?
Seriously, whoever is responsible for this docs should be forced to use it themselves.
The examples in README throw TS errors. I'm getting 401. This is unusable.. @shubhamUpadhyayInBlue @ceisele-r @aayush-sib
Same here for me ! The issue was that when i was using process.env and nodenv top retrieve the apik_key it return undefined and then getbrevo dont have the authorization necessary... Not the first time something like this happens for me, sometimes some packages got difficulties to access env variables i ont know why...
DONT WORK const apiInstance = new brevo.TransactionalEmailsApi(); let apiKey = apiInstance.authentications['apiKey']; apiKey.apiKey = process.env.BREVO_API_KEY;
WORKS const apiInstance = new brevo.TransactionalEmailsApi(); let apiKey = apiInstance.authentications['apiKey']; apiKey.apiKey = 'xkeysib-xxxx';
Nothing is working man. What actually their developer are doing? Typescript is a widely used language and no proper support for it. This is really very bad for the Brevo's brand image among the developers, who are building on it.
Here's my code ->
import * as Brevo from "@getbrevo/brevo";
const initializeBrevoClient = (): Brevo.TransactionalEmailsApi => {
const apiInstance = new Brevo.TransactionalEmailsApi();
const apiKey = apiInstance.authentications["apiKey"];
if (!process.env.BREVO_API_KEY) {
throw new Error("BREVO_API_KEY environment variable is not set");
}
apiKey.apiKey = process.env.BREVO_API_KEY as string;
// apiInstance.timeout = 10000;
return apiInstance;
};
const brevoClient = initializeBrevoClient();
And the type error is ->
Property 'authentications' is protected and only accessible within class 'TransactionalEmailsApi' and its subclasses.ts
Please fix ASAP!
no fix yet? @sujayxaradhya did you find a temporary good solution ?
Yes, you're right, the documentation is sh**.
But if you are developers, you should have found the solution in few seconds.
Here how to set the authentication ⬇
const apiInstance = new Brevo.TransactionalEmailsApi();
apiInstance.setApiKey(Brevo.TransactionalEmailsApiApiKeys.apiKey, YOUR_KEY);