API Webhook
From Spiffy Stores Knowledge Base
Webhooks are a useful tool for apps that want to execute code after a specific event happens on a store, for example, after a customer creates a cart on the storefront, or a merchant creates a new product in their admin.
Instead of telling your app to make an API call every X number of minutes to check if a specific event has occurred on a shop, you can register webhooks, which send an HTTP request from the store telling your app that the event has occurred. This uses far less API requests overall, allowing you to build more robust apps, and update your app instantly after a webhook is received.
Webhooks are scoped to the app they're registered to. This means that when a webhook is registered to an app, other apps can't view, modify, or delete it.
Anatomy of a Webhook
When an event occurs in a shop that corresponds to a registered webhook, Spiffy Stores sends a webhook notification to the specified URL. The webhook contains a payload formatted as JSON, as well applicable HTTP headers. For example, the following headers are sent as part of the
orders/create
webhook.
- X-Spiffy-Topic: orders/create
- X-Spiffy-Hmac-Sha256: XWmrwMey6OsLMeiZKwP4FppHH3cmAiiJJAweH5Jo4bM=
- X-Spiffy-Shop-Domain: johns-apparel.spiffystores.com
etc.
Some of the returned HTTP headers can be useful for your app. For example, X-Spiffy-Hmac-Sha256 is used to authenticate webhooks, and X-Spiffy-Shop-Domain is useful for determining the store context. See the webhooks tutorial for more information concerning authenticating webhooks, and the OAuth docs for general information concerning authentication.
List of Supported Webhook Topics
Event data can be stored as JSON or XML. Webhooks can be registered for the following events:
Events | Topics |
Cart | carts/create, carts/update { "id": "eeafa272cebfd4b22385bc4b645e762c", "token": "eeafa272cebfd4b22385bc4b645e762c", "line_items": [ { "id": 1234567, "properties": { }, "quantity": 3, "variant_id": 1234567, "key": "1234567:f816dcc3b2e26822a28626a786eac953", "title": "Example T-Shirt - ", "price": "19.99", "original_price": "19.99", "discounted_price": "19.99", "line_price": "59.97", "original_line_price": "59.97", "total_discount": "0.00", "discounts": [ ], "sku": "example-shirt-s", "grams": 200, "vendor": "Acme", "product_id": 327475578523353102, "gift_card": false } ] } |
description | { "description" : "Goods returned from Order #12345" } The description provides reference information on why the credit was issued or redeemed. |
customer | { "customer" : { Returns an object containing information about the customer. Customer objects contain the following fields:
|
order | { "order" : { Order details… } } Returns an object containing information about the order. The customer credit has an associated order only when a credit is being posted against a specific order. |
created_at | { "created_at" : "2015-10-24T18:26:31Z" } The date and time when the customer credit was created. The timestamp is in ISO 8601 format. |
updated_at | { "updated_at" : "2016-01-16T05:50:56Z" } The date and time when the customer credit was last updated. The timestamp is in ISO 8601 format. |