Authentication
Every request carries an API key in the X-API-Key header. A key can be limited to the scopes it needs, and it belongs on your server, never in browser or mobile code.
Related:Email validationEmail sending
Checked against the API source on
Send your key
| Header | Format | Use |
|---|---|---|
| X-API-Key | X-API-Key: <your key> | Recommended. |
| Authorization | Authorization: ApiKey <your key> | Also accepted. The word ApiKey, one space, then the key. |
curl "https://api.scrubimail.com/scrubimail/api/v1/validate/" \
-H "X-API-Key: $SCRUBIMAIL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]"}'Create and manage keys
Create keys on the API keys page in the app. You can run several keys side by side, for example one for production, one for staging and one for a CI job, each with its own name, optional expiry date and scopes. Rotating is explicit: create the new key, switch your service over, then deactivate the old one. Creating a key never disables the others.
The same key also works as the password for the SMTP relay, as long as it has the send scope.
Scopes
A scope limits what a key can do. A key with no scopes can use every endpoint. Once you pick scopes, the key can only call endpoints that need one of them. Scopes restrict API keys only; they do not apply to dashboard sessions.
| Scope | Allows |
|---|---|
| validate | POST /validate/, single email validation, and GET /domain-reputation/{domain}/. |
| validate:bulk | POST /validate-bulk/, bulk validation jobs. |
| send | POST /send/, single sends, and SMTP relay login. |
| send:bulk | POST /send/bulk/ and the campaigns endpoints. |
| domains | /send/domains/: add, list, verify and delete sending domains. |
| templates | /send/templates/, including starter templates. |
| suppressions | /send/suppressions/. |
| history | Validation history and analytics (/history/, /analytics/), and sending status, history and analytics (/send/status/, /send/history/, /send/analytics/). |
Your plan can restrict which scopes are available. Asking for a scope your plan does not include is rejected when you create or edit the key with Your plan does not include these scopes.
A call that needs a scope the key lacks fails with 403 and error.code set to permission_denied.
{
"success": false,
"error": {
"code": "permission_denied",
"message": "Your API key does not have the required scope for this endpoint.",
"details": [
{
"field": "non_field_errors",
"issue": "Your API key does not have the required scope for this endpoint."
}
]
}
}IP allow-list
A key can be locked to a list of IP addresses or CIDR ranges, for example 203.0.113.7 or 198.51.100.0/24. A request from any other address is rejected before anything else runs. When the list is set it also applies to SMTP logins made with that key.
- IP allow-listing is available on plans that include it. It is set up by ScrubiMail, not edited in the dashboard: email [email protected] with the key name and the addresses.
- The address checked is the one our edge sees for your connection. An
X-Forwarded-Forheader you send yourself is ignored. - An empty list means no restriction.
Authentication errors
Branch on error.code, not on the HTTP status. The codes are stable.
| Situation | Status | error.code | Message |
|---|---|---|---|
| No credentials sent | 401 | authentication_required | Authentication credentials were not provided. |
| Key unknown or deactivated | 401 | invalid_credentials | Invalid or inactive API key |
| Key past its expiry date | 401 | invalid_credentials | API key has expired |
| Request IP not on the key's list | 401 | invalid_credentials | Request IP is not in the API key's whitelist |
| Key sent as a Bearer token | 401 | invalid_credentials | Given token not valid for any token type |
| Key lacks the endpoint's scope | 403 | permission_denied | Your API key does not have the required scope for this endpoint. |
Keep keys server-side
- Never ship a key in browser, mobile or desktop code. Anyone who opens developer tools can read it. Call ScrubiMail from your backend and expose your own endpoint to the client.
- Load keys from environment variables or a secrets manager. Keep them out of source control, build logs and error reports.
- Use one key per service and give each only the scopes it needs. A signup form that only validates addresses needs just
validate. - Set an expiry date on keys for short-lived jobs and contractors.
- If a key leaks, deactivate it on the API keys page and create a replacement. Deactivated keys stop working immediately.
Something missing or wrong? Email [email protected].