Docs
API reference
Everything the console does goes through the same HTTP API your agent uses, at /api on this origin. Requests and responses are JSON. New here? Start with a quickstart: Claude Code, Codex, TypeScript SDK, or curl and Python.
One click gives you a workspace and a key to paste into your agent. Nothing to sign up for.
Start without an account
An agent can open its own workspace with one call and hand you the console link. No email, no password, no key to copy by hand.
curl -s -X POST https://deskhand.grain64.com/api/guest -H "X-Deskhand: 1"
Send the X-Deskhand: 1 header and an empty body (no fields: an unknown field is refused with unknown_field). The response is 201 with:
key: the agent's bearer key, shown once. Use it asAuthorization: Bearer <key>on every call below.console_url: the link to give the human. Opening it signs them in to this workspace's console, where each run appears and can be reverted.connect: the same key as a readyclaude mcp addline, an MCP JSON block, the MCP URL and a curl example.limits: 50 records, 15 email drafts, 300 agent calls a day, one agent.expires_at: 7 days from now.
The guest agent can read and write the CRM and draft email. Drafts wait in the console for the human to approve; a guest workspace never sends mail. Five workspaces a day per address (429 rate_limited after that). The workspace is kept for 7 days; the human keeps it, with every record and the same key, by adding an email address under "Keep this workspace" in the console.
Tell your agent: "Start a Deskhand workspace with POST https://deskhand.grain64.com/api/guest (header X-Deskhand: 1), add Ada Lovelace as a contact and draft her a note, then give me the console_url."
Connect an agent
- Sign in, open Agents, name the agent and choose its scopes.
- Copy the key. It is shown once and stored hashed.
- Add Deskhand to your agent. For Claude Code, one line:
claude mcp add --transport http deskhand https://deskhand.grain64.com/api/mcp \ --header "Authorization: Bearer $DESKHAND_KEY"
The agent shows as connected in the console after its first call.
Any MCP client
The endpoint is POST https://deskhand.grain64.com/api/mcp: MCP over streamable HTTP, JSON-RPC, one JSON response per request, no session to keep. Authenticate with the agent key as a bearer token; initialize, ping and tools/list answer without a key, so any client or registry can inspect the 30 tools before a key exists. A generic client configuration:
{
"mcpServers": {
"deskhand": {
"type": "http",
"url": "https://deskhand.grain64.com/api/mcp",
"headers": { "Authorization": "Bearer ${DESKHAND_KEY}" }
}
}
}
Protocol versions 2025-06-18, 2025-03-26 and 2024-11-05 are accepted. Tools are checked against the key's scopes, its rate limit and its pause state on every call. A refused call comes back as a tool error with a machine-readable code, so the agent can act on it. A paused or revoked agent gets an HTTP 403 instead.
MCP tools
| Tool | Scope | What it does |
|---|---|---|
search_contacts | read_crm | Find contacts by text, status, source, company or a custom field, with a cursor for more |
upsert_contact | write_crm | Create or update by email; links or creates the company from company_domain or company_name; fields and tags merge |
update_contact | write_crm | Change a contact found by id or email |
create_deal, move_deal | write_crm | Open a deal, optionally linked to a contact by id or email; move it between stages |
add_note | write_crm | Attach a note to a contact or deal |
draft_email, list_email_status | draft_email | Draft one email to a contact (auto-approved unless approval is on) and read the status of this agent's emails, including the To send note |
get_policy | any | The workspace approval setting, what it means for this agent in plain words, caps and the block list |
Write tools accept an optional idempotency_key: repeating a call with the same key and arguments returns the first result instead of writing again. Every write is recorded in Activity with the agent, the run and the before and after values.
Plain HTTP
The same operations are available as REST calls on this origin, and the console uses them too:
curl https://deskhand.grain64.com/api/me \ -H "Authorization: Bearer $DESKHAND_KEY"
Autonomy and approval
A new workspace and a new agent key start autonomous: CRM writes apply at once and email drafts are approved automatically. Every action is audited with the agent, the run and the before and after values; each agent has a per-minute rate limit and a daily send cap; the operator can undo any single action or a whole run from Activity, and pause or revoke an agent instantly. Approval is a switch the operator can turn on, for the whole workspace or for one agent.
| Workspace setting (Settings, Agent approval) | CRM writes | Email drafts |
|---|---|---|
auto (default) | Apply at once | Approved automatically |
email | Apply at once | Wait for the operator in Approvals |
all | Wait for the operator: the call returns 202 with a pending change | Wait for the operator in Approvals |
| Per-agent setting | Effect |
|---|---|
mode: "direct" (default) | CRM writes follow the workspace setting |
mode: "propose" | This agent's CRM writes always wait for the operator, whatever the workspace setting |
email_approval: "inherit" (default) | Drafts follow the workspace setting |
email_approval: "auto" | This agent's drafts are approved automatically, even when the workspace is on email or all |
email_approval: "required" | This agent's drafts always wait for the operator, even when the workspace is on auto |
The operator sets mode and email_approval on the agent's page or through POST /api/agents and PATCH /api/agents/:id, and the workspace setting through PUT /api/policy with approval. Any other value returns 400 invalid_field. An agent reads what applies to it, in plain words, from the get_policy tool or GET /api/me.
How approved mail goes out
An agent drafts with draft_email. With approval off the draft is approved on the spot and recorded as approved by the default policy; with approval on it waits in Approvals until the operator approves it. Approved mail to the operator's own address, such as a test copy, is delivered by Deskhand. Approved mail to anyone else goes out through the To send queue: the draft response and list_email_status report each message's state in a note, and a queued message is not an error. Messages you send yourself do not count against any limit. The operator copies each message or opens it in their mail client, sends it from there, then chooses Mark sent and next (or Mark all sent once the lot is done). Deskhand records the send on the contact's timeline, moves the contact to contacted and tells the agent through list_email_status. Daily send caps, unsubscribe, the block list and the suppression of contacts who replied, unsubscribed or bounced apply in every setting.
Import and export
The Import screen takes a CSV, shows what would be created, filled in or skipped before anything is written, and undoes the whole import in one click. HubSpot and Attio contact exports are recognised and mapped; columns with no home become custom fields. Settings downloads everything as one JSON file, or any record type as CSV.
Campaigns
A campaign is an ordered sequence of steps run for each enrolled contact: emails, waits between them, and tasks for you or your agent. It lives next to your contacts, threads and suppression list, and everything is audited and reversible like the rest of Deskhand. An agent builds one, reads exactly what would go out over the next 14 days, launches it and reports on it, over MCP or HTTP, with the manage_campaigns scope. You watch and correct it in the console under Campaigns.
Build and launch a campaign in five calls
# 1. Create it with its steps and enroll contacts by tag, in one call
curl -X POST https://deskhand.grain64.com/api/campaigns \
-H "Authorization: Bearer $DESKHAND_KEY" -H "Content-Type: application/json" \
-d '{"name":"Seed outreach","strategy":"Engineers who maintain build tools. Two emails and a call task. Stop on any reply.",
"identity_id":"dry_run","window":{"start":"09:00","end":"17:00"},
"steps":[
{"type":"email","subject":"Quick question, {{first_name}}","body":"Hi {{first_name}},\n\nDo you run builds in CI?\n\n{{sender.name}}"},
{"type":"wait","days":3,"business_days":true},
{"type":"email","variants":[{"key":"A","body":"Following up, {{first_name | default: \"there\"}}."},{"key":"B","body":"Bumping this once, {{first_name}}."}]},
{"type":"task","title":"Call {{first_name}} if no reply","due_in_days":2,"kind":"call"}],
"enroll":{"tag":"seed"}}'
# 2. Read what would go out over the next 14 days, rendered per contact
curl -X POST https://deskhand.grain64.com/api/campaigns/$CID/simulate \
-H "Authorization: Bearer $DESKHAND_KEY" -H "Content-Type: application/json" -d '{"horizon_days":14,"contacts":20}'
# 3. Launch (refused with launch_blockers until they are fixed)
curl -X POST https://deskhand.grain64.com/api/campaigns/$CID/launch -H "Authorization: Bearer $DESKHAND_KEY"
# 4. Later: the report, per step and per variant
curl https://deskhand.grain64.com/api/campaigns/$CID/report -H "Authorization: Bearer $DESKHAND_KEY"
Over MCP the same flow is create_campaign (with steps and enroll), simulate_campaign, launch_campaign, campaign_report.
Delivery modes
- Dry run (the
dry_runidentity, always available): the engine runs for real. Enrollments advance, templates render, windows, caps and stop rules apply, and every message is recorded assent_dry. No provider is called and nothing is delivered. Reports say so and compute rates from dry-run records. - Live: delivery through your own sending identity (your Resend or Postmark account and your own domain), connected by you in Settings. Your provider key is stored encrypted, is never shown again and is never in exports or the audit log. An agent cannot create or read identities.
A campaign on your own identity runs as a dry run and reports the state sending_off; that is a normal state, not an error. The console always shows the mode as a badge: a dashed Dry run or a solid Live.
Steps
Step type | Fields |
|---|---|
email | subject and body, or variants (1 to 4, each key A to D, subject, body, weight); reply_in_thread (default true after the first email; a reply may leave the subject empty); condition (opened or not_opened, needs track_opens) with optional condition_step |
wait | days (0 to 60), business_days (default false) |
task | title, due_in_days, kind (task, call, meeting), assignee (human or agent), wait_for_done |
Templates use {{first_name}}, {{last_name}}, {{name}}, {{email}}, {{title}}, {{company.name}}, {{company.domain}}, {{sender.name}} and {{fields.<key>}}, with {{first_name | default: "there"}} as a fallback. No logic, no code. A contact whose step has an empty variable and no default is skipped for that step and the simulation shows it. A variant is assigned per contact and step, deterministically.
Campaign settings
| Field | Notes |
|---|---|
name, description, strategy | strategy is the agent's stated plan, shown to you at the top of the campaign and in the approval |
identity_id | dry_run (default) or an id from GET /api/sending-identities |
timezone_mode, timezone | contact (default: the contact's own zone, then the identity's) or fixed with an IANA timezone |
window, send_days, skip_dates | Default 09:00 to 17:00 local, Monday to Friday. send_days is a list of mon to sun; skip_dates a list of YYYY-MM-DD |
daily_cap | 1 to 500 a day for this campaign, on top of the identity's cap and warm-up |
stop_on | A reply, a bounce and an unsubscribe always stop a contact's sequence. Optional extras: deal_stage_change (default on), contact_status_change |
track_opens | Off by default. When on, a tiny image records opens, reported as unreliable because mail apps pre-load images. There is no click tracking and no link rewriting |
Unknown fields on any campaign endpoint return 400 unknown_field with the accepted list. Every field above round-trips on read.
Enrolling, stopping, safety
POST /api/campaigns/:id/enroll takes contact_ids, tag, source (or list), status, q or fields, plus dry_run (see who would be enrolled and who is skipped, with reasons) and on_conflict (skip or move). Suppressed, replied, unsubscribed, bounced, address-less and blocked-domain contacts are skipped with a reason. A contact is in one active campaign at a time; a second enroll is skipped as in_other_active_campaign unless you ask to move.
An enrollment stops with a machine-readable stop_reason: replied, bounced, unsubscribed, deal_stage_changed, contact_status_changed, manual, moved, suppressed, campaign_archived or reverted. Pausing a campaign freezes it; resuming shifts every pending step by the length of the pause, so nothing is lost and nothing bursts.
Every campaign email carries, added by Deskhand and not removable: the sender identity, your postal address (required in Settings before any launch; Deskhand never supplies one), a working unsubscribe link and the List-Unsubscribe and List-Unsubscribe-Post headers. A suppression list of addresses and domains is checked at enroll and again at every send. A new identity warms up at 20 emails a day, rising over three weeks and never above its configured cap.
launch is refused with launch_blockers (a list of code and message) until the postal address and sender name are set, there is an email step and a contact is enrolled, and, for a live identity, it is verified. With approval on, an agent's launch returns 202 and you approve the campaign once in Approvals, next to its plan and simulated timeline; individual emails are not queued one by one.
Campaign endpoints
| Endpoint | Purpose |
|---|---|
GET/POST /api/campaigns, GET/PATCH/DELETE /api/campaigns/:id | List, create (steps and enroll inline), read, edit, archive |
PUT /api/campaigns/:id/steps | Replace the ordered steps |
POST /api/campaigns/:id/enroll, GET /api/campaigns/:id/enrollments | Enroll; list by status or stop_reason |
POST /api/campaigns/:id/enrollments/:eid/stop | Stop one contact |
POST /api/campaigns/:id/run-due | Empty body. Runs the steps of a running campaign that are due now, once: sends (or records a dry run), creates tasks, applies stop rules and caps. Nothing runs on a timer; steps move when you or your agent call this, or press Run due steps in the console. Needs manage_campaigns (and send_email on a live identity). 30 calls an hour. Returns {ok, enrollments, sent, sent_dry, skipped, tasks, stopped, completed, failed}. |
POST /api/campaigns/:id/simulate | Body {as_of?, horizon_days? (default 14, max 60), contacts? (default 1000)}. Per contact and step: UTC and local send time, rendered subject and body, status (will_send, skipped_missing_variable, skipped_condition, blocked_by_cap, task_created), plus launch_blockers and problems. The real scheduler uses the same calculation |
POST /api/campaigns/:id/launch, pause, resume | Lifecycle |
GET /api/campaigns/:id/report | Enrolled, active, completed, stopped by reason, sent, sent_dry, skipped by reason, replied, bounced, unsubscribed, opens (if tracked), meetings, deals created; per step and per variant |
POST /api/campaigns/:id/test-send | Body {step, contact_id}: renders that step for that contact and sends it to your own address only |
GET/POST /api/suppressions, POST /api/suppressions/import | List, add (value, reason), import up to 1000 at a time. Removing an entry needs a signed-in human |
GET /api/sending-identities | Read-only for agents: the identities a campaign can use, never their keys |
Campaign MCP tools
| Tool | Scope |
|---|---|
create_campaign, update_campaign, enroll_contacts, launch_campaign, pause_campaign, resume_campaign, stop_enrollment, add_suppression | manage_campaigns (launching on a live identity also needs send_email) |
get_campaign, list_campaigns, simulate_campaign, campaign_report, list_sending_identities, list_suppressions | read_crm (or manage_campaigns) |
Every campaign change is one audit entry with before and after. You can revert a create (refused once real mail was sent), an enroll, a launch, a step edit, a pause or resume from Activity, or a whole run. Mail already sent cannot be unsent.
Scopes
| Scope | Allows |
|---|---|
read_crm | Search and read contacts, companies, deals, notes |
write_crm | Create, upsert, update and delete those records |
draft_email | Write email drafts and read their status. Drafts are auto-approved unless the operator turned approval on |
send_email | Send approved mail to a recipient the workspace may send to |
manage_tasks | Tasks and reminders |
manage_campaigns | Create, edit, enroll, launch, pause and stop campaigns, and add to the suppression list. Reading campaigns needs read_crm |
CRM endpoints
| Endpoint | Purpose |
|---|---|
GET /api/contacts | List. Filters: q, status, source, company_id, field.<name>=<value>, limit, cursor |
POST /api/contacts/upsert | Create or update by email. Optional company_name and company_domain link or create the company. fields merge into existing custom fields |
POST /api/contacts, GET/PATCH/DELETE /api/contacts/:id | Create, read, update, delete |
/api/companies, POST /api/companies/upsert | Same shape, de-duplicated by domain |
/api/deals | Stages: lead, contacted, qualified, proposal, won, lost. Move a deal with PATCH {"stage":"qualified"} |
POST /api/notes, GET /api/notes?contact_id= | Notes on a contact or deal |
Email endpoints
| Endpoint | Purpose |
|---|---|
POST /api/emails/draft | Draft one email to a contact. Scope draft_email. Fields are listed under Email draft below |
GET /api/emails, GET /api/emails/:id | Status of this agent's emails. Filters: status (comma separated), run_id, contact_id, limit, cursor. Each email carries status, reject_reason, note, warnings and prior_emails |
curl -X POST https://deskhand.grain64.com/api/emails/draft \
-H "Authorization: Bearer $DESKHAND_KEY" -H "Content-Type: application/json" \
-d '{"contact_id":"ctc_...","subject":"Question about your pipeline","body":"Hi Ada, ..."}'
Fields per record
Only the fields listed here are accepted. Any other field returns 400 unknown_field with the accepted list, so nothing is ever dropped silently. Put your own columns under fields. Strings are trimmed, and ids must belong to your workspace.
Contact
| Field | Type | Notes |
|---|---|---|
email | string | Required on /upsert. Lower-cased, the dedupe key |
name | string | Up to 200 characters. A contact needs a name or an email. first_name and last_name are accepted and joined into name |
title | string | Job title |
status | string | new (default), contacted, replied, qualified, closed. unsubscribed and bounced are reserved to the operator |
source | string | The list or run it came from |
company_id | string | An existing company. On /upsert you can send company_domain and/or company_name instead and the company is found or created |
tags | string[] | Up to 30 labels of up to 60 characters. Merged on upsert |
fields | object | Custom columns, up to 4096 bytes. Merged on upsert |
curl -X POST https://deskhand.grain64.com/api/contacts/upsert \
-H "Authorization: Bearer $DESKHAND_KEY" -H "Content-Type: application/json" \
-d '{"email":"ada@acme.com","name":"Ada Lovelace","title":"CTO","company_domain":"acme.com","tags":["warm"],"fields":{"stack":"Next.js"}}'
Company
| Field | Type | Notes |
|---|---|---|
name | string | Required on POST /api/companies. On /upsert either domain or name is required |
domain | string | For example acme.com. A full URL is reduced to the domain. The dedupe key |
notes | string | Up to 5000 characters |
Deal
| Field | Type | Notes |
|---|---|---|
title | string | Required |
stage | string | lead (default), contacted, qualified, proposal, won, lost |
value_cents | integer | Amount in the smallest currency unit, so 4800.00 is 480000. Default 0. value is accepted as the amount in major units (4800 or 4800.50) and converted. Send one or the other, not both |
currency | string | 3-letter code, default EUR |
contact_id | string | An existing contact |
company_id | string | An existing company. When you send contact_id without it on create, the deal takes that contact's company. Send "company_id": null to leave it empty |
source, fields | string, object | As on contacts |
curl -X POST https://deskhand.grain64.com/api/deals \
-H "Authorization: Bearer $DESKHAND_KEY" -H "Content-Type: application/json" \
-d '{"title":"Acme pilot","contact_id":"ctc_...","stage":"proposal","value_cents":480000,"currency":"EUR"}'
Email draft
| Field | Type | Notes |
|---|---|---|
contact_id | string | The contact to write to. Upsert the contact first. One of contact_id or to is required |
to | string | The contact's email address, used instead of contact_id. It must already be a contact in this workspace |
subject | string | Required, one line, up to 200 characters |
body | string | Required, plain text, up to 20000 characters. The sender identity and unsubscribe footer are added for you |
note | string | Optional, up to 500 characters. Your one-line reason for writing this draft. The operator sees it beside the draft in Approvals |
There is no cc, bcc, attachment or HTML field: a request that includes one returns 400 unknown_field and nothing is drafted. The response is 201 with the email and these fields:
| Response field | Meaning |
|---|---|
status | approved when approval is off, pending_approval when it is on |
note | Present when approved mail waits in the operator's To send list rather than being sent. Not an error |
warnings | Codes, empty when there is nothing to flag: open_draft_exists (another unsent draft to the same contact exists), emailed_today or emailed_N_days_ago (mail to this contact went out in the last 3 days), contact_status_<status> (for example contact_status_qualified). warning_messages holds the same in plain words. A warning does not block the draft: check it and withdraw the duplicate if it is not wanted |
prior_emails | {"sent_count","last_sent_at"}: mail already sent to this contact |
Refusals: 409 contact_suppressed (the contact replied, unsubscribed or bounced), 409 blocked_recipient, 404 contact_not_found, 429 draft_limit.
Note and task
| Field | Type | Notes |
|---|---|---|
Note: body | string | Required, up to 10000 characters |
Note: contact_id, deal_id | string | At least one is required |
Task: title | string | Required (POST /api/tasks, scope manage_tasks) |
Task: due_at | string | ISO date or date-time, for example 2026-10-14 |
Task: contact_id, deal_id, done | string, boolean | Optional links. done is accepted on PATCH |
Retries and runs
Send an Idempotency-Key header on writes. Repeating the same request with the same key returns the stored response instead of writing again; reusing a key with a different body returns 422.
Calls are grouped into runs. Send X-Run-Id (and optionally X-Run-Label) to name a run yourself; otherwise calls within 30 minutes of each other share one. Deskhand returns your id as run_<id> (unchanged if it already starts with run_), and ?run_id= accepts either form.
Errors
Errors return {"error":{"code","message","request_id"}}, plus field where one field is at fault.
| Status | Code | Meaning |
|---|---|---|
| 400 | unknown_field | The body has a field this endpoint does not accept. unknown_fields lists them and accepted lists the valid ones |
| 400 | invalid_field, invalid_email | A value is the wrong type, too long or not allowed. field names it, and the message lists the allowed values where there is a fixed set |
| 401 | invalid_key, key_revoked | Unknown key, or a key that was rotated or revoked |
| 403 | agent_paused, agent_revoked | The operator paused or revoked this agent. Stop and report it |
| 403 | missing_scope | The key lacks the scope named in required_scope |
| 202 | — | Only when approval is on for this agent: it is in propose-only mode, or the workspace approval is all. The change is stored as a pending change and applies when the operator approves it |
| 409 | contact_suppressed | The contact replied, unsubscribed or bounced. Do not draft or chase them |
| 403 | operator_only | Setting that field is reserved to the human operator |
| 429 | rate_limited | Per-minute limit for this agent reached |