Shopify webhooks: big orders, fraud, chargebacks and refunds as signals
Send a Shopify store's webhooks to Pulso and turn large orders, orders cancelled as fraud, chargebacks and refunds into signals, and know when orders stop coming in.
Shopify sends a webhook for each order, refund and chargeback in a store. Sent to Pulso, the ones that need a decision become signals: an order large enough to check before it ships, an order cancelled as fraud, a chargeback with a deadline.
Connect Shopify#
Add Shopify to Pulso to create a webhook source called Shopify; it shows these steps with the source’s URL and takes its signing secret, then creates the monitors below that you pick, with their playbooks and a report. To start from scratch instead, create a webhook data source called Shopify.
Shopify names the topic, such as orders/create, only in the X-Shopify-Topic header, and an order looks the same whether it was just created or just cancelled. Pulso keeps the header as the http_headers.x_shopify_topic column, so one webhook source can take every topic of a store, and each monitor picks its topic with a filter.
- In the Shopify admin, go to Settings > Notifications > Webhooks and click Create webhook.
- Pick the event, set Format to JSON and paste the source’s Endpoint URL,
https://hooks.pulso.run/webhooks/<id>/<token>. An XML delivery arrives in Pulso as an empty event. - Pick the latest Webhook API version and save. Repeat for each event, with the same URL.
- Below the list of webhooks, Shopify shows the key they’re signed with. Paste it as the source’s signing secret: below these steps in Add to Pulso, or from scratch in its signature settings with the Shopify scheme. An app’s subscriptions are signed with the app’s client secret instead.
- Send a test notification from the webhook’s row and check the source’s Recent events.
An app subscribes in shopify.app.toml or with the GraphQL Admin API’s webhookSubscriptionCreate, with the source’s URL as the uri:
[[webhooks.subscriptions]]
topics = ["orders/create", "orders/cancelled", "refunds/create", "disputes/create"]
uri = "https://hooks.pulso.run/webhooks/<id>/<token>"
What arrives#
This is Shopify’s sample payload for orders/create, trimmed:
{
"id": 820982911946154508,
"name": "#9999",
"order_number": 1234,
"email": "jon@example.com",
"created_at": "2021-12-31T19:00:00-05:00",
"currency": "USD",
"total_price": "404.95",
"total_price_set": {
"shop_money": { "amount": "404.95", "currency_code": "USD" },
"presentment_money": { "amount": "404.95", "currency_code": "USD" }
},
"financial_status": "voided",
"fulfillment_status": null,
"cancel_reason": "customer",
"cancelled_at": "2021-12-31T19:00:00-05:00",
"test": true,
"tags": "tag1, tag2",
"source_name": "web",
"payment_gateway_names": ["visa", "bogus"],
"discount_codes": [],
"customer": {
"id": 115310627314723954,
"email": "john@example.com"
},
"line_items": [
{ "id": 487817672276298554, "title": "Aviator sunglasses", "quantity": 1, "price": "89.99" }
]
}
Its monitors see these columns:
| Column | Value |
|---|---|
id |
820982911946154508 |
name |
#9999 |
email |
jon@example.com |
total_price |
404.95, a string a number filter still reads |
total_price_set.shop_money.amount |
404.95 |
total_price_set.shop_money.currency_code |
USD |
financial_status |
voided |
fulfillment_status |
null |
cancel_reason |
customer |
test |
true |
tags |
tag1, tag2, one string |
payment_gateway_names |
["visa", "bogus"], the whole list in one column |
customer.id |
115310627314723954 |
customer.email |
john@example.com |
line_items |
the whole list of items in one column |
http_headers.x_shopify_topic |
orders/create |
http_headers.x_shopify_shop_domain |
example.myshopify.com |
http_headers.x_shopify_webhook_id |
the delivery’s id, the same when Shopify sends it again |
Monitors to build#
Large orders to check before shipping#
- Filters:
http_headers.x_shopify_topicequalsorders/create,total_pricegreater than1000,testis false. - Uniq by:
id. - Playbook: a task to check the order, with
{{signal.name}}and{{signal.email}}in its text, and an approval before the warehouse ships it.
Orders cancelled as fraud#
- Filters:
http_headers.x_shopify_topicequalsorders/cancelled,cancel_reasonequalsfraud. - Uniq by:
id. - Playbook: a task to look for other orders from
{{signal.email}}or{{signal.customer.id}}. Add a notification to whoever runs payments.
Chargebacks#
- Filters:
http_headers.x_shopify_topicequalsdisputes/create,typeequalschargeback. The payload is small:id,order_id,type,amount,currency,reason,statusandevidence_due_by. - Uniq by:
id. - Playbook: a task to gather the evidence for order
{{signal.order_id}}before{{signal.evidence_due_by}}, an approval, and a task to submit it.
Refunds to review#
- Filters:
http_headers.x_shopify_topicequalsrefunds/create, and maybenotecontains a word your team uses. - Uniq by:
id. - Playbook: a question, “Was the reason valid?”, with
{{signal.order_id}}and{{signal.note}}, and a task to talk to whoever issued it when it wasn’t. The refunded amount is insidetransactions, a list, so a number filter can’t select large refunds. For orders refunded in full, a monitor onorders/updatedwithfinancial_statusequalsrefundedand uniq byidgives one signal per order.
Heartbeat: orders stop coming in#
On the source, a heartbeat monitor with Frequency custom, 0 9-21 * * *, in the store’s time zone, and a grace period of 15 minutes. If an hour of opening time goes by without an order, it raises a signal: a broken checkout, a payment gateway down or a webhook Shopify removed. Filter on http_headers.x_shopify_topic equals orders/create, and add test is false so test orders don’t count.
Limits#
- Signatures. With the signing key and the Shopify scheme, Pulso checks
X-Shopify-Hmac-Sha256. Shopify signs no timestamp, so a delivery captured on its way could be sent again; the URL’s token still keeps anyone else out. - Several stores. Each store’s deliveries carry its domain in
http_headers.x_shopify_shop_domain: one source can take them all, with a filter on it in each monitor, or give each store its own source. - Duplicates and order. Shopify can deliver the same webhook twice, with the same
http_headers.x_shopify_webhook_id; uniq by the order’s or refund’sidcovers it and also gives one signal per order. Shopify doesn’t guarantee order either: anorders/updatedcan arrive before itsorders/create. - Timeouts and removal. Shopify fails a delivery that takes more than five seconds. For an app’s subscriptions, it retries up to eight times in four hours and then removes the subscription; the heartbeat above is how you notice.
- JSON only. Choose JSON: Pulso doesn’t read XML.
Sources: Shopify’s webhooks overview, delivery structure, troubleshooting webhooks, the webhook topics reference with each topic’s sample payload, and the Order resource.
Add Shopify to Pulso: a webhook source, 5 monitors with their playbooks and a report, then these steps with the source's URL.
- Shopify large orders to check
- Shopify orders cancelled as fraud
- Shopify chargebacks
- Shopify refunds to review
- Shopify orders stop coming in
- Report: Shopify