The MailGuard REST API
23 JSON endpoints covering every operator surface — domains, alerts, DMARC reports (DMARC: the rule that tells mail servers to reject email pretending to be you), sending sources, DNS records (each one is a setting published for your domain that the rest of the internet reads), checks, webhooks and audit logs. One auth model, cursor pagination, idempotency keys and a stable error envelope.
Is this for you?
If you manage domains for clients and want to script onboarding, pull MailGuard data into your own tools, or wire domain health into a CI/CD check, the API is for you. You don't need to be a DMARC expert — the endpoints hand back plain fields (a health score, a policy, a pass rate), and every response tells you exactly what to do next.
Scoped keys
Mint keys in Settings with only the scopes you need. Revoke anytime.
Tenant-isolated
Every call is hard-scoped to your organization. You can't see another org's data.
Event-driven
Subscribe to alerts, DNS changes and DMARC reports via signed webhooks.
The API is available on every paid plan (Solo and up). The Free plan intentionally has no API access.
Base URL & authentication
Every request goes to the versioned base URL below and carries your API key as a bearer token. Keys look like mg_live_<hex> — create and revoke them in Settings → API keys. The full secret is shown once at creation; store it in your secret manager immediately.
https://api.themailguard.ai
# Every request:
Authorization: Bearer mg_live_<your-secret>Authentication runs before routing: an unauthenticated request always gets 401 regardless of the path, so the API surface is never leaked to anonymous probes. Every response carries an X-Request-Id — quote it in support tickets.
Quickstart
Mint a key with the domains:read and checks:run scopes, then:
# 1. List your domains (read scope)
curl -s "https://api.themailguard.ai/v1/domains" \
-H "Authorization: Bearer mg_live_REPLACE_ME"
# 2. Run a fresh check on one of them (checks:run scope, idempotent)
curl -sX POST "https://api.themailguard.ai/v1/checks" \
-H "Authorization: Bearer mg_live_REPLACE_ME" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: onboard-acme-2026-07-05" \
-d '{"domain_id":"11111111-1111-1111-1111-111111111111"}'Scopes
Keys follow Stripe's resource:action pattern. A key only carries the scopes you grant it; an endpoint whose scope you're missing returns 403 insufficient_scope. Grant the minimum a given integration needs.
| Scope | Grants |
|---|---|
| domains:read | Read domains, DNS records, sending sources and check results. |
| domains:write | Add domains to monitoring. |
| domains:delete | Remove domains from monitoring. |
| alerts:read | Read alerts. |
| alerts:write | Acknowledge and resolve alerts. |
| reports:read | Read DMARC aggregate reports (the daily reports mail providers send about who sent email as your domain). |
| checks:run | Trigger on-demand health checks. |
| messages:verify | Verify whether a message really came from its domain (metered: spends credits). |
| webhooks:manage | Create, edit, test and revoke outbound webhooks. |
| audit_logs:read | Read your org's audit log. |
| mcp:basic | Use the basic MCP tools (read + acknowledge). |
| mcp:smart | Use the AI-grade smart MCP tools (Pro plan and up). |
Rate limits
Limits are per API key and per surface. Every authenticated response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (unix seconds). On a 429 we also send Retry-After — honor it and back off.
| Plan | Read | Mutating | MCP basic | MCP smart |
|---|---|---|---|---|
| Free | — | — | — | — |
| Solo | 500 / h | 50 / h | 200 / h | — |
| Pro | 5,000 / h | 500 / h | 1,000 / h | 100 / 10 min |
| Agency | 25,000 / h | 2,500 / h | 5,000 / h | 300 / 10 min |
| Enterprise | 100,000 / h | 10,000 / h | 25,000 / h | 1,000 / 10 min |
Smart MCP tools share your organization's AI-chat budget (the same pool the in-app Olivio assistant uses) — no double accounting.
Pagination
List endpoints return { data, next_cursor, has_more }. Pass next_cursor back as the cursor query param to fetch the next page. Cursors are opaque and stable under concurrent inserts — a new row appearing between pages never duplicates or skips a result. Default page size is 50; the maximum is 200.
# First page
curl -s "https://api.themailguard.ai/v1/domains?limit=50" -H "Authorization: Bearer mg_live_…"
# → { "data": [ … ], "next_cursor": "eyJ0cyI6…", "has_more": true }
# Next page — pass the cursor back verbatim
curl -s "https://api.themailguard.ai/v1/domains?limit=50&cursor=eyJ0cyI6…" -H "Authorization: Bearer mg_live_…"Idempotency
Mutating endpoints accept an Idempotency-Key header. Sending the same key with the same body within 24 hours replays the original response instead of doing the work twice — safe to retry a request whose reply you never received. Reusing a key with a different body returns 422 idempotency_conflict. Generate one key per logical operation (e.g. per client onboarding).
Errors
Every non-2xx response uses one envelope. Switch on error.code (stable) rather than the HTTP status, and treat any unknown code as internal_error for forward compatibility.
{
"error": {
"code": "insufficient_scope",
"message": "This endpoint requires the `domains:read` scope.",
"request_id": "3f2a…", // echoes X-Request-Id
"details": { "required_scope": "domains:read", "key_scopes": ["alerts:read"] }
}
}| Code | HTTP | Meaning |
|---|---|---|
| missing_api_key | 401 | No Authorization header, or not `Bearer mg_live_…`. |
| invalid_api_key | 401 | Key is unknown, revoked, expired, or on the Free plan. |
| plan_required | 402 | This feature isn't available on your plan (e.g. webhooks on Free). |
| insufficient_scope | 403 | The key is valid but missing the scope this endpoint needs. |
| not_found | 404 | No such route, or the resource isn't in your org (anti-enumeration). |
| method_not_allowed | 405 | The path exists but not for this HTTP verb — see the Allow response header. |
| invalid_query | 400 | A path or query parameter is malformed (e.g. id isn't a UUID). |
| invalid_body | 400 | The request body isn't valid JSON or fails validation. |
| invalid_cursor | 400 | The pagination cursor is malformed — restart from the first page. |
| domain_already_exists | 409 | That domain is already registered for your org. |
| domain_verified_elsewhere | 409 | Another MailGuard organization has verified that domain. |
| idempotency_in_progress | 409 | A request with this Idempotency-Key is still executing — retry with the same key after the Retry-After interval. |
| idempotency_conflict | 422 | The Idempotency-Key was reused with a different body. |
| domain_limit_reached | 422 | You've hit your plan's domain cap — upgrade to add more. |
| webhook_limit_reached | 422 | You've hit your plan's webhook-endpoint cap. |
| endpoint_disabled | 422 | The webhook endpoint is disabled — re-enable it first. |
| rate_limited | 429 | Too many requests in the window. Wait for the reset. |
| upstream_error | 502 | A dependency (e.g. the check service) returned an error. |
| upstream_unavailable | 503 | A dependency is temporarily unavailable. |
| internal_error | 500 | Unexpected error — quote the request_id in a support ticket. |
Endpoint reference
All 23 endpoints, grouped by resource. Path parameters are UUIDs. read endpoints count against the read budget; mutating against the mutating budget.
Health
Unauthenticated-safe liveness probe (still requires a valid key).
/v1/healthConfirms the API is up and returns the serving region and server time.
Domains
Onboard, list and remove the domains you monitor.
/v1/domainsList your domains with health score, mode and onboarding status. Cursor-paginated; filter by status or mode.
/v1/domainsAdd a domain to monitoring. Body: { domain_name, mode? }. Returns the new domain (with its id).
/v1/domains/{id}Full detail for one domain — DMARC policy, SPF lookup count (SPF: the list of servers allowed to send email for your domain), latest check and MX provider.
/v1/domains/{id}Stop monitoring a domain and remove its data.
Alerts
The attention queue — what needs a human across your portfolio.
/v1/alertsList alerts. Filter by severity, acknowledged/resolved state, alert type or domain.
/v1/alerts/{id}Fetch one alert by id.
/v1/alerts/{id}Acknowledge or resolve an alert once you've handled it.
DMARC reports
The aggregate (RUA) reports MailGuard ingests for your domains.
/v1/dmarc-reportsList ingested DMARC aggregate reports. Cursor-paginated.
/v1/dmarc-reports/{id}One report with its top-200 per-source records embedded.
Sending sources
Who sends mail as your domain — ESPs, IPs, volumes and pass rates.
/v1/sending-sourcesList the observed sending sources for one domain. Requires the domain_id query param.
DNS records
The expected-vs-actual DNS records MailGuard tracks per domain.
/v1/dns-recordsList a domain's DNS records with expected value, actual value and verification status. Requires domain_id.
Checks
Run a fresh health check on demand and read past results.
/v1/checksRun a synchronous health check (DMARC + SPF + DKIM (a digital signature that proves an email really came from you) + MX + blacklist (public spam lists that mail providers check before accepting email)). Body: { domain_id }. Supports the Idempotency-Key header.
/v1/checks/{id}Fetch a single check result by id. Either scope works, so a checks:run-only key can poll the check it started.
Webhooks
Register outbound HTTPS endpoints that receive events as they happen.
/v1/webhooksList your webhook endpoints and their delivery health.
/v1/webhooksCreate an endpoint. The signing secret (whsec_…) is returned ONCE — store it immediately.
/v1/webhooks/{id}Fetch one endpoint's configuration and status.
/v1/webhooks/{id}Enable/disable an endpoint or change its event types, severity floor or domain filter.
/v1/webhooks/{id}Revoke an endpoint. It stops receiving deliveries immediately.
/v1/webhooks/{id}/deliveriesInspect the delivery log for one endpoint — status, attempts, last response.
/v1/webhooks/{id}/testEnqueue a synthetic event so you can verify your receiver end-to-end.
Audit logs
Your org's append-only record of processing (GDPR Article 30).
/v1/audit-logsStream your org's audit events to your SIEM. Cursor-paginated.
/v1/audit-logs/{id}Fetch one audit event by id.
Webhooks
Register an HTTPS endpoint (via POST /v1/webhooks or Settings → Webhooks) to receive events as they happen. Deliveries are signed and retried with exponential backoff (30s → 5m → 1h → 6h → dead-letter); an endpoint that fails 10 times in a row is auto-disabled and you get an alert.
| Event | Fires when |
|---|---|
| alert.created | A new alert is raised on one of your domains. |
| alert.resolved | An alert is resolved (by you or automatically). |
| domain.health_changed | A domain's health score crosses a bucket boundary. |
| dns.changed | MailGuard detects a change in a domain's DNS. Since 2026-09-25 `severity` is graded on the change's EFFECT (a weakened DMARC/SPF policy is critical; a change MailGuard applied itself, a duplicate cleanup or a restored record is info) and `classification` says what the change did. The previous record-type grade (NS, DMARC and MX critical, everything else warning) is still sent as `severity_legacy` for one deprecation cycle. Endpoint `min_severity` filters on `severity`. |
| dmarc_report.processed | A new DMARC aggregate report finishes ingesting. |
Verify each delivery with the HMAC header X-MailGuard-Signature: t=<unix>,v1=<sha256-hex> computed over <t>.<raw-body> with the whsec_… secret returned once at creation. Reject anything older than the 300-second anti-replay window.
SDKs & Terraform
A TypeScript SDK, a Python SDK and a Terraform provider live in the open-source repository. They are not yet published to npm, PyPI or the HashiCorp Registry — until they are, call the REST API directly (any HTTP client works) or vendor the SDK source. We'll announce package-registry availability here.
The REST API and the hosted MCP server are the two fully-supported, deployed integration surfaces today.