0
votes

I created a powershell script to automate the installation of a SendGrid Account in Azure. Everything works as expected. But after the installation is done, I would like to create an API Key to use it later in C#. This does not work. I tried to send this command with powershell:

curl -Uri "https://api.sendgrid.com/v3/api_keys" -Method Post -Body '{"name":"QnA APi Key","scopes":["mail.send"]}'

and I get the following error: {"errors":[{"field":null,"message":"authorization required"}]}

It seems that it needs the header 'authorization: Bearer <>'. But in my case, my goal is to create this key because no one was created before.

Does anybody know how to proceed when no API key was created at all?

1

1 Answers

1
votes

Does anybody know how to proceed when no API key was created at all?

We could use the username and password to get the token. With the token then we could create the SendGrid API key.

1.Use username and password to get the token

POST https://api.sendgrid.com/v3/public/tokens HTTP/1.1
Content-Type:application/json
{"username":"[email protected]","password":"xxxxx"}

enter image description here

2.Use the token to create the api key

Post https://api.sendgrid.com/v3/api_keys
Content-Type:application/json
Authorization: token e43xxxxxxxxxx38acf
{
"name":"xxxx",
"scopes":["mail.send"]
}

enter image description here