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

Setup issue #356

Closed
DonWono opened this issue Feb 10, 2017 · 14 comments
Closed

Setup issue #356

DonWono opened this issue Feb 10, 2017 · 14 comments
Labels
type: question question directed at the library

Comments

@DonWono
Copy link

DonWono commented Feb 10, 2017

Hi,
I'm trying to setup SendGrid, and I'm just following the instructions in the tutorial for "With Mail Helper Class". After I run the following code:

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

I get an error "export: Command not found."

When I try to send my first send grid e-mail I get an error 401. 'The provided authorization grant is invalid, expired, or revoked.'

I've checked and echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env did create a sendgrid.env in my projects root folder.

When I checked the:
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
console.log(sg);

The console returns Authorization: 'Bearer undefined',.

Any help would be appreciated. Thank you.

All the best,
Don

  • sendgrid-nodejs Version: master (latest commit: [commit number])
  • Node v 6.3.1
@thinkingserious thinkingserious added the type: question question directed at the library label Feb 10, 2017
@thinkingserious
Copy link
Contributor

Hello @DonWono,

Are you developing on Windows, Mac or Linux?

@DonWono
Copy link
Author

DonWono commented Feb 11, 2017

Hi @thinkingserious

Thanks for your quick reply. I'm developing on a Mac. When everything works I will be deploying to an Ubuntu server.

@thinkingserious
Copy link
Contributor

What happens if you do the following from your command line:

echo $SENDGRID_API_KEY

If you don't see your API Key, try:

export SENDGRID_API_KEY='YOUR_API_KEY'
echo $SENDGRID_API_KEY

@DonWono
Copy link
Author

DonWono commented Feb 14, 2017

Hi @thinkingserious,
Thank you for your help! When I checked the echo $SENDGRID_API_KEY, it did print out my api key, but I still couldn't load it into my node application using:

var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);

I did a work around, and put the API_KEY into a JSON file and added the JSON file to gitignore.
Everything seems to be working now.

Thank you for your help.

@thegregthomp
Copy link

I'm having a similar issue when using a env variable. If I use the env variable I get the issue above. If I just drop the string into the require process it works. I can not figure out why.

Works...
var sg = require('sendgrid')('SG.iIpwjF6ASgmRuYmwl_KHoQ.EoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxY3NQ9vwd0');

Doesn't Work...
SENDGRID_API_KEY=SG.iIpwjF6ASgmRuYmwl_KHoQ.EoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxY3NQ9vwd0
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);

Even if I log out the env and compare it to the string it's an exact match.

@thinkingserious
Copy link
Contributor

Hello @thegregthomp,

Your "Doesn't Work" case is failing because process.env.SENDGRID_API_KEY is looking for the environment variable to be set.

On a Unix-like system, this is usually done like this on the command line:

export SENDGRID_API_KEY='YOUR_API_KEY'

Then you can verify it works by executing the following on the command line:

echo $SENDGRID_API_KEY

To get your "Doesn't Work" case to work:

SENDGRID_API_KEY=SG.iIpwjF6ASgmRuYmwl_KHoQ.EoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxY3NQ9vwd0
var sg = require('sendgrid')('SENDGRID_API_KEY');

But that is not recommended. We recommend you store your API Key in an environment variable for security reasons.

I hope that helps. Thanks!

@hridayam
Copy link

This is an old issue but I was facing a similar issue and the problem was that I had 2 terminal windows open. One for installing packages and the other for running the server. The source ./sendgrid.env needs to be done in the terminal window you're running the server in. So stopping the server, running the command and restarting the server fixed the issue for me.

@drewclem
Copy link

What's the solution to this if you're on windows? My issue may be different, as even with the key directly in place it still doesn't seem to work.

I do know it's not accessing my api key properly when I use .env but I also get 'unresolved promise...' as well

@aroach
Copy link
Contributor

aroach commented Dec 6, 2018 via email

@drewclem
Copy link

drewclem commented Dec 10, 2018 via email

@aroach
Copy link
Contributor

aroach commented Dec 13, 2018

Oh bummer @drewclem but glad you figured it out!

@hassanasif
Copy link

If you're a window user and getting source not recognized.
Try this command
set ./sendgrid.env
It works for me.

@MuhammadSufyanMalik
Copy link

Hi, I am still facing a 401 error from my python code. I have checked my environment variable is set properly as well.
What should i do ?? :(

@childish-sambino
Copy link
Contributor

@MuhammadSufyanMalik Tracking here: sendgrid/sendgrid-python#561

@sendgrid sendgrid locked as resolved and limited conversation to collaborators Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

9 participants