# MailmanAPI developer documentation

## Things worth knowing first.

- **A draft costs nothing.** Quoting, drafting, reading and canceling are free. A piece is charged only once it is approved.
- **A person approves by default.** Share `approval_url` so they can review and pay. An account owner can enable a key to approve from prepaid balance up to a monthly cap.
- **Quotes show how much each payment method costs.** `total_cents` is the price from balance. `card_total_cents` includes `payment_processing` for Checkout. Once paid, `payment.amount_cents` is the amount collected.
- **Approval starts a 30-minute hold.** Cancel before `cancel_until` for a full refund. After the hold the piece goes through screening before it can print.
- **Certified Mail needs a full return address.** USPS returns undelivered Certified Mail to the sender, so `from` needs a street, city, state and ZIP.
- **Test keys never buy postage.** In test mode every piece goes to a simulated print partner. Nothing is printed, mailed or charged.

## Quickstart.

No key is needed for a draft. The POST needs an Idempotency-Key, so a retry with the same body never makes a second piece.

1. POST the letter: who it goes to, who it is from, the service, and text or a PDF.
2. Show the person `approval_url`. They see the exact preview and itemized price, and approve.
3. Follow `mail_url`, or GET the piece, for its timeline, Certified Mail tracking and the return receipt.

```sh
curl https://mailmanapi.com/v1/mail \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: demand-letter-okafor-0001" \
  -d '{
    "product": "letter",
    "service": "certified_err",
    "to":   { "name": "R. Okafor", "line1": "418 Alder Court",
              "line2": "Apt 2", "city": "Macon", "state": "GA", "zip": "31201" },
    "from": { "name": "Sam Rivera", "line1": "77 Pine St",
              "city": "Atlanta", "state": "GA", "zip": "30303" },
    "document": { "text": "Dear R. Okafor, ..." }
  }'
```

## Endpoints.

Base URL `https://mailmanapi.com`. JSON in and out, PDF for documents, money in integer US cents. The full schema is at `/openapi.json` (OpenAPI 3.1). A person can add funds in Account.

| Call | Auth | What it does |
| --- | --- | --- |
| `GET /v1/products` | none | What can be sent, with starting prices. |
| `POST /v1/quotes` | optional | An itemized price for a letter by page count or PDF, or a postcard by size. |
| `POST /v1/mail` | optional | Create a draft: preview, price and approval link. |
| `GET /v1/mail/{id}` | key or link | A mailpiece, its timeline, any Certified tracking and the next step. |
| `GET /v1/mail` | key | Your key's mailpieces, newest first. |
| `POST /v1/mail/{id}/cancel` | key or link | Cancels a draft, or cancels a paid piece during its hold for a full refund. |
| `GET /v1/mail/{id}/preview` | key or link | The exact PDF that will be printed. |
| `GET /v1/mail/{id}/receipt` | key or link | The electronic return receipt PDF, when ready. |
| `POST /v1/addresses/verify` | optional | Check a US address before you draft. |
| `GET /v1/balance` | key | Read the owner’s prepaid balance. |
| `POST /v1/mail/{id}/approve` | key | Approve from prepaid balance only with an enabled auto-send key. Pass approval_hash. |
| `POST /v1/balance/top-up` | key | Return the account link where the owner can sign in and add funds. |

## MCP tools.

Streamable HTTP at `https://mailmanapi.com/mcp`. Use the private approval URL by default. Only an owner-enabled auto-send key can call approve_mail. The Claude directory endpoint at `https://mailmanapi.com/mcp/claude` has four tools for letter drafts and status.

- `list_mail_types`: What can be sent, the options, and starting prices.
- `quote_mail`: An itemized price, without making a draft.
- `send_mail`: Creates a draft with the preview, price and private approval link. It never charges or mails the draft.
- `get_mail`: State, timeline, any Certified tracking and the next step for one piece.
- `list_mail`: The pieces made with your key.
- `cancel_mail`: Cancels a draft, or cancels a paid piece during its hold for a full refund.
- `verify_address`: Checks a US address and returns the address it will use.
- `get_balance`: Read the owner’s prepaid balance in US cents.
- `approve_mail`: Spend from balance with the creating key when its owner enabled auto-send and set a cap. Pass id and approval_hash.

## Errors say how to fix the call.

Every REST error has the same shape: a code, a message, a fix your code or your model can act on, and the field at fault when there is one.

- **Approval is bound to what the person saw.** The draft's `approval_hash` covers the document, both addresses, the service, the route and the total. Any change is a new draft.
- **Retries are safe.** Within the same credential scope, the same Idempotency-Key and body return the same piece. A different body with the same key is refused.
- **Test mode never mails.** In test mode every piece goes to a simulated print partner, and its page says so.

```json
{
  "error": {
    "code": "address_undeliverable",
    "message": "The recipient address could not be confirmed. The street was not found.",
    "fix": "Confirm the recipient's street and ZIP code, then correct to and try again.",
    "field": "to",
    "reason": { "code": "street_not_found", "fields": ["to.line1"] }
  }
}
```

## Refusals, and what to tell the person.

Each code the API and MCP can return, what it means, and what an assistant should say. "Nothing" means the fix is in the call, not for the person.

| Code | What happened | What to tell the person |
| --- | --- | --- |
| `invalid_request` (422) | A field is missing or has the wrong value. `field` names it and `fix` says what to send. | Nothing yet. Fix the call, or ask the person for the one missing detail. |
| `invalid_json` (400) | The body is not valid JSON. | Nothing. Fix the request and send it again. |
| `idempotency_key_required` (400) | A draft was sent without an idempotency key. | Nothing. Add a key and send it again. |
| `idempotency_key_invalid` (400) | The key is not 16 to 255 letters, digits, underscores, periods, colons or hyphens. | Nothing. Fix the key and send it again. |
| `idempotency_mismatch` (409) | The key was already used with a different body. | Nothing. Resend the original body, or use a new key for a new draft. |
| `address_undeliverable` (422) | The recipient address could not be confirmed. `reason` says which part. | "I couldn't confirm that address. Can you check the street, unit and ZIP code?" |
| `pdf_invalid` (422) | The PDF can't be printed as sent: over 10 MB, password-protected, unreadable, or not portrait US Letter. | Say which of those it is, and ask for a fixed PDF. |
| `pages_out_of_range` (422) | The letter has more pages than the service takes. | Say how many pages it has and the limit, and ask whether to shorten or split it. |
| `document_missing` (422) | No document was sent. | Nothing. Send exactly one of text, pdf_base64 or pdf_url. |
| `document_ambiguous` (422) | More than one document source was sent. | Nothing. Send exactly one of text, pdf_base64 or pdf_url. |
| `unsupported_combination` (422) | An option was sent that this product doesn't take, such as pages on a postcard. | Nothing. Remove the option and send it again. |
| `approval_mismatch` (409) | The approval hash differs from the draft's current one. | "The draft changed since you looked. Here is the current preview and price." Show them both again. |
| `payment_unavailable` (501) | Live approval needs payments, and payments are not open yet. | "Live mail isn't open yet, so nothing was mailed or charged." |
| `too_late_to_cancel` (409) | The piece was already submitted to the print partner. | "It already went to print, so it can't be canceled." |
| `invalid_state` (409) | The action doesn't fit the piece's state, such as approving a canceled draft. | Read the piece and tell them where it stands, from its `next_step`. |
| `auth_required` (401) | The call needs the private link's token or the API key that made the piece. | Nothing. Use the full `mail_url` with its `t` token, or the creating key. |
| `invalid_api_key` (401) | The Bearer key is not valid. | Nothing. Remove the header to draft with an approval link, or use a valid key. |
| `mail_not_found` (404) | No piece with that ID is visible to this link or key. | Ask them for the full private link. |
| `provider_unavailable` (502) | No print partner can take this piece in the current mode. | "I can't send this kind of piece right now." |
| `not_implemented` (501) | Balance top-ups arrive with payments. | Nothing. There is no balance to top up yet. |
| `internal_error` (500) | Something failed on our side. | Retry once with the same idempotency key. If it fails again, say the mail service had an error, and give support the piece ID. |

## Named test recipients.

In test mode the recipient's name picks the outcome to rehearse, matched without regard to case. In live mode these are ordinary names. Test controls, where enabled, take precedence.

| Recipient name | Outcome |
| --- | --- |
| Test Delivered | The test clock, from submission: printed after 2 minutes, mailed after 5, in transit after 10, delivered after 20, and the return receipt after 25 (Certified with return receipt only). First-Class letters and postcards stop at mailed, as live mail does. Any other name follows this clock too. |
| Test Returned | Certified: mailed after 5 minutes, then returned after 10. |
| Test Print Failure | The print partner rejects it at submit. The piece is failed, with the reason. |
| Test Undeliverable | The address check fails at draft, with address_undeliverable. |
| Test No Scans | Mailed after 5 minutes and never scans, so you can see the empty tracking state. |

## Mailpiece statuses.

Every state a piece can be in, from the same table the API's next_step and the private pages use. Cancel means the private link or key can still cancel it.

| State | Label | Cancel | Next step for an assistant |
| --- | --- | --- | --- |
| `draft` | Draft | yes | Show approval_url to the person so they can review the preview and price and approve the draft. |
| `paid` | Approved | yes | Wait for the cancellation hold to end or cancel the piece before submission. |
| `screening` | Checking | no | Check the mailpiece again after the next processing tick. |
| `review` | In review | no | Check the mailpiece again for a decision. |
| `submitted` | At print | no | Check the mailpiece again for printing and postal updates. |
| `printed` | Printed | no | Check the mailpiece again for the USPS mailing update. |
| `mailed` | Mailed | no | Check the mailpiece for updates as it travels through USPS. |
| `in_transit` | In transit | no | Check the mailpiece again for the delivery update. |
| `delivered` | Delivered | no | Keep the mail link for your records. |
| `receipt_ready` | Receipt filed | no | Download the electronic return receipt at receipt_url. |
| `canceled` | Canceled | no | Create a new draft with a new idempotency key if you still want to mail it. |
| `failed` | Failed | no | Review the failure and create a corrected draft with a new idempotency key. |
| `returned` | Returned | no | Confirm the full recipient address before creating a new draft. |
| `refunded` | Refunded | no | Review the refund and create a new draft if you still want to mail it. |

First-Class letters get no USPS scans after hand-off. Choose Certified Mail if you need proof. Postcards get no USPS scans after hand-off. USPS keeps Certified tracking for 2 years.

## A sandbox run, start to finish.

A real test-mode run, captured 2026-11-27: the assistant drafts with send_mail, the person approves on the private page, the assistant reads the status, and a replay of the same idempotency key with a changed body is refused. Link tokens are shortened.

```
// 1. Assistant: send_mail
{
  "product": "letter",
  "service": "certified_err",
  "idempotency_key": "transcript-38a230da5f00",
  "to": {
    "name": "R. Okafor",
    "line1": "418 Alder Court",
    "line2": "Apt 2",
    "city": "Macon",
    "state": "GA",
    "zip": "31201"
  },
  "from": {
    "name": "Sam Rivera",
    "line1": "77 Pine St",
    "city": "Atlanta",
    "state": "GA",
    "zip": "30303"
  },
  "document": {
    "text": "Dear R. Okafor, …"
  }
}
→ {
  "id": "mp_ht6os4qvuhlkkluiauxy",
  "state": "draft",
  "total_cents": 1031,
  "approval_url": "https://mailmanapi.com/l/mp_ht6os4qvuhlkkluiauxy/approve?t=…",
  "mail_url": "https://mailmanapi.com/l/mp_ht6os4qvuhlkkluiauxy?t=…",
  "next_step": "Show approval_url to the person so they can review the preview and price and approve the draft."
}

// 2. The person: Approve on approval_url
{
  "approval_hash": "ade6d3c563fd…"
}
→ {
  "http": 303
}

// 3. Assistant: get_mail
{
  "mail_url": "https://mailmanapi.com/l/mp_ht6os4qvuhlkkluiauxy?t=…"
}
→ {
  "id": "mp_ht6os4qvuhlkkluiauxy",
  "state": "paid",
  "cancel_until": "2026-11-27T20:08:36.415Z",
  "next_step": "Wait for the cancellation hold to end or cancel the piece before submission.",
  "approval": {
    "at": "2026-11-27T19:38:36.415Z",
    "via": "approval_page"
  }
}

// 4. Assistant: send_mail
{
  "idempotency_key": "transcript-38a230da5f00",
  "service": "first_class",
  "…": "the rest unchanged"
}
→ {
  "isError": true,
  "error": {
    "code": "idempotency_mismatch",
    "message": "This idempotency key was already used with a different request.",
    "fix": "Resend the original body unchanged, or use a new idempotency key for a new draft.",
    "field": "idempotency_key"
  }
}
```
