Direct Mail Webhooks & QR Scan Tracking API: JSON Schemas, Idempotency & CRM Sync
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.
Turn physical postcards, windowed and windowless letters, folded notecards, and 6×9 MagnaCards—rendered with Thanks.io's proprietary digital handwritten-style engine—into an observable event stream your engineering team can route directly into PostgreSQL, Redis, Slack, HubSpot, or Zapier.
qr.scannedReal-TimeRecipient scans their unique per-piece QR code. Works on Standard & First Class mail.
order_item.deliveredFirst Class IMbUSPS Intelligent Mail Barcode destination scan. Requires First Class (+$0.05 / +$0.21).
order_item.status_updatedPer-PieceGranular piece state updates (queued, printed, mailed) across batch orders.
order.status_updatedOrder-LevelBatch transitions (submitted -> in_production -> completed) for ops & billing.
Thanks.io Webhook Event Payloads & Field Schemas
Select any webhook event below to inspect its JSON payload structure, copy a test fixture, and review required fields and postage prerequisites.
{
"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": "[email protected]",
"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"
}
}qr.scannedEmitted the moment a recipient scans the per-recipient QR code printed on a postcard, letter, folded notecard, gift card, or 6×9 MagnaCard. Carries recipient identity, custom merge tags (custom1–custom4), creative ID, and scan metadata so your CRM or Slack channel can react immediately.
| Field | Type | Description |
|---|---|---|
| event_idreq | string | Globally unique delivery identifier. Store this key in Postgres or Redis to deduplicate at-least-once retries. |
| event_typereq | string | Constant string "qr.scanned" for real-time QR code scan events. |
| occurred_atreq | string (ISO-8601) | UTC timestamp when Thanks.io recorded the QR redirect hit. |
| data.order_id / data.order_item_idreq | integer | Parent order ID and individual mailpiece ID for joining back to your send log. |
| data.recipient_idreq | integer | Thanks.io recipient identifier across orders, Global Scan List, and Lead Board cards. |
| data.custom1 – data.custom4 | string | null | Your pass-through foreign keys (CRM contact ID, deal ID, campaign slug, account owner) supplied at send time. |
| data.scan_url / data.destination_urlreq | string (URL) | Per-recipient tracking short URL and resolved landing page URL configured on the creative or API send. |
Idempotent Webhook Consumers & Downstream Sync (Postgres, Slack & HubSpot)
Pick a downstream architecture and switch between Node.js / TypeScript, Python / FastAPI, and SQL or cURL to deploy deduplicated attribution pipelines.
1. Idempotent Webhook Consumer with Postgres Unique Key & Fast 200 ACK
Safely ingest at-least-once Thanks.io webhooks without duplicate CRM writes or double notifications. Persists every raw payload with a UNIQUE constraint on event_id and hands processing off to an async worker.
- Deduplicates retries atomically via Postgres INSERT ... ON CONFLICT (event_id) DO NOTHING
- Returns HTTP 200 OK immediately (< 100ms) so upstream timeouts never trigger cascading retries
- Retains full raw JSONB payloads for replayability and attribution auditing
// Node.js / Express + PostgreSQL (pg) — Atomic Idempotent Webhook Receiver
import express, { Request, Response } from "express";
import { Pool } from "pg";
const app = express();
app.use(express.json({ limit: "1mb" }));
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const WEBHOOK_PATH_TOKEN = process.env.THANKSIO_WEBHOOK_TOKEN!;
interface ThanksIoEvent {
event_id: string;
event_type:
| "qr.scanned"
| "order_item.delivered"
| "order_item.status_updated"
| "order.status_updated";
occurred_at: string;
data: Record<string, unknown>;
}
app.post("/webhooks/thanksio/:token", async (req: Request, res: Response) => {
if (req.params.token !== WEBHOOK_PATH_TOKEN) {
return res.status(401).json({ error: "Invalid webhook token" });
}
const event = req.body as ThanksIoEvent;
if (!event?.event_id || !event?.event_type) {
return res.status(400).json({ error: "Missing event_id or event_type" });
}
try {
// Atomic deduplication: returns 1 row only on first-ever receipt of event_id
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, // Pass-through CRM contact ID
JSON.stringify(event),
]
);
if (result.rowCount === 0) {
// Duplicate retry — acknowledge 200 OK without re-running side effects
return res.status(200).json({ ok: true, duplicate: true });
}
// Enqueue background job (BullMQ / SQS / pg-boss) and ACK immediately
queueMicrotask(() => {
void processAttributionEvent(event).catch((err) =>
console.error("Async webhook worker failed:", event.event_id, err)
);
});
return res.status(200).json({ ok: true, duplicate: false });
} catch (err) {
console.error("Database ingest error:", err);
return res.status(500).json({ error: "Temporary ingest failure" });
}
});
async function processAttributionEvent(event: ThanksIoEvent) {
if (event.event_type === "qr.scanned") {
// Route to Slack, HubSpot, or internal lead scoring
console.log("Processing QR scan for CRM ID:", event.data.custom1);
} else if (event.event_type === "order_item.delivered") {
console.log("Logging USPS delivery for Order Item:", event.data.order_item_id);
}
}Compare Standard vs. First Class IMb Webhook Coverage & Monthly Cost
All Thanks.io rates include printing and postage with zero minimum order quantities. Webhooks and QR tracking unlock on Business ($49/mo) and Professional ($199/mo)—choose your mail format and postage class below to see exact unit economics and event visibility.
Lowest-cost QR-tracked postcard; +$0.05 unlocks First Class USPS IMb delivery webhooks
Pay as you go ($0/mo) supports API sends but does not include QR tracking or webhooks.
Typically 5–10 business days + USPS IMb delivery webhooks & return-to-sender.
qr.scanned— Real-time per-recipient QR scansorder_item.delivered— Active via USPS First Class IMb (typically 5–10 bus. days)order.status_updated&order_item.status_updated
3 Ways to Attach Tracked QR Codes (Plus Call Attribution)
Every recipient receives a unique tracked QR URL so you always know exactly who scanned, which creative drove the hit, and when it happened—without sharing generic static QR codes.
Saved Creative IDs (Decoupled Design & Engineering)
Configure the QR code destination URL (or Thanks.io's default branded landing page) inside a saved Creative in the dashboard. Even a QR code already printed inside uploaded artwork can be converted into a tracked per-recipient QR code.
Inline API Parameter (qrcode_url + Merge Tags)
Pass qrcode_url directly in your send payload with dynamic merge variables such as %CUSTOM1% and %CUSTOM2%. Thanks.io encodes a unique per-recipient tracking URL that records the scan, fires qr.scanned, and redirects cleanly to your destination.
Global Scan List & Lead Board Automation
Every scanned recipient automatically enters the Global Scan List (All QR Scans) and appears as a card on your Lead Board (New -> Contacted -> Follow Up -> Done). Business and Professional accounts can trigger follow-up drips or fire stage-change webhooks.
Capture Callers Alongside QR Scanners with %YOUR_AI_PHONE%
Some recipients prefer dialing a phone number rather than scanning a QR code. On Business and Professional plans, your main account's first 24/7 AI Receptionist number is $0/month ($3/month per sub-account number, $0.20/minute for answered calls) and logs every qualified caller onto the same Lead Board alongside your QR scans.
4 Rules for Bulletproof Direct Mail Webhook Consumers
Verify every item below in staging before pointing live campaign volume at your webhook endpoint.
Deduplicate Every Delivery on event_id
Thanks.io delivers webhooks with at-least-once semantics, meaning network timeouts or transient 5xx responses can cause the same event to be retried. Store event_id as a PRIMARY KEY in Postgres or an atomic Redis SETNX key before running any CRM or Slack side effect.
Return HTTP 200 OK in Under 3 Seconds
Never block the webhook HTTP response while calling slower downstream APIs (HubSpot, Salesforce, Slack, enrichment providers). Validate the request, persist or enqueue the event, return HTTP 200 OK immediately, and process fan-out in an async worker.
Pass Foreign Keys in custom1–custom4 at Send Time
Matching incoming webhooks back to your CRM by street address or display name is error-prone after USPS CASS standardization. Always pass your immutable internal CRM contact ID in custom1 and campaign slug in custom2 so every webhook joins cleanly.
Validate with Test Mode + Built-In Webhook Test Trigger
Enable API Testing Mode under Account Settings -> API Access to verify send payloads without printing or billing, then trigger synthetic webhook payloads from Webhook Settings (or POST /api/v2/webhooks/{id}/test) twice in a row to confirm duplicate suppression works.
Related API Guides, FAQs & CRM Integrations
Explore the rest of the Thanks.io developer documentation, compare legacy direct mail APIs, or wire up no-code webhook workflows.
Postcard API Hub
Overview of Thanks.io REST API v2 endpoints, 300 DPI print specs, per-piece pricing, and the 57-tool OAuth MCP server.
Direct Mail API Developer Guide
End-to-end Node.js, Python, and cURL blueprints for postcards, windowless letters, PDF documents, and neighbor radius blasts.
Does Thanks.io Support Webhooks?
Quick-reference answers on supported event types, at-least-once delivery semantics, and Business/Pro plan requirements.
Can I Track Direct Mail with QR Codes?
How per-recipient QR codes, custom landing URLs, the Global Scan List, and Lead Board cards work across every format.
HubSpot Direct Mail Integration
Trigger postcards, letters, notecards, and pay-on-redemption gift cards from HubSpot Workflows with 2-way contact sync.
Zapier Direct Mail Automation
Route QR scan events and delivery updates into 8,000+ apps without hosting a dedicated webhook listener.
AI Direct Mail Agent & MCP Guide
Connect Claude, Cursor, and autonomous agents to https://mcp.thanks.io/mcp to preview, send, and manage campaigns.
Direct Mail Delivery Time & Cutoffs
Understand same-day print cutoffs (11:00 AM CT), First Class (typically 5–10 business days), and Standard Mail timing.
Thanks.io vs. Lob API Comparison
Compare $0/$49/$199 plans, per-piece postcard rates, digital handwriting, and built-in QR scan webhooks against Lob.
Direct Mail Webhooks & QR Tracking FAQs
Straight answers on supported event types, First Class USPS IMb requirements, retry idempotency, and CRM correlation.
Turn Physical Mail into Real-Time CRM & Slack Events
Create your Thanks.io account, validate send payloads for free in Test Mode, and unlock per-recipient QR tracking plus real-time webhooks on Business ($49/mo) or Professional ($199/mo).