sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

API key does not start with "SG."

Open donpayne199 opened this issue 10 months ago • 1 comments

Hello. Day 1 with sendGrid. Weekend warrior when it comes to coding. I have followed the simple instructions and have created a contactUs.js file which looks like this

import sgMail from "@sendgrid/mail"; sgMail.setApiKey(process.env.SENDGRID_API_KEY); const msg = { to: "[email protected]", from: "[email protected]", subject: "Hello world", text: "Hello plain world!", html: "

Hello HTML world!

", }; sgMail.send(msg); (I am using modules as seen above, if I have brought that over correctly)

My .env looks like this SENDGRID_API_KEY=SG.xW.......

And I am trying to run this in the backend with $node contactUs.js

I get in return API key does not start with "SG.". Followed by ResponseError: Unauthorized ...

What am I am missing in order to get this to go at this point and forward?

The solutions offered online for "API key does not start with "SG."" did not address my issue. A little help please.

donpayne199 avatar Feb 06 '25 22:02 donpayne199

Hey @donpayne199 First make sure that the email in from property match the email verifed in portal of sendgrid Second try to console.log the SENDGRID_API_KEY variable, if it log as undefined, that's telling you should use dotenv to include the .env variables

gor3a avatar Feb 16 '25 13:02 gor3a