Web Hook

From Spiffy Stores Knowledge Base

Web Hooks are a way to tell Spiffy stores to call a script on one of your own web servers and react to the event in any way you want.

Example Web Hook Post

Here is an example of the format of the data that a Web Hook posts to your application.

POST /your-web-hook-path HTTP/1.1
Accept: */*
Content-Type: application/xml
Content-Length: 2665
X_spiffy_stores_id: 00000000-0000-0000-0000-000000000000

<?xml version="1.0" encoding="UTF-8"?>
<order>
  <buyer-accepts-marketing type="boolean">false</buyer-accepts-marketing>
  <cart-token nil="true"/>
  <closed-at type="datetime" nil="true"></closed-at>
  <created-at type="datetime">2010-06-18T00:00:00+10:00</created-at>
  <currency>AUD</currency>
  <email>spiffy@mystore.spiffystores.com</email>
  <financial-status>paid</financial-status>
  <fulfillment-status>unshipped</fulfillment-status>
  <gateway>Testing Gateway</gateway>
  <id type="integer">0</id>
  <ip>127.0.0.1</ip>
  <note></note>
  <number type="integer">99999</number>
  <shipping-method>Australia Post</shipping-method>
  <shop-id type="integer">0</shop-id>
  <subtotal-price type="decimal">81.82</subtotal-price>
  <taxes-included type="boolean">true</taxes-included>
  <total-discounts type="decimal">10.0</total-discounts>
  <total-line-items-price type="decimal">91.82</total-line-items-price>
  <total-price type="decimal">100.0</total-price>
  <total-shipping type="decimal">50.0</total-shipping>
  <total-tax type="decimal">12.72</total-tax>
  <total-weight type="float">0.2</total-weight>
  <name>#99999</name>
  <billing-address>
    <address1>1 Bill St</address1>
    <address2></address2>
    <city>Billingsworth</city>
    <company></company>
    <country>Australia</country>
    <first-name>Spiffy</first-name>
    <id type="integer"></id>
    <last-name>Customer</last-name>
    <phone></phone>
    <province>New South Wales</province>
    <title>Mr</title>
    <zip>3333</zip>
    <name>Spiffy Customer</name>
  </billing-address>
  <shipping-address>
    <address1>1 Ship St</address1>
    <address2></address2>
    <city>Shipping Town</city>
    <company></company>
    <country>Australia</country>
    <first-name>Spiffy</first-name>
    <id type="integer"></id>
    <last-name>Customer</last-name>
    <phone></phone>
    <province>New South Wales</province>
    <title>Mr</title>
    <zip>2222</zip>
    <name>Spiffy Customer</name>
  </shipping-address>
  <line-items type="array">
    <line-item>
      <fulfillment-service>manual</fulfillment-service>
      <weight type="float">0.1</weight>
      <id type="integer"></id>
      <price type="decimal">25.0</price>
      <quantity type="integer">2</quantity>
      <sku>ITEM001</sku>
      <name>A very wonderful item</name>
    </line-item>
    <line-item>
      <fulfillment-service>manual</fulfillment-service>
      <weight type="float">0.1</weight>
      <id type="integer"></id>
      <price type="decimal">25.0</price>
      <quantity type="integer">2</quantity>
      <sku>ITEM002</sku>
      <name>A Barrel of Monkeys</name>
    </line-item>
  </line-items>
</order>

Adding Security to your Web Hook Application

Spiffy Stores includes a unique Web Hook key in the request header that can be used to validate the request. A unique key is generated for each store.

You can access the key using the request header value 'HTTP_X_SPIFFY_STORES_ID'.

For example, an application written in PHP would validate the key with the following code.

  define('MY_SPIFFY_KEY', '0c1c9920-5c9c-012d-bd34-000c295ec56b');
  
  // Check for a valid Spiffy Store Web Hook Key
  if (strcmp(MY_SPIFFY_KEY, $_SERVER['HTTP_X_SPIFFY_STORES_ID']) != 0) {
    header('HTTP/1.1 403 Forbidden');
    exit(0);
  }

You can find your unique Web Hook key on the Notifications page, just underneath the list of current notifications.