question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mailjet API_KEY is required even with API KEY

See original GitHub issue

I’ve got the error Mailjet API_KEY is required my Code:

const express = require('express');
const bodyParser = require('body-parser');
const mailjet = require ('node-mailjet')
    .connect(process.env.USER, process.env.PASSWORD)
const app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.raw());

app.post('/sendMail',async (req, res) => {
    mailjet
    .post("send", {'version': 'v3.1'})
    .request({
        "Messages":[{
            "From": {
                "Email": "leonllrcraft@gmail.com",
                "Name": "thesportclinic server"
            },
            "To": [{
                "Email": req.body.to,
                "Name": "Alexis"
            }],
            "Subject": "nouveau demande de rendez-vous",
            "TextPart": "",
            "HTMLPart": `${req.body.body}`
        }]
    }).then((result) => {
    console.log(result.body)
    res.status(200);
  })
  .catch((err) => {
    console.log(err.statusCode)
  })

    
})

app.listen(process.env.PORT)
console.clear()//just for Repl.it don't log express server

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

2reactions
scroll17commented, Apr 13, 2022

@leonllrmc @simonlayfield I’m tested this problem and the error is not reproduced.

The error you are getting is generated in file mailjet-client.js on line 191:

...
  function basicConnectStrategy(apiKey, apiSecret, options) {
    if (!apiKey) {
      throw new Error('Mailjet API_KEY is required');
    }
    if (!apiSecret) {
      throw new Error('Mailjet API_SECRET is required');
    }
...    

The code check value apiKey for not empty value (0, "", null, undefined, NaN in Boolean have value false) so you need to check that values process.env.USER and process.env.PASSWORD aren’t empty.

Please, check you passed values and if error repeat with not empty values provide more information: mailjet-apiv3-nodejs package version, NodeJS version, OS, environment

0reactions
scroll17commented, Apr 26, 2022

This issue will be closed

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Key Configuration - Mailjet for Developers
/apikey. Create a sub-account with a new Public and Secret API Key. API Keys are used as credentials to access the API and...
Read more >
What are the API Keys? - Mailjet Help Center
An API Key and Secret Key are secret tokens used by Mailjet to authenticate you with our servers. Your Secret Key is displayed...
Read more >
Send API V3.1 - Mailjet for Developers
Mailjet is still supporting Send API V3. ... The mandatory properties for any message element are: ... View : API Key Statistical campaign/message...
Read more >
Email API Authentication - Mailjet for Developers
It requires you to provide a username and a password for each API request. The username is your API Key and the password...
Read more >
Finding and managing your API credentials | Customer.io Docs
You can find your API keys by navigating to Account Settings > API Credentials. In this settings area, you can add new API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found