SendInBlue - sib-api-v3-sdk sendTransacEmail() returns 403 Forbidden

1.3k Views Asked by At

I'm trying to send a transactional email with my new SendInBlue account and I keep receiving an error that simply says "Forbidden". I followed the example on SendInBlue's Nodejs docs to write this code:

const SibApiV3Sdk = require('sib-api-v3-sdk');

const defaultClient = SibApiV3Sdk.ApiClient.instance;

// Configure API key authorization: api-key
const apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'xxx';
// Uncomment the following line to set a prefix for the API key, e.g. 'Token' (defaults to null)
//apiKey.apiKeyPrefix = 'Token'

// Configure API key authorization: partner-key
//const partnerKey = defaultClient.authentications['partner-key'];
//partnerKey.apiKey = 'YOUR API KEY';
// Uncomment the following line to set a prefix for the API key, e.g. 'Token' (defaults to null)
//partnerKey.apiKeyPrefix['partner-key'] = 'Token'

const apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();

const sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail(); // SendSmtpEmail | Values to send a transactional email

const sendEmail = async (to, subject, htmlBody, textBody) => {

    sendSmtpEmail.to = [{ email: to }];
    sendSmtpEmail.sender = { email: '*', name: '*' };
    sendSmtpEmail.htmlContent = `*`;
    sendSmtpEmail.textContent = `*`;
    sendSmtpEmail.subject = `*`;
    sendSmtpEmail.replyTo = { email: '*' };

    const result = await apiInstance.sendTransacEmail(sendSmtpEmail);
    console.log(result);
    return result;
};


export { sendEmail };

The apiInstance.sendTransacEmail(sendSmtpEmail) line throws a 403 error that simply says "Forbidden". How do I fix this?

2

There are 2 best solutions below

0
On BEST ANSWER

Your transactional account is not activated. Create a ticket on SendinBlue support. They will activate it and your issue will be resolved.

0
On

I had the same error. Solved by upgrading to the new brevo sdk.

  • Only the configuration change, so it's easy to do.

For PHP:

 $config = Brevo\Client\Configuration::getDefaultConfiguration()->setApiKey(...);
        //And of course update the sources:
use Brevo;
use Brevo\Client\Api\TransactionalEmailsApi;
use Brevo\Client\Model\SendSmtpEmail;

Hope this help. Ps: SendInblue sdk is now deprecated.