2

I've dug through past Stack posts and nothing seems to fix the issue. I'm using the generated API key (NOT the API key ID), I've allowed all permissions, and I even tried opening a second account and trying it from there. Here is the code:

// Create new mail object.
var mail = new helper.Mail();

// Set 'from' for email.
var from = new helper.Email("owner@site.com", "First Last");
mail.setFrom(from)

// Set 'subject' for email.
mail.setSubject("SchemeBeam Email Verification");

// Create a new personalization, which will allow us to define
// an individual to send this email too, as well as define
// substitutions to use so we can replace a string, such as
// '%hash'%, in the email template with the real hash for this
// user.
var personalization = new helper.Personalization()
var to = new helper.Email("test1@example.com", "Example User");
personalization.addTo(to);

// Set hash substituion.
//var substitution = new helper.Substitution("%hash%", md5Hash);
//personalization.addSubstitution(substitution);

// Let's send it.
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
var request = sg.emptyRequest({
  method: 'POST',
  path: '/v3/mail/send',
  body: mail.toJSON(),
});

sg.API(request, function(error, response) {
  // Handle the response here.
  console.log(response.statusCode);
  console.log(response.body);
  console.log(response.headers);
});

And here is the error:

{ errors: 
   [ { message: 'The provided authorization grant is invalid, expired, or revoked',
       field: null,
       help: null } ] }
{ server: 'nginx',
  date: 'Wed, 16 Nov 2016 17:45:14 GMT',
  'content-type': 'application/json',
  'content-length': '116',
  connection: 'close',
  'x-frame-options': 'DENY' }
Jeremy
  • 149
  • 2
  • 14
  • Possible duplicate of [SendGrid API Key not working. "The provided authorization grant is invalid, expired or revoked"](http://stackoverflow.com/questions/34789622/sendgrid-api-key-not-working-the-provided-authorization-grant-is-invalid-expi) – bwest Nov 16 '16 at 22:03
  • possible duplicate... make sure you are using the API Key itself and NOT the API key ID – bwest Nov 16 '16 at 22:03
  • I specified that I was using the generated key. I am indeed using the API key. – Jeremy Nov 17 '16 at 16:25
  • I understand, I was just making sure that we had a common definition of what the generated key means. I would suggest contacting SendGrid support in this case as I don't see anything wrong with your code. – bwest Nov 18 '16 at 16:02

0 Answers0