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

Not sending transational email: HttpError: HTTP request failed

Open brunodmn opened this issue 1 year ago • 4 comments

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?

brunodmn avatar Apr 08 '24 14:04 brunodmn

Facing same problem 😢

saurabh-antcreatives avatar May 18 '24 14:05 saurabh-antcreatives

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

brunodmn avatar May 20 '24 12:05 brunodmn

hey @brunodmn

this code is also not working, giving this error image

saurabh-antcreatives avatar May 20 '24 13:05 saurabh-antcreatives

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.

brunodmn avatar May 21 '24 12:05 brunodmn