Agent & Automation API

A serious email automation system can't be a destination. It has to be a participant in your broader workflow. 27+ JSON endpoints. Bearer auth. HIPAA hard-off.

Why it exists

Four integration paths the API serves.

Agentic Assistants

Claude, custom GPT-family agents, internally-hosted LLMs running tool-calling loops. The API gives the agent list_messages / search_mail / triage / draft_reply without rendering HTML or clicking buttons.

CRM / Ticketing

Pull "what mail did we get from Customer X this week" or "list of action-required messages from the last 24 hours" on demand. Surface mail context inline in the CRM record.

BI / Analytics

Triage activity as a data source — counts per category, response-time analytics, per-account volume trends. Standard data-pipeline tooling ingests the JSON.

Custom Automation

Python, shell, n8n / Zapier-style flows. A stable HTTP contract instead of scraping the admin UI. Cron jobs, scheduled triage sweeps, summary digests.

API Surface

27+ endpoints under /api/openclaw/*

Organized into five families. All return JSON. All bearer-token authenticated.

FamilyEndpointPurpose
Account + HealthGET /api/openclaw/healthLiveness + token-scope verification
GET /api/openclaw/accountsList accounts the token is scoped to
Mail Read + SearchGET /accounts/<id>/messagesPaginated mail list with filter
GET /accounts/<id>/messages/<msg_id>Single message detail
GET /accounts/<id>/mail/searchFull-text + structured search
POST /accounts/<id>/mail/bulkBulk-fetch multiple messages
POST /accounts/<id>/bulk/mail/fetchBulk-fetch with custom query DSL
GET /accounts/<id>/bulk/mail/fullFull-body bulk read
Mail WritePOST /accounts/<id>/messages/<msg_id>/labelApply a label
POST /accounts/<id>/messages/<msg_id>/moveMove to folder
POST /accounts/<id>/messages/<msg_id>/archiveArchive
POST /accounts/<id>/messages/<msg_id>/draftCreate a draft (with in_reply_to threading)
POST /accounts/<id>/bulk/mail/writeBatch label/move/archive
TriagePOST /accounts/<id>/triageTrigger triage with a custom query + limit
GET /api/openclaw/runsHistorical triage runs
CalendarGET /accounts/<id>/calendar/eventsList events in a date range
GET /accounts/<id>/calendar/events/<id>Single event detail
POST /accounts/<id>/calendar/eventsCreate event
POST /.../events/<id>/respondAccept / decline / tentative
GET /accounts/<id>/calendar/free-slotsFind free slots within a horizon
POST /accounts/<id>/calendar/bulk-respondBatch-respond to multiple events

Auth + Authorization

Bearer tokens. Owner-or-delegate scope. HIPAA hard-off.

Bearer Tokens

Each token is bound to a single user. The user's accounts are visible via the API. Tokens are created via the admin UI; revocation is immediate (token-table check on every request).

Per-Token Rate Limiting

Token-bucket algorithm with operator-configurable defaults. Different tokens get independent buckets so a runaway agent on one token doesn't starve others.

Owner OR Delegate, NOT Admin

A token can access only accounts the user owns or has been granted delegate access to. Admin role does NOT bypass this gate. Agent tokens carry operator intent, not role privilege. Narrow contract reduces blast radius if a token is compromised.

HIPAA Hard-Off

Any account with the HIPAA flag set returns 403 on this API surface, period. No "with BAA acknowledgment" override on this path. Even a properly-BAA-covered agent endpoint creates a second exfiltration surface — the safer posture is to keep HIPAA accounts UI-only.

In practice

Token management + sample response.

API token management

Token management UI — bearer tokens scoped to a single user's accounts

Sample JSON response from /api/openclaw/health

Sample JSON response from /api/openclaw/health — liveness, DB status, audit health, push watchers, build SHA

Integration patterns

Four ways teams wire this up.

Tool-calling agent (Claude, custom GPT, internal LLM)

Wire the API as a tool definition; the agent calls list_messages / search_mail / triage / draft_reply as natural-language requests come in. The agent never sees raw provider tokens; the operator manages OAuth lifecycle separately.

Scripted automation (cron + curl)

A daily cron job that calls POST /accounts/<id>/triage with a custom query, then GET /api/openclaw/runs to verify success. Useful for "run a sweep of marketing@ every Monday at 8am and post a summary to Slack."

BI / analytics pipeline

Pull /api/openclaw/runs into your data warehouse for triage volume + response-time analysis. The endpoint returns JSON; standard data-pipeline tooling (Airflow, dbt, Fivetran) handles the rest.

CRM integration

A custom webhook from your CRM hits GET /accounts/<id>/mail/search?from=customer@example.com to surface relevant mail context inline in the CRM record. No scraping. No re-authenticating against the provider.

Limitations

Transparent constraints.

Want to wire this to your agent stack?

A 30-minute call to scope integration patterns, token scoping, and webhook design.

Schedule a Conversation