Skip to content

Emails API

All endpoints require authentication and emails tool permissions.

POST /api/emails/sync

Syncs the current user’s Gmail for emails involving known contacts. Returns { synced, errors }.

GET /api/emails/sync/status

Returns { sync: { sync_status, last_synced_at, last_history_id, error_message } }.

GET /api/emails/threads

Query params: search, company_id, contact_id, direction (inbound|outbound), page, per_page

Returns { threads, total, page, pages }. Each thread includes companies[] with matched company names.

GET /api/emails/threads/:threadId

Returns { messages } — all emails in the thread ordered chronologically.

GET /api/emails

Flat email list. Query params: search, page, per_page.

GET /api/emails/:id

Returns { email, contacts } with linked contact/company info.

GET /api/emails/by-company/:companyId
GET /api/emails/by-contact/:contactId
POST /api/emails/send

Body:

{
"to": ["email@example.com"],
"cc": ["optional@example.com"],
"subject": "string",
"body_html": "string",
"contact_id": "optional",
"company_id": "optional",
"in_reply_to": "optional (RFC 822 Message-ID)",
"thread_id": "optional (Gmail thread ID for reply)"
}

Sends via Gmail API and stores in the emails table. Returns { email_id, gmail_message_id, thread_id }.