Problem to integrate send in blue api with my nestjs application

1.1k Views Asked by At

Describe the bug

Problem to integrate sendinblue api with my nestjs app. I need to integrate with a custom authentication and in the axios's api says that i need to use a header for custom authentication, in postman i'm using api key for authorization and it works,but it throws a error 401.

To Reproduce

    async SendEmailToSendInBlue(email: {
        sender: { email: string };
        to: [{ email: string }];
        subject: string;
        textContent: string;
    }): Promise<any> {
        const url = `${SENDINBLUE_URL}`;
        return this.httpService
            .post<any>(url, email, {
                headers: {
                    Key: 'api-key',
                    Value: process.env.SENDBLUE_API_KEY,
                    'Add To': 'Header',
                },
                /* auth: {
                    username: 'apikey',
                    password: process.env.SENDBLUE_API_KEY,
                }, */
            })
            .toPromise()
            .then((data) => {
                return data;
            });
    }

Expected behavior Send an transational email to client.

Environment -Axios Version 0.19.2 -Node.js Version 14+ -Docker Version 19.03.12-ce -Additional Library Versions

Additional context/Screenshots enter image description here enter image description here

1

There are 1 best solutions below

0
On

The Sendinblue documentation itself explains how to do this.

The link below explained how to pass api-key in header:

https://developers.sendinblue.com/docs/send-a-transactional-email#send-a-transactional-email-using-a-basic-html-content

headers: {
 'api-key': 'YOUR_API_KEY'
}