SendGrid — API key unauthorized with 403
SendGrid returns 403 Forbidden because the API key lacks the required scope or belongs to a different team or subuser, despite being valid.
Symptoms
- error: 403 Forbidden - The provided authorization grant is invalid
- The API key works for some endpoints but not others
- Mail send fails but template retrieval works
Possible causes
- The API key does not have mail.send permission
- The key is scoped to a subuser but the request targets the parent account
- The key was revoked or expired in the SendGrid dashboard
Diagnosis steps
Check the API key scopes
curl -X GET https://api.sendgrid.com/v3/scopes -H "Authorization: Bearer $KEY"Interpretation
The response lists the scopes granted to the key.
Verify the key is active
curl -X GET https://api.sendgrid.com/v3/api_keys -H "Authorization: Bearer $KEY"Interpretation
If 403, the key itself is invalid or revoked.
Root cause
The SendGrid API key does not have the required permission scope for the requested operation, so the server rejects it with 403.
Fix
Create a new API key with the required scopes, or update the existing key permissions in the SendGrid dashboard, and use the new key in the application.
Verify the fix
Retry the request with the updated API key and confirm it returns 202 Accepted.
Symptom walkthrough
SendGrid returns 403 Forbidden because the API key lacks the required scope or belongs to a different team or subuser, despite being valid. The error appears in production but may not surface in local development because the conditions that trigger it depend on the deployment environment or runtime configuration. Understanding the full symptom set helps distinguish this issue from similar errors.
Diagnosis in practice
Follow the diagnosis steps in the frontmatter to isolate the cause. Each step includes a command and an interpretation of the output. The goal is to narrow down whether the issue is in the configuration, the runtime, or the application code. Reproduce the error in a minimal setup before applying a fix.
Root cause
The SendGrid API key does not have the required permission scope for the requested operation, so the server rejects it with 403.
Fix
Create a new API key with the required scopes, or update the existing key permissions in the SendGrid dashboard, and use the new key in the application. After applying the fix, monitor the system to confirm the error does not recur under load or in different environments.
Verification
Retry the request with the updated API key and confirm it returns 202 Accepted. If the verification passes, the fix is confirmed; if not, re-examine the diagnosis steps for missed contributing factors.
Diagnostic commands
Run these commands to reproduce and diagnose the issue:
curl -X GET https://api.sendgrid.com/v3/scopes -H "Authorization: Bearer $KEY"
curl -X GET https://api.sendgrid.com/v3/api_keys -H "Authorization: Bearer $KEY"