We respect your privacy

    MailGuard uses cookies and local storage to keep you signed in and remember your preferences. With your permission, we'd also like to use functional cookies (affiliate referrals) and analytics (anonymized error replays, and on the free domain check your time zone, screen size and a random visit identifier) to improve the product. Learn more

    Skip to main content
    Developers
    REST API reference

    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.

    Base URL
    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:

    quickstart.sh
    # 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.

    ScopeGrants
    domains:readRead domains, DNS records, sending sources and check results.
    domains:writeAdd domains to monitoring.
    domains:deleteRemove domains from monitoring.
    alerts:readRead alerts.
    alerts:writeAcknowledge and resolve alerts.
    reports:readRead DMARC aggregate reports (the daily reports mail providers send about who sent email as your domain).
    checks:runTrigger on-demand health checks.
    messages:verifyVerify whether a message really came from its domain (metered: spends credits).
    webhooks:manageCreate, edit, test and revoke outbound webhooks.
    audit_logs:readRead your org's audit log.
    mcp:basicUse the basic MCP tools (read + acknowledge).
    mcp:smartUse 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.

    PlanReadMutatingMCP basicMCP smart
    Free————
    Solo500 / h50 / h200 / h—
    Pro5,000 / h500 / h1,000 / h100 / 10 min
    Agency25,000 / h2,500 / h5,000 / h300 / 10 min
    Enterprise100,000 / h10,000 / h25,000 / h1,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.

    pagination
    # 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 envelope
    {
      "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"] }
      }
    }
    CodeHTTPMeaning
    missing_api_key401No Authorization header, or not `Bearer mg_live_…`.
    invalid_api_key401Key is unknown, revoked, expired, or on the Free plan.
    plan_required402This feature isn't available on your plan (e.g. webhooks on Free).
    insufficient_scope403The key is valid but missing the scope this endpoint needs.
    not_found404No such route, or the resource isn't in your org (anti-enumeration).
    method_not_allowed405The path exists but not for this HTTP verb — see the Allow response header.
    invalid_query400A path or query parameter is malformed (e.g. id isn't a UUID).
    invalid_body400The request body isn't valid JSON or fails validation.
    invalid_cursor400The pagination cursor is malformed — restart from the first page.
    domain_already_exists409That domain is already registered for your org.
    domain_verified_elsewhere409Another MailGuard organization has verified that domain.
    idempotency_in_progress409A request with this Idempotency-Key is still executing — retry with the same key after the Retry-After interval.
    idempotency_conflict422The Idempotency-Key was reused with a different body.
    domain_limit_reached422You've hit your plan's domain cap — upgrade to add more.
    webhook_limit_reached422You've hit your plan's webhook-endpoint cap.
    endpoint_disabled422The webhook endpoint is disabled — re-enable it first.
    rate_limited429Too many requests in the window. Wait for the reset.
    upstream_error502A dependency (e.g. the check service) returned an error.
    upstream_unavailable503A dependency is temporarily unavailable.
    internal_error500Unexpected 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).

    GET/v1/health

    Confirms the API is up and returns the serving region and server time.

    Domains

    Onboard, list and remove the domains you monitor.

    GET/v1/domains
    domains:read

    List your domains with health score, mode and onboarding status. Cursor-paginated; filter by status or mode.

    POST/v1/domains
    domains:write

    Add a domain to monitoring. Body: { domain_name, mode? }. Returns the new domain (with its id).

    GET/v1/domains/{id}
    domains:read

    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.

    DELETE/v1/domains/{id}
    domains:delete

    Stop monitoring a domain and remove its data.

    Alerts

    The attention queue — what needs a human across your portfolio.

    GET/v1/alerts
    alerts:read

    List alerts. Filter by severity, acknowledged/resolved state, alert type or domain.

    GET/v1/alerts/{id}
    alerts:read

    Fetch one alert by id.

    PATCH/v1/alerts/{id}
    alerts:write

    Acknowledge or resolve an alert once you've handled it.

    DMARC reports

    The aggregate (RUA) reports MailGuard ingests for your domains.

    GET/v1/dmarc-reports
    reports:read

    List ingested DMARC aggregate reports. Cursor-paginated.

    GET/v1/dmarc-reports/{id}
    reports:read

    One report with its top-200 per-source records embedded.

    Sending sources

    Who sends mail as your domain — ESPs, IPs, volumes and pass rates.

    GET/v1/sending-sources
    domains:read
    requires domain_id

    List 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.

    GET/v1/dns-records
    domains:read
    requires domain_id

    List 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.

    POST/v1/checks
    checks:run
    idempotent

    Run 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.

    GET/v1/checks/{id}
    domains:read or checks:run

    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.

    GET/v1/webhooks
    webhooks:manage

    List your webhook endpoints and their delivery health.

    POST/v1/webhooks
    webhooks:manage

    Create an endpoint. The signing secret (whsec_…) is returned ONCE — store it immediately.

    GET/v1/webhooks/{id}
    webhooks:manage

    Fetch one endpoint's configuration and status.

    PATCH/v1/webhooks/{id}
    webhooks:manage

    Enable/disable an endpoint or change its event types, severity floor or domain filter.

    DELETE/v1/webhooks/{id}
    webhooks:manage

    Revoke an endpoint. It stops receiving deliveries immediately.

    GET/v1/webhooks/{id}/deliveries
    webhooks:manage

    Inspect the delivery log for one endpoint — status, attempts, last response.

    POST/v1/webhooks/{id}/test
    webhooks:manage

    Enqueue 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).

    GET/v1/audit-logs
    audit_logs:read

    Stream your org's audit events to your SIEM. Cursor-paginated.

    GET/v1/audit-logs/{id}
    audit_logs:read

    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.

    EventFires when
    alert.createdA new alert is raised on one of your domains.
    alert.resolvedAn alert is resolved (by you or automatically).
    domain.health_changedA domain's health score crosses a bucket boundary.
    dns.changedMailGuard 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.processedA 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.

    Next steps