Recently we have decided to work on the domain authentication workflow through SendGrid API endpoints (https://docs.sendgrid.com/api-reference/domain-authentication/authenticate-a-domain)
As per the documentation, I have setup the request for the domain authentication, but the response I got was 401 status code stating,
Request:
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'], host: nil, request_headers: {'on-behalf-of' => 'None'})
data = JSON.parse('{
"domain": "example.com"
}')
response = sg.client.whitelabel.domains.post(request_body: data)
puts response.status_code
puts response.body
Response:
401
{"errors":[{"field":null,"message":"authorization required"}]}
I have used the same SendGrid API key for other use cases, like getting the scopes of the API key (https://docs.sendgrid.com/api-reference/api-key-permissions/retrieve-a-list-of-scopes-for-which-this-user-has-access) and sending the email through SendGrid, and also I have enabled Full Access for it.
But for other API endpoints like authenticating the domain and creating API keys, it throws the same error like 'authorization required'.
Can someone explain regarding this?