# Quickstart

Go from a sandbox key to a simulated, submitted mail order in about fifteen minutes with `curl`.

The sandbox never prints, mails or creates work for Xcel staff. Every step below uses a sandbox key (`xm_test_...`).

## Before you start

You need:

- A sandbox API key (`xm_test_...`). Request sandbox access at [www.updash.com/developers/agents](https://www.updash.com/developers/agents), sign in to the console from the emailed link, and create a test key under **Developers** ([Get sandbox access](console.md#get-sandbox-access)).
- The base URL: `https://api.updash.com`.
- A dealer id: Xcel's dealer id or your own external id for the dealer. `GET /v1/dealers` (step 1) lists yours. Every self-serve sandbox starts with a sample dealer whose external id is `demo-motors`. A sandbox key can also create your own stores as [test dealers](dealers.md#test-dealers), whose changes save. Its changes to the sample dealer and to dealers your live key made only validate ([Test keys only validate](dealers.md#test-keys-only-validate)).
- `curl` and, for the copy-paste variables below, [`jq`](https://jqlang.org/).

Prefer code? Three scripts run this whole flow: [Node](examples/node/sandbox.mjs) (Node 22 or later, `fetch` only), [Python](examples/python/sandbox.py) (Python 3.9 or later, standard library only) and [MCP](examples/mcp/sandbox.mjs) (the official MCP TypeScript client: put its [package.json](examples/mcp/package.json) beside it and run `npm install` first). Download one and run it with your sandbox key, for example `XM_API=https://api.updash.com XM_KEY=xm_test_... node sandbox.mjs`. Each prints every step and stops at the first error with its `fix`. Each also stops at the approval: it prints `review_url` and waits for a person to decide in a browser. The Node and Python scripts take `XM_SANDBOX_APPROVE=1` to decide it with the sandbox's test route instead. No route or tool approves a live order. `XM_DEALER` picks the dealer (your first one by default). Each also registers a webhook endpoint, checks a delivery's signature with a small receiver on `127.0.0.1` and deactivates the endpoint at the end. Against the hosted API, set `XM_WEBHOOK_PORT`, point a tunnel at that port and set `XM_WEBHOOK_PUBLIC_URL` to the tunnel's https URL; without one the signature check is skipped. Xcel's end-to-end test runs all three, so they stay in step with the API.

Prefer Postman? Import the [collection](postman/updash-mail-api.postman_collection.json) and its [sandbox environment](postman/updash-mail-api.postman_environment.json), set `apiKey` to your sandbox key and send the requests folder by folder: they follow these steps and save each id for the next one, and the Sandbox folder moves the order to `completed` before the Results folder reads it.

Prefer TypeScript? A pre-release SDK exists, but it is not published: `@updash/mail-api` is not on npm (the npm package `updash` is someone else's), so plain HTTPS is the supported way in today. Ask Xcel if you want the package. [Its README](sdk/typescript.md) shows that it runs these steps with typed methods, safe retries and paging, and checks webhook signatures with `verifyWebhook`; its README walks this flow.

```bash
export API=https://api.updash.com
export KEY=xm_test_REPLACE_WITH_YOUR_SANDBOX_KEY
export DEALER=demo-motors
H="Authorization: Bearer $KEY"
```

Every response is JSON. Every error has the shape `{"error":{"code","message","fix","field"}}`; do what `fix` says. Most responses that change state include `next_step`, a sentence saying what to call next.

## 1. Find a template and look at the dealer

```bash
curl -s -H "$H" "$API/v1/templates?product_code=postcard_6x9" | jq '.templates[] | {code, name, use_cases}'
curl -s -H "$H" "$API/v1/templates?query=birthday"
curl -s -H "$H" $API/v1/dealers
curl -s -H "$H" $API/v1/dealers/$DEALER/brand
```

`GET /v1/templates` lists Xcel's twenty-four templates (fourteen 6 x 9 postcards, five tri-fold letters and five fold cards, from two birthday pieces to a warranty letter and a holiday card) and any you have saved yourself ([Your own templates](creative.md#your-own-templates)); filter them by `product_code`, `use_case` or `query`. It answers one short entry per template (`detail=full` adds every slot and the compliance rules). The query `birthday` finds the two birthday pieces, the postcard first:

```json
{
  "code": "postcard_6x9_birthday",
  "product_code": "postcard_6x9",
  "name": "Birthday postcard with a gift",
  "summary": "Birthday postcard for the dealer's customers, designed as a wrapped gift.",
  "use_cases": ["birthday", "customer_loyalty", "gift_offer"],
  "required_slots": ["note", "expires"],
  "audience_columns": ["vehicle_year", "vehicle_make", "vehicle_model"],
  "requires_prescreened_list": false,
  "preview_url": "https://api.updash.com/preview/AQBq6LOA...5fS5rHS39uV3JjXLSPUS2w"
}
```

Open `preview_url` in a browser: it shows the template with its sample copy for the sample dealer Demo Motors, for one hour, with no key. `audience_columns` are the columns the piece reads from your file beyond the name and address (here, the vehicle, which the sample note names). `GET /v1/templates/postcard_6x9_birthday` gives every slot with its `kind`, `max_length`, `sample` and any `default`. See [Creative](creative.md#templates) for every template and slot. To see the template printed with your own copy before you create a campaign, call `POST /v1/templates/{code}/preview` ([Preview a template](creative.md#preview-a-template)).

This is what a new creative prints for the dealer: name, address, logo, colors and phone from its profile, which you can change ([Dealers](dealers.md)), the disclosures, which only Xcel sets, and the registered approvers, whom you name ([Approvers](dealers.md#approvers)). This is a sample dealer; yours shows its own values:

```json
{
  "dealer_id": "05720507-ac60-4915-977e-f12e9cd29b3f",
  "dealer_name": "Demo Motors",
  "address": { "line1": "100 Demo Blvd", "line2": null, "city": "Columbus", "state": "OH", "zip": "43004" },
  "logo_url": "data:image/png;base64,...",
  "logo": { "source": "url", "url": "data:image/png;base64,..." },
  "colors": { "primary": "#0B3D93", "secondary": "#FFB020" },
  "disclaimers": ["Offer valid at Demo Motors only. See dealer for details.", "Sample disclosure: each dealer's own disclosures, set by Xcel, print here."],
  "phone": "(380) 246-4003",
  "locked": true,
  "registered_approvers": [],
  "profile_version": 1,
  "note": "Name, address, logo, colors and phone come from the dealer profile, which you keep current (GET and PATCH /v1/dealers/{id}/profile, POST /v1/dealers/{id}/logo); a creative prints the profile version it was made with. Disclosures are set by Xcel. Registered approvers are the people you named who confirmed (POST /v1/dealers/{id}/approvers)."
}
```

## 2. Create a campaign

```bash
C=$(curl -s -H "$H" -H 'content-type: application/json' $API/v1/campaigns \
  -H "Idempotency-Key: $(uuidgen)" \
  -d "{\"dealer_id\":\"$DEALER\",\"product_code\":\"postcard_6x9\",\"name\":\"November service reminder\",\"external_ref\":\"cmp_778\"}" \
  | tee /dev/stderr | jq -r .campaign.id)
```

Response (201):

```json
{
  "campaign": {
    "id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
    "mode": "test",
    "name": "November service reminder",
    "dealer_id": "05720507-ac60-4915-977e-f12e9cd29b3f",
    "dealer_external_id": "demo-motors",
    "product_code": "postcard_6x9",
    "template_code": null,
    "template_version": null,
    "envelope": null,
    "requested_mail_date": null,
    "status": "draft",
    "status_label": "Draft",
    "status_evidence": null,
    "creative_version": null,
    "audience_version": null,
    "external_ref": "cmp_778",
    "metadata": {},
    "created_at": "2026-11-02T15:00:00.000Z",
    "updated_at": "2026-11-02T15:00:00.000Z"
  },
  "next_step": "Upload the audience: upload_audience (POST /v1/campaigns/{id}/audience).",
  "live_gaps": [],
  "timing": {
    "mail_class": "first_class",
    "earliest_mail_date": "2026-11-04",
    "mailed_by": "2026-11-04",
    "first_scan_by": "2026-11-09",
    "in_home_from": "2026-11-11",
    "in_home_to": "2026-11-13",
    "placeholder_timing": true
  }
}
```

To ask for a mail date, add `"requested_mail_date": "YYYY-MM-DD"`. It is optional; without it Xcel mails on the first available date. A date before today (UTC) is refused with `mail_date_in_past`, and one more than 180 days out with `mail_date_too_far`. `timing` holds placeholder dates, not promises ([Mail dates](quotes-and-approvals.md#mail-dates)).

`envelope` is `null` because a postcard has none. A letter mails in a #10 envelope with no window, which the printer addresses, unless you send `"envelope": "double_window"` on create for a #10 double-window envelope ([A letter's envelope](concepts.md#a-letters-envelope)).

The campaign names its dealer by both ids (`dealer_id` is Xcel's, `dealer_external_id` yours) and, once it has a creative, the template the creative prints (`template_code` and `template_version`; `null` until then, and for your own HTML or print-ready artwork). `external_ref` is your own id for the order and `metadata` holds up to 20 string labels; both come back on the campaign, its results and its webhooks, and `GET /v1/campaigns?external_ref=cmp_778` finds the order later ([Your reference on a campaign](concepts.md#your-reference-on-a-campaign)). Never put customer data in them. The `Idempotency-Key` is optional here: a retry with the same key and body returns the first campaign (`Idempotent-Replayed: true`) instead of making a second one. In a real integration, keep the key with your order and reuse it only to retry.

## 3. Upload the audience

Save this file as `audience.csv`. The last three rows are bad on purpose, so you can see the reconciliation report. The first column, `external_id`, is your own id for each person (a CRM id, say); results come back per lead with it, so you can join them to your records:

```csv
external_id,first_name,last_name,address1,address2,city,state,zip,vin,vehicle_year,vehicle_make,vehicle_model,service_advisor
crm-1001,Maria,Lopez,412 Cedar Ln,,Springfield,IL,62704,1HGCV1F30LA012345,2020,Honda,Accord,Dana
crm-1002,JAMES,O'BRIEN,88 Lake Shore Dr,Apt 3B,Chicago,Illinois,60611-2201,,2018,Ford,Escape,
crm-1003,Priya,Shah,1200 W Main St,,Peoria,IL,61606,,2022,Toyota,RAV4,Ravi
crm-1004,Tom,Nguyen,5 Elm Ct,,Normal,IL,61761,,2019,Chevrolet,Malibu,Dana
crm-1005,,Baker,77 Oak St,,Decatur,IL,62521,,2021,Kia,Sorento,
crm-1006,Ann,Lee,9 Pine Rd,,Champaign,ZZ,61820,,2017,Nissan,Altima,
crm-1007,Maria,Lopez,412 Cedar Lane,,Springfield,IL,62704,,2020,Honda,Accord,Dana
```

This step uses the signed upload, which works for any file size. To send the file in one call instead, POST it as the body: `curl -s -H "$H" -H 'content-type: text/csv' --data-binary @audience.csv $API/v1/campaigns/$C/audience/import` answers with the same report as the completion below, or send `{"source_url": "https://..."}` for a link Xcel fetches once ([Import in one call](audiences.md#import-in-one-call)).

Ask for a signed upload URL:

```bash
UP=$(curl -s -H "$H" -X POST $API/v1/campaigns/$C/audience)
echo "$UP" | jq
AUD=$(echo "$UP" | jq -r .audience_id)
URL=$(echo "$UP" | jq -r .upload_url)
```

Response (201):

```json
{
  "audience_id": "09ef23ca-cee4-4669-b282-828ce568bb64",
  "version": 1,
  "upload_url": "https://abcdefghijklmnopqrst.supabase.co/storage/v1/object/upload/sign/audiences/407603e8-5469-46dc-bf46-9374fc5cdad4/20b6b4d9-f321-41ef-aa5e-c1db05b559fd/v1/source.csv?token=eyJhbGciOi...",
  "upload_method": "PUT",
  "upload_content_type": "text/csv",
  "upload_expires_in_seconds": 7200,
  "suppression_upload_url": null,
  "required_columns": ["first_name", "last_name", "address1", "zip"],
  "optional_columns": ["external_id", "address2", "city", "state", "vin", "vehicle_year", "vehicle_make", "vehicle_model", "<any custom merge field>"],
  "template_columns": null,
  "next_step": "PUT the CSV (UTF-8, header row first) from the user's own system to upload_url: your host's upload function or the person does it, and rows never go in the chat or a tool argument. Then POST /v1/campaigns/{id}/audience/complete with this audience_id (MCP: call upload_audience again with uploaded_audience_id). Name your record-id column external_id, or send column_map {\"customer_id\": \"external_id\"} with the completion, so per-lead results come back keyed by your id. Phone and email columns are optional: UpDash uses them only to match responses and sales to the piece, and they are never printed or returned."
}
```

PUT the file to `upload_url`. The URL carries its own token, so do not send your API key with it. Expect `200`:

```bash
curl -s -o /dev/null -w '%{http_code}\n' -X PUT -H 'content-type: text/csv' --data-binary @audience.csv "$URL"
```

`template_columns` lists the columns the campaign's creative reads beyond the name and address (its custom columns, and the vehicle columns when it prints the vehicle); it is `null` here because the campaign has no creative yet. Then tell the API to process it. If your columns have other names, add `column_map` to this body, for example `{"customer_id": "external_id"}` ([Column mapping](audiences.md#column-mapping-column_map)):

```bash
curl -s -H "$H" -H 'content-type: application/json' $API/v1/campaigns/$C/audience/complete \
  -d "{\"audience_id\":\"$AUD\"}" | jq
```

Response (200), trimmed:

```json
{
  "audience": {
    "id": "09ef23ca-cee4-4669-b282-828ce568bb64",
    "version": 1,
    "status": "ready",
    "submitted_count": 7,
    "mailable_count": 4,
    "rejected_count": 3,
    "reconciliation": {
      "submitted": 7,
      "mailable": 4,
      "rejected": 3,
      "rejected_by_reason": { "missing_first_name": 1, "invalid_state": 1, "duplicate": 1 },
      "rejected_rows": [
        { "row": 6, "reason": "missing_first_name", "external_id": "crm-1005" },
        { "row": 7, "reason": "invalid_state", "external_id": "crm-1006" },
        { "row": 8, "reason": "duplicate", "external_id": "crm-1007" }
      ],
      "rejected_rows_truncated": false,
      "warnings": {},
      "columns": ["first_name", "last_name", "address1", "city", "state", "zip", "address2", "vin", "vehicle_year", "vehicle_make", "vehicle_model", "external_id", "service_advisor"],
      "blank_counts": { "address2": 3, "vin": 3, "vehicle_year": 0, "vehicle_make": 0, "vehicle_model": 0, "external_id": 0, "service_advisor": 1 },
      "suppression_list_rows": 0,
      "column_map": {},
      "column_warnings": [],
      "suggested_column_map": null,
      "address_processing": {
        "status": "processed",
        "processor": "sandbox_pass_all",
        "note": "Sandbox: address processing is simulated and every address passes.",
        "processed_at": "2026-11-02T15:00:00.000Z",
        "cass_failed": 0,
        "ncoa_moved": 0
      },
      "reprocessed_from_version": null
    },
    "retention_expires_at": "2027-01-31T15:00:00.000Z",
    "created_at": "2026-11-02T15:00:00.000Z",
    "completed_at": "2026-11-02T15:00:00.000Z",
    "purged_at": null
  },
  "campaign_status": "draft",
  "next_step": "Generate the creative: generate_creative (POST /v1/campaigns/{id}/creative)."
}
```

Row numbers are spreadsheet rows: the header is row 1. `column_warnings` is empty because the file names its id column `external_id` and has no email or phone columns; without `external_id` it would warn `external_id_column_missing` and propose a map ([Column warnings](audiences.md#column-warnings)). Row 8 is a duplicate of row 2 because `Cedar Ln` and `Cedar Lane` normalize to the same address. The response never contains a name or an address. Each mailable row also gets a row key, which ties it to its results ([Lead identity](audiences.md#lead-identity)). See [Audiences](audiences.md) for every reason code.

With the audience in place, `next_step` names the creative. Had the report proposed a `suggested_column_map`, `next_step` would first say to complete the same `audience_id` again with it.

## 4. Generate the creative

Fill the template's copy slots. `gift_offer` is a dealer fact: only the dealer can promise the gift. Send the dealer's own, as here, or leave it out for the standard gift ($50 toward any service, or $50 gift card for a test drive at a store whose profile has no service hours), which preflight asks you to confirm with the dealer (`default_claim_check`). Copy may use recipient merge fields with a fallback after `|`:

```bash
curl -s -H "$H" -H 'content-type: application/json' $API/v1/campaigns/$C/creative -d '{
  "template_code": "postcard_6x9_birthday",
  "copy": {
    "note": "Happy birthday from all of us at {{dealer.name}}! Thank you for trusting us with your {{recipient.vehicle|vehicle}}.\n\nYour gift is on the other side. Stop by any time this month and we will take care of it for you.",
    "gift_offer": "$50 toward any service",
    "expires": "12/31/2026"
  }
}' | jq
```

Response (201), trimmed:

```json
{
  "creative": {
    "id": "794ead57-ad24-4af6-8955-7909c2267ce4",
    "version": 1,
    "kind": "template",
    "template_code": "postcard_6x9_birthday",
    "template_version": 4,
    "copy_slots": ["gift_offer", "offer_disclosure", "handwriting", "signer_name", "signer_title", "cta_phone", "note", "expires"],
    "preflight": {
      "ok": true,
      "checked_at": "2026-11-02T15:00:00.000Z",
      "audience_version": 1,
      "issues": []
    }
  },
  "campaign_status": "draft",
  "profile_slots": ["signer_name", "signer_title", "cta_phone"],
  "next_step": "Render the proof: render_proof (POST /v1/campaigns/{id}/proof)."
}
```

`profile_slots` names the store details (phone, hours, web address, QR link, signer) that the creative prints from the dealer's profile because the copy left them out. Here they come from the sample dealer: its phone, and its contact Alex Rivera, General Manager, as the signer. Leave them out for your own dealers too: copy that repeats Demo Motors' details for another dealer gets `sample_store_value`, a warning in the sandbox and an error on a live order. `copy_slots` also lists the slots the template filled with its default text (here the gift's terms, `offer_disclosure`, and the handwriting face, `handwriting`). The note names each recipient's own vehicle where the file has one, and says "vehicle" where it has none (`{{recipient.vehicle|vehicle}}`). The sandbox dealer lists Ford and Lincoln as its franchise makes, so their logos print wherever a creative places `{{dealer.make_logos}}`; a real dealer's profile names its own `makes` ([Dealers](dealers.md)).

Try a `gift_offer` longer than 32 characters once, such as "A free oil change and tire rotation". The creative is still stored, but preflight reports an error with a fix:

```json
{
  "code": "slot_too_long",
  "severity": "error",
  "message": "copy.gift_offer is 35 characters; the template allows 32.",
  "fix": "Shorten copy.gift_offer to 32 characters or fewer (cut 3).",
  "field": "copy.gift_offer"
}
```

The response's `next_step` names the first error's field and its fix. Send a corrected creative; each call makes a new version.

If your copy quotes a payment, a rate, a term or a down payment, preflight also requires the full terms in `offer_disclosure`. These are pattern checks, not legal review; see [Compliance checks](creative.md#compliance-checks).

Have a designer's print-ready art instead? Send `{"artwork": {"url": "https://..."}}` in place of `template_code` and `copy` for a PDF with one page per printed side at the product's file size (9.25 x 6.25 in for this postcard), or `{"artwork": {"front": {"url": "..."}, "back": {"url": "..."}}}` for one PNG or JPEG per side (2775 x 1875 px or more for this postcard), and Xcel prints the address block over it. To check the art before you create a campaign, `POST /v1/artwork/preview` with `{"product_code": "postcard_6x9", "artwork": {...}}` (MCP: `preview_artwork`) returns its preflight, a review proof and an `artwork_id` that `generate_creative` takes. The rest of the flow is the same, but the copy checks cannot read art ([Print-ready artwork](creative.md#print-ready-artwork)).

## 5. Render the proof and check readiness

```bash
curl -s -H "$H" -X POST $API/v1/campaigns/$C/proof | jq
curl -s -H "$H" $API/v1/campaigns/$C/validate | jq
```

The proof response (200) describes the pages but does not include them, because they show customer records. On the hosted service, the proof is also printed to PDF:

```json
{
  "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
  "status": "proof_ready",
  "creative_version": 1,
  "audience_version": 1,
  "renderer": {
    "name": "chromium_pdf",
    "format": "pdf",
    "pdf_available": true,
    "message": "PDF proofs are ready at trim size plus bleed: a review proof with guides for the approver and a print-ready PDF for the printer. They show customer records, so the API never returns them; the approver opens the PDF from the review page and Xcel ops from the dashboard."
  },
  "pages": [
    { "label": "Sample 1", "source_row": 2 },
    { "label": "Sample 2", "source_row": 3 },
    { "label": "Sample 3", "source_row": 4 },
    { "label": "Worst case (longest name/address)", "source_row": 3 }
  ],
  "warnings": [],
  "preview": "The proof shows customer records, so it is not returned through the API. The approver sees it on the review page that request_approval creates; Xcel ops see it in the ops dashboard.",
  "next_step": "Get a quote (get_quote), then request_approval with the quote_id and a max_spend_cents ceiling."
}
```

`renderer.name` says what drew the proof. Without a browser it is `html_preview`, with `"format": "html"` and `"pdf_available": false`; the rest of the flow is the same. See [PDF proofs](creative.md#pdf-proofs).

`validate` returns a checklist (`audience`, `creative`, `preflight`, and `quantity`, `mail_date`, `dealer_profile`, `spend_cap`, `dealer_facts` and `proof_disclosures` when they apply; on a live order also `approver`, `live_ordering` and `disclosures`, with `live_gaps` saying who acts next) plus the full preflight result and the dealer's spend cap (`dealer_spend_cap_cents` and `dealer_spend_remaining_cents`, both `null` for the sample dealer, which has no cap). It changes nothing.

## 6. Get a quote

```bash
QUOTE=$(curl -s -H "$H" -X POST $API/v1/campaigns/$C/quote)
echo "$QUOTE" | jq
Q=$(echo "$QUOTE" | jq -r .quote.id)
TOTAL=$(echo "$QUOTE" | jq .quote.total_cents)
```

Response (201):

```json
{
  "quote": {
    "id": "0e0f8f4d-902c-40d1-ac8e-c47e14cb0758",
    "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
    "creative_version": 1,
    "audience_version": 1,
    "quantity": 4,
    "mail_class": "first_class",
    "pooled_weekly": false,
    "unit_price_cents": 95,
    "total_cents": 380,
    "line_items": [
      { "code": "print_and_lettershop", "description": "Print, personalize and prepare 6 x 9 postcard", "quantity": 4, "unit_price_cents": 46, "total_cents": 184 },
      { "code": "postage", "description": "First-Class Mail postage", "quantity": 4, "unit_price_cents": 49, "total_cents": 196 }
    ],
    "notes": [
      "Standard pricing (up to 4,999 live pieces a month): your live orders mailed 0 pieces last month and 0 pieces this month so far (UTC), across all your dealers.",
      "Quantity is the mailable count before CASS/NCOA. Pieces removed by address processing are not billed."
    ],
    "placeholder_pricing": false,
    "timing": {
      "mail_class": "first_class",
      "earliest_mail_date": "2026-11-04",
      "mailed_by": "2026-11-04",
      "first_scan_by": "2026-11-09",
      "in_home_from": "2026-11-11",
      "in_home_to": "2026-11-13",
      "placeholder_timing": true
    },
    "expires_at": "2026-11-09T15:00:00.000Z",
    "created_at": "2026-11-02T15:00:00.000Z"
  },
  "dealer_spend_cap_cents": null,
  "dealer_spend_remaining_cents": null,
  "next_step": "Call request_approval with this quote_id and the budget a person set as max_spend_cents, at least total_cents. Ask for the figure if you have none: this total alone is not one."
}
```

A postcard mails First-Class only. The price per piece is your volume tier's (the console's [Pricing](/console/pricing) page), and a note names the tier. The sample dealer has no monthly spend cap, so both cap fields are `null`; for a dealer with one, they show the cap and what is left of it this month, and `next_step` says when the total is over it.

## 7. Ask a human to approve

`max_spend_cents` is the ceiling the approver agrees to: the figure the person you work for gave, never your own estimate. It must be at least the quote total. The dealer's monthly spend cap is checked first; an order over it is refused with `dealer_spend_cap_exceeded` before anyone is asked.

```bash
BUDGET=50000  # the most the person you work for said to spend, in cents
APPROVAL=$(curl -s -H "$H" -H 'content-type: application/json' $API/v1/campaigns/$C/approval \
  -d "{\"quote_id\":\"$Q\",\"max_spend_cents\":$BUDGET,\"approver_email\":\"you@example.com\"}")
echo "$APPROVAL" | jq
A=$(echo "$APPROVAL" | jq -r .approval_id)
```

Sandbox response (201):

```json
{
  "approval_id": "31d6383b-4c48-425a-accf-73cf8a69719c",
  "status": "pending",
  "approver_email": "y***@example.com",
  "total_cents": 380,
  "expires_at": "2026-11-09T15:00:00.000Z",
  "review_url": "https://api.updash.com/review/Jf3k...",
  "sandbox_only": true,
  "next_step": "Sandbox: open review_url and decide as the developer testing the integration. In live mode the link is emailed to the dealer's registered approver and never returned."
}
```

Open `review_url` in a browser. The page shows the dealer, product, quantity, line items, total, the approved maximum and the proof (three sample rows and the worst case), shown as the PDF review proof (the exact file that prints, with the guides drawn on top) and a **Download the proof (PDF)** link when the proof was printed to PDF. Tick the confirmation box, give your email if the page asks for it (it does when `request_approval` named no `approver_email`), and choose **Approve order**.

In a script or CI job, decide without the browser: `curl -s -H "$H" -H 'content-type: application/json' $API/v1/test/campaigns/$C/approval -d '{"approval_id":"...","decision":"approve"}'`. It makes every check the page makes, and only a sandbox key can call it. The Node and Python scripts use it when you set `XM_SANDBOX_APPROVE=1`.

With a live key the response has no `review_url`. Xcel emails the link to one of the dealer's registered approvers instead. See [Quotes and approvals](quotes-and-approvals.md#the-approval-flow).

Poll until the approval is decided:

```bash
curl -s -H "$H" $API/v1/campaigns/$C | jq '{status: .campaign.status, approval: .latest_approval.status, next_step}'
```

```json
{ "status": "approved", "approval": "approved", "next_step": "Submit: submit_campaign with the approval_id and an idempotency_key (POST /v1/campaigns/{id}/submit, with the key as the Idempotency-Key header)." }
```

## 8. Submit

Generate one `Idempotency-Key` per order and keep it. Reuse it only to retry the same request.

```bash
IDEM=$(uuidgen)
curl -s -i -H "$H" -H 'content-type: application/json' -H "Idempotency-Key: $IDEM" \
  $API/v1/campaigns/$C/submit -d "{\"approval_id\":\"$A\"}"
```

Response (201):

```json
{
  "submission_id": "b48acca5-6870-4d04-8c7c-4bbed2ef7c56",
  "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
  "approval_id": "31d6383b-4c48-425a-accf-73cf8a69719c",
  "mode": "test",
  "status": "submitted",
  "quantity": 4,
  "mail_class": "first_class",
  "total_cents": 380,
  "placeholder_pricing": false,
  "submitted_at": "2026-11-02T15:00:00.000Z",
  "timing": {
    "mail_class": "first_class",
    "earliest_mail_date": "2026-11-04",
    "mailed_by": "2026-11-04",
    "first_scan_by": "2026-11-09",
    "in_home_from": "2026-11-11",
    "in_home_to": "2026-11-13",
    "placeholder_timing": true
  },
  "in_ops_queue": false,
  "message": "Sandbox order recorded. Nothing will print and no ops work was created. advance_test_campaign (MCP) or POST /v1/test/campaigns/{id}/advance simulates production."
}
```

Run the same command again. You get the same body and status, plus the header `idempotent-replayed: true`. Nothing is submitted twice.

Try submitting before the approval is decided, or after you send a new creative: the submit is refused with a code such as `approval_pending` or `approval_stale_creative`. See the [refusal table](quotes-and-approvals.md#submit-refusals).

## 9. Simulate production

Each call moves a submitted sandbox campaign one step along the pipeline. Five calls take it to `completed`. From `in_postal_network` on, each call also simulates results (`results_simulated: true`): the totals from `in_postal_network`, the first responders per lead from `delivery_estimated`, and matched sales and repair orders at `completed`:

```bash
for i in 1 2 3 4 5; do
  curl -s -H "$H" -X POST $API/v1/test/campaigns/$C/advance | jq -c '{from, status, status_evidence, results_simulated}'
done
```

```json
{"from":"submitted","status":"in_production","status_evidence":null,"results_simulated":false}
{"from":"in_production","status":"at_usps","status_evidence":"usps_processing_scan","results_simulated":false}
{"from":"at_usps","status":"in_postal_network","status_evidence":"usps_processing_scan","results_simulated":true}
{"from":"in_postal_network","status":"delivery_estimated","status_evidence":"usps_processing_scan","results_simulated":true}
{"from":"delivery_estimated","status":"completed","status_evidence":"usps_processing_scan","results_simulated":true}
```

To jump straight to a status, send a body such as `-H 'content-type: application/json' -d '{"to":"delivery_estimated"}'`. Only later statuses are allowed. This endpoint exists for sandbox keys only. MCP: `advance_test_campaign`.

## 10. Read the results

```bash
curl -s -H "$H" $API/v1/campaigns/$C/results | jq
```

```json
{
  "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
  "status": "completed",
  "status_label": "Completed",
  "quantities": { "submitted_rows": 7, "mailable": 4, "rejected_rows": 3, "ordered": 4 },
  "submitted_at": "2026-11-02T15:00:00.000Z",
  "timeline": [
    { "at": "2026-11-02T15:00:00.000Z", "status": "proof_ready", "label": "Proof ready", "evidence": null },
    { "at": "2026-11-02T15:00:00.000Z", "status": "awaiting_approval", "label": "Awaiting approval", "evidence": null },
    { "at": "2026-11-02T15:00:00.000Z", "status": "approved", "label": "Approved", "evidence": null },
    { "at": "2026-11-02T15:00:00.000Z", "status": "submitted", "label": "Submitted", "evidence": null },
    { "at": "2026-11-02T15:00:00.000Z", "status": "in_production", "label": "In production", "evidence": null },
    { "at": "2026-11-02T15:00:00.000Z", "status": "at_usps", "label": "Accepted at USPS (processing scan)", "evidence": "usps_processing_scan" }
  ],
  "evidence_note": "USPS processing scans show mail moving through postal facilities. They are not proof of delivery to a mailbox.",
  "results": {
    "source": "sandbox",
    "simulated": true,
    "job": "SBX-20B6B4D9",
    "drops": [{ "drop_number": 1, "home_date": "2026-11-02", "project_status": "Completed", "quantity": 4 }],
    "delivery_percent": 98.1,
    "responses": {
      "leads": 2, "sms": 0, "web": 1, "calls": 0, "appointments": 2, "showroom_visits": 0,
      "facebook": 0, "qr_codes": 1, "total": 4, "unique_responders": 2
    },
    "matched": { "sales": 1, "repair_orders": 0 },
    "leads_with_results": 2,
    "updated_at": "2026-11-02T15:00:00.000Z"
  },
  "results_note": "Simulated sandbox results: realistic shape, invented values. Sandbox time runs as fast as you advance: the order mails, lands and gets its responses when you advance it, so simulated dates follow the timeline, not the quoted dates. Live results come from Xcel's tracking (UpDash).",
  "leads": {
    "items": [
      {
        "external_id": "crm-1001",
        "row_key": "xmdr6kslk45b2rkegz",
        "responses": [
          { "type": 2, "type_label": "web", "at": "2026-11-02T14:00:00.000Z" },
          { "type": 4, "type_label": "appointment", "at": "2026-11-02T15:00:00.000Z" }
        ],
        "matches": [{ "kind": "sale", "date": "2026-11-02", "vehicle_type": "Used", "gross_cents": 285000, "revenue_cents": 4125000 }],
        "updated_at": "2026-11-02T15:00:00.000Z"
      },
      {
        "external_id": "crm-1002",
        "row_key": "xmpksflhfx7fhctpdw",
        "responses": [
          { "type": 7, "type_label": "qr_code", "at": "2026-11-02T13:00:00.000Z" },
          { "type": 4, "type_label": "appointment", "at": "2026-11-02T14:00:00.000Z" }
        ],
        "matches": [],
        "updated_at": "2026-11-02T15:00:00.000Z"
      }
    ],
    "next_after": null,
    "limit": 100
  }
}
```

The timeline above is trimmed after `at_usps`. The sandbox values are invented; the shape is what a live order returns once Xcel links it to UpDash. `results` holds the totals and `leads` one page of per-lead results, keyed by your `external_id`, never a name or address. `gross_cents` and `revenue_cents` are integer cents, like every amount in the API. For the next page, pass `?leads_after=<next_after>`; `leads_limit` sets the page size (1 to 500, default 100). See [Results and attribution](concepts.md#results-and-attribution).

## Next steps

- Register a webhook before you create the next campaign, to receive each event as a signed POST: [Webhooks](webhooks.md). An endpoint receives only events that happen after it is registered.
- Run the same flow from an agent: [MCP server](mcp.md).
- Follow this order, its proof and its leads in the [partner console](console.md) at `/console`. Switch it to test mode to see sandbox orders.
- Read the rules behind each step: [Concepts](concepts.md).

## Next: going live

Ready to order real mail? [Going live](going-live.md) lists what you do, what Xcel does, in what order, and how to ask.
