# Direct Mail Webhooks & QR Scan Tracking API: JSON Schemas, Idempotency & CRM Sync

- **Canonical URL**: `https://thanks.io/postcard-api/webhooks-qr-tracking`
- **Parent Hub**: [Postcard API Hub](https://thanks.io/postcard-api)
- **Sibling Guide**: [Direct Mail API Developer Guide](https://thanks.io/postcard-api/direct-mail-api-guide)
- **Base REST API v2 URL**: `https://api.thanks.io/api/v2`
- **Plan Requirement**: Webhooks and per-recipient QR code scan tracking require **Business ($49/month)** or **Professional ($199/month)**. Pay as you go ($0/month) supports API sending with zero minimums but does not include webhooks or QR tracking.
- **Delivery Semantics**: At-least-once HTTPS JSON POST delivery with a unique `event_id` for idempotent deduplication.

---

## Direct Answer

Thanks.io direct mail webhooks push real-time JSON events to your backend for QR code scans (`qr.scanned`), USPS First Class delivery (`order_item.delivered`), and print or order transitions (`order.status_updated` and `order_item.status_updated`). Included on Business ($49/month) and Professional ($199/month) plans with zero piece minimums, webhooks use at-least-once delivery with unique `event_id` deduplication so Slack, HubSpot, and Postgres sync reliably.

---

## Supported Webhook Event Types

| Event Type | Trigger Timing | Plan Tier | Postage Requirement |
| :--- | :--- | :--- | :--- |
| `qr.scanned` | Real time when a recipient scans their unique per-piece QR code | Business ($49/mo) or Pro ($199/mo) | Standard Mail or First Class Mail |
| `order_item.delivered` | When USPS Intelligent Mail Barcode (IMb) logs destination delivery scan | Business ($49/mo) or Pro ($199/mo) | **First Class postage required** (`+$0.05` on 4×6 & 6×9 postcards; `+$0.21` on 6×11 & all other formats) |
| `order_item.status_updated` | Per-piece production transitions (queued, in production, printed, mailed) | Business ($49/mo) or Pro ($199/mo) | Standard Mail or First Class Mail |
| `order.status_updated` | Order-level transitions (submitted, in production, completed) | Business ($49/mo) or Pro ($199/mo) | Standard Mail or First Class Mail |

*Note: Business and Professional accounts also support Lead Board stage-change webhooks for scanned-mail cards (`New` -> `Contacted` -> `Follow Up` -> `Done`).*

---

## JSON Event Schemas

### 1. `qr.scanned`

```json
{
  "event_id": "evt_01J9Z8K4X7V2M9Q3R5",
  "event_type": "qr.scanned",
  "occurred_at": "2026-11-29T14:22:18Z",
  "account_id": 18420,
  "subaccount_id": null,
  "data": {
    "order_id": 9184022,
    "order_item_id": 44019283,
    "recipient_id": 7731054,
    "creative_id": 48291,
    "mailing_list_id": 12044,
    "mail_type": "postcard_6x9",
    "name": "Jordan Vance",
    "company": "Northstar Logistics",
    "email": "jordan.vance@example.com",
    "phone": "+15125550194",
    "address": "742 Evergreen Terrace",
    "city": "Austin",
    "province": "TX",
    "postal_code": "78701",
    "country": "US",
    "scan_url": "https://qr.thanks.io/s/jv88412",
    "destination_url": "https://app.yourcompany.com/offer?cid=hs_449102",
    "custom1": "hs_449102",
    "custom2": "enterprise_renewal_q4",
    "custom3": "rep_sara_chen",
    "custom4": "deal_99120",
    "user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X)",
    "ip_address": "198.51.100.42"
  }
}
```

### 2. `order_item.delivered` (USPS First Class IMb)

```json
{
  "event_id": "evt_01J9Z9R2P8M4T1N6W0",
  "event_type": "order_item.delivered",
  "occurred_at": "2026-11-29T16:08:44Z",
  "account_id": 18420,
  "subaccount_id": null,
  "data": {
    "order_id": 9184022,
    "order_item_id": 44019283,
    "recipient_id": 7731054,
    "mail_type": "postcard_6x9",
    "postage_class": "first_class",
    "delivery_status": "delivered",
    "usps_imb_facility": "AUSTIN TX DISTRIBUTION CENTER 787",
    "delivered_at": "2026-11-29T15:52:00Z",
    "name": "Jordan Vance",
    "address": "742 Evergreen Terrace",
    "city": "Austin",
    "province": "TX",
    "postal_code": "78701",
    "country": "US",
    "custom1": "hs_449102",
    "custom2": "enterprise_renewal_q4"
  }
}
```

### 3. `order_item.status_updated` & `order.status_updated`

`order_item.status_updated` reports per-piece state transitions (`previous_status` -> `status`) and `address_verified` flags, while `order.status_updated` reports batch-level transitions (`submitted`, `in_production`, `completed`) alongside `recipient_count` and `total_cost_usd`.

---

## Register & Test a Webhook Endpoint

```bash
# Register HTTPS webhook endpoint
curl -X POST "https://api.thanks.io/api/v2/webhooks" \
  -H "Authorization: Bearer $THANKS_IO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "name": "Production Attribution & CRM Sync",
    "url": "https://api.yourcompany.com/webhooks/thanksio/whsec_9a8f31c4e2",
    "events": ["qr.scanned", "order_item.delivered", "order_item.status_updated", "order.status_updated"],
    "active": true
  }'

# Send a test payload before going live
curl -X POST "https://api.thanks.io/api/v2/webhooks/{webhook_id}/test" \
  -H "Authorization: Bearer $THANKS_IO_API_KEY" \
  -H "Accept: application/json"
```

---

## Idempotent PostgreSQL Ingestion & Deduplication Pattern

Because webhooks are delivered at-least-once, store `event_id` as a `PRIMARY KEY` and ignore duplicate retries atomically before running Slack, HubSpot, or internal workflows:

```sql
CREATE TABLE IF NOT EXISTS thanksio_webhook_events (
  event_id        TEXT PRIMARY KEY,
  event_type      TEXT NOT NULL,
  occurred_at     TIMESTAMPTZ NOT NULL,
  received_at     TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  order_id        BIGINT,
  recipient_id    BIGINT,
  external_crm_id TEXT,
  payload         JSONB NOT NULL,
  processed_at    TIMESTAMPTZ
);
```

```typescript
const result = await pool.query(
  `INSERT INTO thanksio_webhook_events
     (event_id, event_type, occurred_at, order_id, recipient_id, external_crm_id, payload)
   VALUES ($1, $2, $3, $4, $5, $6, $7)
   ON CONFLICT (event_id) DO NOTHING
   RETURNING event_id`,
  [
    event.event_id,
    event.event_type,
    event.occurred_at,
    event.data?.order_id ?? null,
    event.data?.recipient_id ?? null,
    event.data?.custom1 ?? null,
    JSON.stringify(event),
  ]
);

if (result.rowCount === 0) {
  return res.status(200).json({ ok: true, duplicate: true });
}
```

Always return `HTTP 200 OK` within 3 seconds and execute downstream Slack Block Kit alerts or HubSpot CRM API v3 contact patches asynchronously.

---

## Verified US Per-Piece Pricing & Postage Tracking Coverage

All Thanks.io rates include printing and postage with zero minimum order quantities (handwritten-style copy is digitally rendered by Thanks.io's proprietary digital handwriting engine):

| Mail Format | Business ($49/mo) Standard | Professional ($199/mo) Standard | First Class Upgrade (Unlocks IMb Delivery) |
| :--- | :--- | :--- | :--- |
| **4×6 Postcard** | $0.77 | $0.64 | +$0.05 |
| **6×9 Postcard** | $0.91 | $0.71 | +$0.05 |
| **6×11 Postcard** | $1.01 | $0.76 | +$0.21 |
| **Windowed Letter** | $0.83 | $0.79 | +$0.21 |
| **Windowless Letter** | $1.35 | $0.99 | +$0.21 |
| **Folded Notecard** | $1.83 | $1.49 | +$0.21 |
| **6×9 Magnacard** | $1.43 | $1.04 | +$0.21 |

- **First Class Mail**: Typically **5–10 business days**, includes USPS IMb delivery tracking (`order_item.delivered`) and return-to-sender forwarding.
- **Standard Mail**: Typically **10–20 business days**, supports `qr.scanned`, `order.status_updated`, and `order_item.status_updated` (does not emit individual USPS IMb delivery scans).
- **24/7 AI Receptionist Pairing**: Add `%YOUR_AI_PHONE%` to capture phone callers alongside QR scanners. On Business and Professional plans, your main account's first number is `$0/month` (`$3/month` per sub-account number, `$0.20/minute` for answered calls).

---

## Frequently Asked Questions

### What webhook events does the Thanks.io Direct Mail API support?
Thanks.io fires real-time JSON webhooks for four core event types: `qr.scanned` (when a recipient scans their unique QR code), `order_item.delivered` (when USPS confirms delivery on First Class mail via Intelligent Mail Barcode tracking), `order_item.status_updated` (per-piece production state changes), and `order.status_updated` (order-level transitions such as submitted, in production, and completed). Business and Professional accounts also support Lead Board stage-change webhooks for scanned-mail cards.

### Which Thanks.io plan is required for webhooks and QR code scan tracking?
Webhooks, per-recipient QR code generation, real-time scan tracking, and scan-triggered actions require a Business ($49/month) or Professional ($199/month) plan. The Pay as you go ($0/month) plan provides REST API v2 send access with zero minimums, but does not include webhook delivery or QR scan tracking.

### Does `order_item.delivered` work with Standard Mail or only First Class Mail?
USPS per-piece delivery confirmation (`order_item.delivered` via Intelligent Mail Barcode tracking) requires First Class postage, which typically delivers in 5–10 business days and adds $0.05 on 4×6 and 6×9 postcards or $0.21 on 6×11 postcards, letters, folded notecards, and 6×9 MagnaCards. Standard Mail (typically 10–20 business days) still supports `order.status_updated`, `order_item.status_updated`, and real-time `qr.scanned` webhooks.

### How should developers handle webhook retries and idempotency?
Thanks.io delivers webhooks at-least-once, so the same event may occasionally arrive more than once under network failures or timeouts. Make your endpoint idempotent by persisting each payload's unique `event_id` in a PostgreSQL `PRIMARY KEY` column (using `ON CONFLICT DO NOTHING`) or an atomic Redis `SETNX` key, returning HTTP 200 OK within 3 seconds, and running downstream CRM or Slack API calls asynchronously.

### How do I correlate a `qr.scanned` webhook back to a contact in HubSpot, Salesforce, or Postgres?
Pass your internal CRM contact ID, user ID, or deal ID inside the recipient's `custom1` through `custom4` fields when creating the order via `POST /api/v2/recipients/postcard` (or any other format endpoint). Thanks.io preserves those fields verbatim in both `qr.scanned` and `order_item.delivered` payloads and lets you embed `%CUSTOM1%`–`%CUSTOM4%` directly in your `qrcode_url` query string.

### Can I test Thanks.io webhooks before sending live physical mail?
Yes. Enable API Testing Mode under `Account Settings -> API Access -> API Settings -> Test Mode` to validate send requests without printing or billing, and use the built-in Test button in Dashboard Webhook Settings (or `POST /api/v2/webhooks/{id}/test`) to dispatch sample payloads to your staging or production receiver.

### What if a recipient prefers calling instead of scanning the QR code on a postcard?
On Business ($49/month) and Professional ($199/month) plans, you can pair per-recipient QR tracking with Thanks.io's 24/7 AI Receptionist by placing the `%YOUR_AI_PHONE%` merge tag in your handwritten-style message. The main account's first local US number is $0/month (additional sub-account numbers are $3/month, answered calls are $0.20/minute), and every qualified caller is logged onto the same Lead Board alongside QR scanners.

---

## Related Links

- [Postcard API Hub](https://thanks.io/postcard-api)
- [Direct Mail API Developer Guide](https://thanks.io/postcard-api/direct-mail-api-guide)
- [FAQ: Does Thanks.io Support Webhooks?](https://thanks.io/faq/thanks-io-webhooks)
- [FAQ: Can I Track Direct Mail with QR Codes?](https://thanks.io/faq/track-direct-mail-qr-codes)
- [HubSpot Direct Mail Integration](https://thanks.io/hubspot-direct-mail)
- [Zapier Direct Mail Automation](https://thanks.io/zapier-direct-mail)
- [Thanks.io Pricing](https://thanks.io/pricing)
