Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not sending transational email: HttpError: HTTP request failed #21

Open
brunodmn opened this issue Apr 8, 2024 · 4 comments
Open

Not sending transational email: HttpError: HTTP request failed #21

brunodmn opened this issue Apr 8, 2024 · 4 comments

Comments

@brunodmn
Copy link

brunodmn commented Apr 8, 2024

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?

@saurabh-antcreatives
Copy link

Facing same problem 😢

@brunodmn
Copy link
Author

brunodmn commented May 20, 2024

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

@saurabh-antcreatives
Copy link

saurabh-antcreatives commented May 20, 2024

hey @brunodmn

this code is also not working, giving this error
image

@brunodmn
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants