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.
sendEmail trigger while configuring the sendgrid client with a valid API key.When running inside the docker container, the request doesn't go through and the email is not sent. While running locally it works fine.
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!
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 proxyandsecure web proxy?EDIT:
Nvm, I logged all requests through the
httpmodule and after checking the headers I found the error - the API key variable was wrapped in quotes...Thanks for all your help!