Not sending transational email: HttpError: HTTP request failed
I received last email from my cron job running bellow snipped on April, 2, 2024 (some days ago). Now it is just not working anymore, I have not changed anything on the platform. Error message says nothing useful : "sendLogMail error: HttpError: HTTP request failed".
Bellow a short version of my code:
import { SENDINGBLUE_API_KEY } from "../../../config";
const SibApiV3Sdk = require("@getbrevo/brevo");
const apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();
apiInstance.setApiKey(
SibApiV3Sdk.TransactionalEmailsApiApiKeys.apiKey,
SENDINGBLUE_API_KEY
);
async sendLogMail(subject: string, message: string): Promise<void> {
let sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail();
sendSmtpEmail.templateId = 7;
sendSmtpEmail.params = {
subject: subject,
message: message,
};
sendSmtpEmail.to = [
{ email: "[email protected]", name: "Bruno Andrade" },
];
try {
await this.instance.sendTransacEmail(sendSmtpEmail);
} catch (error) {
functions.logger.warn("sendLogMail error: " + error);
}
}
await sendLogMail("test","test")
I went thru documentation, nothing about it, besides, very confusing documentation, divergent information from one page to another (github sdk readme and api guide, per instance).
As it's looking a bit messy, maybe sdk changed the way it uses underlined http api or something like it.
Anyone using TransactionalEmailsApi with same problem? Could somebody help me?
Facing same problem 😢
Facing same problem 😢
Hi @saurabh-antcreatives, just to let you know. My workaround was to use direct API instead of SDK:
const SENDINGBLUE_API_KEY = "my-api-key";
export class SendinblueDataSource {
private axios: AxiosInstance;
constructor() {
const instance = axios.create({
timeout: 7000,
baseURL: "https://api.brevo.com/v3",
headers: {
accept: "application/json",
"api-key": SENDINGBLUE_API_KEY,
"content-type": "application/json",
},
});
this.axios = instance;
}
async sendLogMail(subject: string, message: string): Promise<void> {
const data = {
templateId: 7,
params: { subject: subject, message: message },
to: [{ email: "[email protected]", name: "Jhon Dee" }],
};
try {
await this.axios.post("/smtp/email", data);
} catch (error) {
functions.logger.warn("sendLogMaila error: " + error);
}
}
}
hey @brunodmn
this code is also not working, giving this error
SENDINGBLUE_API_KEY
You need to replace SENDINGBLUE_API_KEY by your brevo API KEY, if still getting unauthorized after this, replace for a new one.