# Webhooks to any CRM

Send try-on leads from the TryOnCloud Shopify app to any URL: HubSpot, Zoho, Mailchimp, Brevo, ActiveCampaign, Salesforce, Zapier, Make, n8n or your own server.

> **Note:** This page is about **lead** webhooks from the Shopify app. For **Developer API** webhooks when an async try-on or batch finishes, see [Async jobs, batches and webhooks](/docs/async#webhooks).

## Connect

1. Open the TryOnCloud app in your Shopify admin.
2. Go to **Leads > Integrations** and click **Connect** on the Webhook row.
3. Paste your `https` endpoint URL and copy the signing secret.

## Event

TryOnCloud sends `POST` with a JSON body when a shopper leaves their email after a try-on:

```json
{
  "event": "lead_captured",
  "shop": "yourstore.myshopify.com",
  "created_at": "2026-11-14T10:30:00.000Z",
  "data": {
    "email": "shopper@example.com",
    "customer_id": null,
    "product_id": "8812345678901",
    "product_title": "Floral Wrap Dress",
    "result_url": "https://www.tryoncloud.com/api/result/...",
    "product_url": "https://yourstore.com/products/floral-wrap-dress",
    "tagged_shopify": true
  }
}
```

## Headers

| Header | Meaning |
|---|---|
| `x-tryoncloud-event` | `lead_captured` |
| `x-tryoncloud-shop` | Your shop domain |
| `x-tryoncloud-delivery-id` | Unique per delivery. Use it to ignore duplicates |
| `x-tryoncloud-timestamp` | Unix seconds when sent |
| `x-tryoncloud-signature-v2` | `sha256=` + HMAC-SHA256 of `<timestamp>.<raw body>` with your secret. Verify this one |
| `x-tryoncloud-signature` | `sha256=` + HMAC-SHA256 of the raw body only. Still sent so existing integrations keep working |

## Verify the signature

Always verify before trusting the data. Use the **raw** request body, not re-serialised JSON. Verify `x-tryoncloud-signature-v2`: it signs the timestamp too, so you can reject deliveries older than 5 minutes and a captured request cannot be replayed later. Each retry is signed again with its own timestamp.

```js
import crypto from "node:crypto"

function verify(rawBody, headers, secret) {
  const ts = headers["x-tryoncloud-timestamp"]
  const sig = headers["x-tryoncloud-signature-v2"]
  if (typeof ts !== "string" || typeof sig !== "string") return false
  if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false // too old: possible replay
  const expected = "sha256=" + crypto.createHmac("sha256", secret).update(`${ts}.${rawBody}`, "utf8").digest("hex")
  const a = Buffer.from(expected)
  const b = Buffer.from(sig)
  return a.length === b.length && crypto.timingSafeEqual(a, b)
}
```

```python
import hmac, hashlib, time

def verify(raw_body: bytes, headers, secret: str) -> bool:
    ts = headers.get("x-tryoncloud-timestamp")
    sig = headers.get("x-tryoncloud-signature-v2")
    if not ts or not sig or not ts.isdigit():
        return False
    if abs(time.time() - int(ts)) > 300:  # too old: possible replay
        return False
    expected = "sha256=" + hmac.new(secret.encode(), ts.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, sig)
```

## Delivery

- Your endpoint must be `https` and should respond `2xx` within 8 seconds.
- Failed deliveries retry after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours.
- Deliveries can arrive more than once. Deduplicate on `x-tryoncloud-delivery-id`.
- Redirects are not followed.
