Overview

The Spree Commerce hub API also allows messages to be pushed to it.

This guide covers how to see which message types can be pushed to the hub and instructions for pushing a message via the API.

Available Messages

To see a list of message types that have been previously processed on hub for a given store, you can run the following request:

GET https://spreeecommerce.com/api/stores/YOUR_STORE_ID/available_messages

The following response is an abbreviated example:

Status: 200 OK
[
  "endpoint:poll",
  "notification:error",
  "notification:info",
  "notification:warn",
  "order:canceled",
  "order:import",
  "order:new",
  "order:persist",
  "order:updated",
  "payment:capture",
  "payment:ready",
  "product:update"
]

Pushing a Message to the Hub

For more information on the structure of messages and to view some sample messages, please view the Sample Messages guide.

Let’s go over pushing a couple different messages to the Spree Commerce hub. First, we’ll push a more basic message, stock:change, and then we’ll push a more complicated messages, order:persist.

stock:change example

Request

To push a stock:change message, make the following request:

POST https://spreeecommerce.com/api/stores/your_store_id/messages

with the following JSON request body:

{
  "message": "stock:change",
  "payload": {
    "sku": "apc-00001",
    "quantity": 10
  }
}

Here is an example request using cURL:

curl -XPOST -H"Content-Type: application/json" 
     -H"X-Augury-Token:YOUR_AUGURY_TOKEN" 
     -d '{"message":"stock:change","payload":{"sku":"APC-00001","quantity":10}' 
     https://spreeecommerce.com/api/stores/YOUR_STORE_ID/messages

Response

Status: 201 Created
{
  "message": "stock:change",
  "payload": {
    "sku": "apc-00001",
    "quantity": 10
  },
  "message_id": "52811a8584a8169f7a000002"
}

order:persist example

Request

To push an order:persist message, make the following request:

POST https://spreeecommerce.com/api/stores/YOUR_STORE_ID/messages

with the following JSON request body:

{
  "message": "order:persist",
  "payload": {
  }
}

To view the details of what should be in an order:persist payload, use the samples API described in the sample messages guide to generate a sample message.

Here is an example request using cURL:

curl -XPOST -H"Content-Type: application/json" 
     -H"X-Augury-Token:YOUR_AUGURY_TOKEN" 
     -d '{"message":"order:persist","payload":{}' 
     https://spreeecommerce.com/api/stores/YOUR_STORE_ID/messages

Response

Status: 201 Created
{
  "message": "order:persist",
  "payload": {
  },
  "message_id": "52811a8584a8169f7a000002"
}
x Spree Conf NYC 2014

Want to learn more about Spree?

Early Bird is 50% Off (Ends 12/31)

Learn More