Both errors mean the request did not carry a key Mailcandor recognises.
{ "error": { "type": "missing_api_key", "message": "Add your API key as \"Authorization: Bearer mc_live_...\"." } }
{ "error": { "type": "invalid_api_key", "message": "This API key is not valid. It may have been revoked." } }
Fix missing_api_key
The request had no bearer token. Send the header exactly like this:
Authorization: Bearer mc_live_xxxxxxxxxxxxxxxx
Common causes:
- The word
Bearerand a space are missing. - The environment variable is empty in this environment. Print its length (not its value) at startup:
console.log((process.env.MAILCANDOR_KEY || '').length). - A proxy or framework strips the
Authorizationheader. - For the Postmark-compatible endpoints, the key goes in
X-Postmark-Server-Tokeninstead; that works too.
Fix invalid_api_key
The key was sent but does not match an active key.
- Check it is complete. Keys start with
mc_live_. Copying often drops the last characters or adds a space or newline. Trim the value. - Check it still exists. Open API keys. Keys show their first characters (for example
mc_live_a1b2c3…). If yours is not in the list, it was revoked. - Check the team. If you are on several teams, the key may belong to another one.
- Check the base URL. Use
https://api.mailcandor.com. A key sent to another provider’s URL, or another provider’s key sent to Mailcandor, fails. - Check the audit log (admins):
api_key.revokedshows who revoked it and when. A key locked to a domain is deleted when that domain is deleted (domain.deleted).
Test the key on its own:
curl https://api.mailcandor.com/v1/whoami \
-H "Authorization: Bearer $MAILCANDOR_KEY"
A 200 shows the team, key name and permission. A 401 confirms the key is the problem.
Create a new key
Keys are shown once and cannot be recovered. Open API keys, press Create API key, choose Sending only for apps, copy the key into your secrets store, and redeploy. See Create an API key.
SMTP
The same problem over SMTP looks like:
535 5.7.8 Use the username "mailcandor" and an API key as the password.The username is wrong or the password is empty.535 5.7.8 That API key is not valid. It may have been revoked.
The username is always mailcandor, and the password is the full API key. See SMTP connection failed.
If it does not work
- 401 only in production. The production environment has an old or empty variable. Redeploy after updating it.
- 401 after moving from another provider. You are still sending the old provider’s key. Mailcandor needs an
mc_live_key. See Switched provider and it does not work. - It is a 403, not a 401. The key works but is sending-only or locked to another domain. See API key best practices.
See the API reference for authentication.