I'm trying to send an email in a GitLab pipeline via Sendgrid.
The API key is base64 encoded, so I run:
SENDGRID_API_KEY=`printf $SENDGRID_API_KEY | base64 -d`
Yet when running the following, I get the error: "The provided authorization grant is invalid, expired, or revoked", which isn't true:
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header 'Authorization: Bearer $SENDGRID_API_KEY'\
--header 'Content-Type: application/json' \
--data '{"personalizations": [{"to": [{"email": "'${EMAIL_TO}'"}]}],"from": {"email": "'${FROM_EMAIL}'","name": "'${FROM_NAME}'"},"subject": "'${SUBJECT}'","content": [{"type": "text/html", "value": "'${bodyHTML}'"}]}'
If I don't use a variable for the Sendgrid API and instead have it as a string, it works perfectly fine.
Clearly, the syntax is getting muddled somehow when the variable is being read, such that Sendgrid thinks it's an invalid API key.
Can anyone advise on how to rectify this?