An API key lets your app send email and call the Mailcandor API. Every key starts with mc_live_ and is shown once, when you create it.
Key types
| Type | Can do | Use it for |
|---|---|---|
| Sending only | POST /v1/emails, /v1/emails/batch, /v1/emails/check, GET /v1/whoami, the SMTP relay and the SendGrid and Postmark compatible endpoints |
App servers, SMTP clients, anything that only sends |
| Full access | Every endpoint, including domains, keys, webhooks, logs and broadcasts | Scripts and tools that manage your account |
A sending-only key can also be limited to one domain. It then refuses to send from any other domain with 403 restricted_api_key.
To create a key in the dashboard
- Open API keys and choose Create API key.
- Name: up to 50 characters. Name it after where it will live, such as
Production server. - Pick Sending only (the default) or Full access.
- For a sending-only key, optionally choose a domain under Limit to one domain. Leave it on Any domain on this team to allow all of them.
- Choose Create key.
- Copy the key with Copy, store it in your secrets manager, then choose I’ve copied it. It is not shown again.
To create a key with the API
Use a full-access key. permission defaults to full here, so set it explicitly:
curl https://api.mailcandor.com/v1/api-keys \
-H "Authorization: Bearer $MAILCANDOR_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Billing service", "permission": "sending", "domain_id": "DOMAIN_ID" }'
The answer is 201 with token, the new key. domain_id is only allowed with "permission": "sending". Get domain ids from GET /v1/domains.
To check which key you are using
curl https://api.mailcandor.com/v1/whoami -H "Authorization: Bearer $MAILCANDOR_KEY"
It returns your team name, the key name and its permission. Any key type can call it.
To revoke a key
In the dashboard: open API keys, choose Revoke on the key, then Revoke key. Anything still using it stops working at once. This cannot be undone.
With the API, using a different full-access key:
curl -X DELETE https://api.mailcandor.com/v1/api-keys/KEY_ID \
-H "Authorization: Bearer $MAILCANDOR_KEY"
You cannot revoke the key that makes the request. Use another key or the dashboard.
To rotate a key safely
- Create a new key with the same permission.
- Deploy it to your app.
- Watch Last used on the old key in the API keys list. When it stops changing, revoke it.
If it does not work
401 invalid_api_key: the key was revoked, mistyped or has spaces around it. Check with/v1/whoami.403 restricted_api_key: a sending-only key called an endpoint that needs full access, or a domain-limited key sent from another domain.403 forbiddenwhen creating or revoking keys with the API: the person who created the calling key is no longer an admin or developer. Use a key made by a current admin or developer.- No Create API key button: your role is viewer or billing. Ask an admin to change your role on the Team page.
- A domain-limited key disappeared: deleting a domain also deletes keys limited to it.
More in Error codes reference and at docs.mailcandor.com.