Sendgrid-nodejs: 401 Unauthorized inside a docker container

Created on 24 Mar 2019  路  5Comments  路  Source: sendgrid/sendgrid-nodejs

Issue Summary

Trying to send email through a server inside a docker container running on the local machine but I keep getting 401 Unauthorized. When running the server locally (not in a container) everything works well. The configuration is the same, both running with production env, same API key is setup correctly and accessible in both cases.

Steps to Reproduce

  1. Setup a simple server and hook-up an sendEmail trigger while configuring the sendgrid client with a valid API key.
  2. Try to trigger it while running the server locally.
  3. Try to trigger it while running the server inside a docker container.

When running inside the docker container, the request doesn't go through and the email is not sent. While running locally it works fine.

Technical details:

  • sendgrid-nodejs Version: 6.3.1
  • Node.js Version: 11.11.0
  • Condainer Node.js Version: 11.11.0 or lts-alpine
unknown or a waiting for feedback question

Most helpful comment

@thinkingserious, I can't manage to log the outbound request to sendgrid. I've used Postman and Charles proxy but none of them catches the api request. The request to the local server shows up but not the one it makes to sendgrid. Other requests show up as well. Any pointers? Do I need to check anything else apart from web proxy and secure web proxy ?

EDIT:

Nvm, I logged all requests through the http module and after checking the headers I found the error - the API key variable was wrapped in quotes...

Thanks for all your help!

All 5 comments

Hello @monojack,

This error occurs when either the API is not set or your API key is invalid. It looks like your key is valid, so I would ensure that the API key is getting set properly inside of your container. I suspect it works locally, because you have defined your API key in a local environment variable.

With Best Regards,

Elmer

@thinkingserious,
I do set it up correctly in the container as well... For debugging I just console.log the key right before configuring the client and it shows up. I have other env variables and everything else is working fine.

Hello @monojack,

Please use Postman or similar and examine the API call being transmitted via your container vs. the API call being transmitted via your local environment. Perhaps that will point you in the right direction. Please give it a try and let me know what you find. Thanks!

With Best Regards,

Elmer

@thinkingserious, I can't manage to log the outbound request to sendgrid. I've used Postman and Charles proxy but none of them catches the api request. The request to the local server shows up but not the one it makes to sendgrid. Other requests show up as well. Any pointers? Do I need to check anything else apart from web proxy and secure web proxy ?

EDIT:

Nvm, I logged all requests through the http module and after checking the headers I found the error - the API key variable was wrapped in quotes...

Thanks for all your help!

Awesome, thanks following up!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prasoonjalan picture prasoonjalan  路  3Comments

Loriot-n picture Loriot-n  路  4Comments

umarhussain15 picture umarhussain15  路  3Comments

Chrischuck picture Chrischuck  路  3Comments

egges picture egges  路  3Comments