Share
Embed
Backend Integrations & the Spree Commerce Hub
SpreeConf 2014, New York City
Brian Quinn
February 26, 2014
Transcript
307 slides
-
Brian Quinn CTO & Co founder of Spree Commerce, Inc.
Twitter: @briandq Github: BDQ -
A suite of tools to help you monitor and manage
your integrations. -
A peace of mind that everything is happening as it
should. OR WE’LL COME FIND YOU! -
A peace of mind that everything is happening as it
should. OR WE’LL COME FIND YOU! -
A peace of mind that everything is happening as it
should. OR WE’LL COME HELP YOU! -
What problems does it solve? The Acme Widgets Store ➡
Third Party Logistics -
What problems does it solve? The Acme Widgets Store ➡
Third Party Logistics ➡ Accounting Application -
What problems does it solve? The Acme Widgets Store ➡
Third Party Logistics ➡ Accounting Application ➡ Multi-channel Sales -
What problems does it solve? The Acme Widgets Store ➡
Third Party Logistics ➡ Accounting Application ➡ Multi-channel Sales ➡ Customer Service -
What problems does it solve? The Acme Widgets Store ➡
Third Party Logistics ➡ Accounting Application ➡ Multi-channel Sales ➡ Customer Service ➡ Analytics & Marketing -
What problems does it solve? The Acme Widgets Store ➡
Third Party Logistics ➡ Accounting Application ➡ Multi-channel Sales ➡ Customer Service ➡ Analytics & Marketing -
What problems does it solve? The Acme Widgets Store ➡
Third Party Logistics ➡ Accounting Application ➡ Multi-channel Sales ➡ Customer Service ➡ Analytics & Marketing And much more! -
History - Timeline ➡ Version 1 went into production late
2012 ➡ Version 2..4 deployed up to Q1 2013 -
History - Timeline ➡ Version 1 went into production late
2012 ➡ Version 2..4 deployed up to Q1 2013 ➡ Version 5 - SpreeConf DC - May 2013 -
History - Timeline ➡ Version 1 went into production late
2012 ➡ Version 2..4 deployed up to Q1 2013 ➡ Version 5 - SpreeConf DC - May 2013 ➡ called the ‘Integrator’ -
History - Timeline ➡ Version 1 went into production late
2012 ➡ Version 2..4 deployed up to Q1 2013 ➡ Version 5 - SpreeConf DC - May 2013 ➡ called the ‘Integrator’ ➡ Version 6 - SpreeConf NYC - February 2014 -
History - Timeline ➡ Version 1 went into production late
2012 ➡ Version 2..4 deployed up to Q1 2013 ➡ Version 5 - SpreeConf DC - May 2013 ➡ called the ‘Integrator’ ➡ Version 6 - SpreeConf NYC - February 2014 ➡ called the ‘Spree Commerce Hub’ -
History - Integrations ➡ NetSuite ➡ OpenERP ➡ QuickBooks ➡
Quiet Logistics ➡ Shipwire ➡ DotCom ➡ PCH International ➡ Fosdick ➡ VPD ➡ RLM ➡ Simparel ➡ Twilio ➡ Zendesk ➡ Desk ➡ Tender ➡ Mandrill ➡ Exact Target ➡ SMTP -
Three core terms Object ➡ A JSON representation of an
order, product, customer, shipment, return, etc. -
Three core terms Object ➡ A JSON representation of an
order, product, customer, shipment, return, etc. Event ➡ An interesting change to an object. -
Three core terms Object ➡ A JSON representation of an
order, product, customer, shipment, return, etc. Event ➡ An interesting change to an object. Webhook ➡ HTTP POST to predefined URL. -
Common Use Cases ➡ Third Party Logistics ➡ Accounting &
ERP ➡ Multi channel sales ➡ Communications ➡ Customer Service -
Third Party Logistics Use Case: “I want to tell my
3PL when there’s a new shipment to fulfill.” ➡ Object: Shipment ➡ Event: shipment:ready ➡ Webhook: /add_shipment -
Third Party Logistics Use Case: “I want to tell my
3PL when there’s a new shipment to fulfill.” ➡ Object: Shipment ➡ Event: shipment:ready ➡ Webhook: /add_shipment -
Third Party Logistics Use Case: “I want to tell my
3PL when there’s a new shipment to fulfill.” ➡ Object: Shipment ➡ Event: shipment:ready ➡ Webhook: /add_shipment -
Third Party Logistics Use Case: “I want to update my
store when a shipment has dispatched.” ➡ Object: Shipment ➡ Event: schedule ➡ Webhook: /get_shipments -
Third Party Logistics Use Case: “I want to update my
store with my 3PL’s stock levels.” ➡ Object: Inventory ➡ Event: schedule ➡ Webhook: /get_inventory -
Accounting & ERP Use Case: “I want keep my accounts
up to date with all orders my store front.” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /add_order -
Accounting & ERP Use Case: “I want keep my accounts
up to date with all orders my store front.” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /add_order -
Accounting & ERP Use Case: “I want keep my accounts
up to date with all orders my store front.” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /add_order -
Accounting & ERP ➡ Object: Order ➡ Event: order:updated ➡
Webhook: /update_order Use Case: “I want keep my accounts up to date with all orders my store front.” -
Accounting & ERP Use Case: “I need to import Products
from my ERP to my store front.” ➡ Object: Product ➡ Event: schedule ➡ Webhook: /get_products -
Multi Channel Sales Use Case: “I’d like to consolidate &
process all my orders on a single platform.” ➡ Object: Order ➡ Event: schedule ➡ Webhook: /get_orders -
Multi Channel Sales Use Case: “I’d like to consolidate &
process all my orders on a single platform.” ➡ Object: Order ➡ Event: schedule ➡ Webhook: /get_orders -
Use Case: “I want to keep stock levels in-sync across
all my sales channels.” ➡ Object: Inventory ➡ Event: inventory:updated ➡ Webhook: /set_inventory Multi Channel Sales -
Communications Use Case: “I want to send a user an
email after they complete an order” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /send_email -
Communications Use Case: “I want to send a user an
email after they complete an order” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /send_email -
Communications Use Case: “I want to send a user an
email after they complete an order” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /send_email -
Communications Use Case: “I want to send a user an
email after they cancel an order” ➡ Object: Order ➡ Event: order:cancelled ➡ Webhook: /send_email -
Communications Use Case: “I want to send a user an
email after their order ships” ➡ Object: Shipment ➡ Event: shipment:confirm ➡ Webhook: /send_email -
Communications Use Case: “I want to send a user a
SMS after their order ships” ➡ Object: Shipment ➡ Event: shipment:confirm ➡ Webhook: /send_sms -
Customer Service Use Case: “I need to create a support
ticket for high-risk orders” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /create_ticket -
Customer Service Use Case: “I need to create a support
ticket for high-risk orders” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /create_ticket -
Customer Service Use Case: “I need to create a support
ticket for high-risk orders” ➡ Object: Order ➡ Event: order:created ➡ Webhook: /create_ticket -
Use Cases Summary ➡ 5 business areas ➡ 13 use
cases ➡ 15 vendors -
Use Cases Summary ➡ 5 business areas ➡ 13 use
cases ➡ 15 vendors All solved with 3 basic ideas: -
Use Cases Summary ➡ 5 business areas ➡ 13 use
cases ➡ 15 vendors All solved with 3 basic ideas: ➡ Objects -
Use Cases Summary ➡ 5 business areas ➡ 13 use
cases ➡ 15 vendors All solved with 3 basic ideas: ➡ Objects ➡ Events -
Use Cases Summary ➡ 5 business areas ➡ 13 use
cases ➡ 15 vendors All solved with 3 basic ideas: ➡ Objects ➡ Events ➡ Webhooks -
Object Basics ➡ Required Attributes ➡ id - unique identifier
Object ➡ JSON ➡ predefined schemas -
Object Basics ➡ Required Attributes ➡ id - unique identifier
➡ Suggested Attributes ➡ status - objects’ state Object ➡ JSON ➡ predefined schemas -
Order Object ➡ email ➡ currency ➡ totals ➡ line_items
➡ billing_address Order ➡ channel ➡ placed_on ➡ payments ➡ shipments ➡ shipping_address -
Order JSON { "order": { "id": "R154085346", "status": "complete", "channel":
"spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "line_items": [ { "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT", "external_ref": "", Order -
Objects have schemas ➡ Building `The API for commerce` ➡
Public schema for JSON representation of core commerce objects: -
Objects have schemas ➡ Building `The API for commerce` ➡
Public schema for JSON representation of core commerce objects: ➡ orders, products, customers, returns, etc -
Objects have schemas ➡ Building `The API for commerce` ➡
Public schema for JSON representation of core commerce objects: ➡ orders, products, customers, returns, etc -
Objects have schemas ➡ Building `The API for commerce` ➡
Public schema for JSON representation of core commerce objects: ➡ orders, products, customers, returns, etc ➡ Hub Official Format -
Order JSON-Schema Order { "type": "object", "required": ["id", "status", "channel"],
"properties": { "id": { "type": "string" }, "channel": { "type": "string" }, "currency": { "type": "string" }, "placed_on": { "type": "string" }, "status": { "type": "string" }, "totals": { "type": "object", "required": ["item","adjustment", "tax", "shipping", "... "properties": { -
Custom Order - Simple { "order": { "id": "R154085346", "status":
"complete", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "risk_level": "low", "line_items": [ { "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT", Order -
Custom Order - Simple { "order": { "id": "R154085346", "status":
"complete", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "risk_level": "low", "line_items": [ { "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT", Order -
Custom Order - Object { "order": { "id": "R154085346", "status":
"complete", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "risk": { "level": " low", "score": 9 }, "line_items": [ Order -
Custom Order - Object { "order": { "id": "R154085346", "status":
"complete", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "risk": { "level": " low", "score": 9 }, "line_items": [ Order -
Custom Object { "pirate": { "id": "ARRGH1", "status": "angry", "name":
"Captain Blue Beard", "port": "Basse-Terre", "ships": [ { "name": "Blue Bell", "type": "frigate" } ], "parrots": [ { Pirate -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push ➡ Fast - validated asynchronously -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push ➡ Fast - validated asynchronously ➡ Customizable - attributes & objects -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push ➡ Fast - validated asynchronously ➡ Customizable - attributes & objects ➡ Partial updates -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push ➡ Fast - validated asynchronously ➡ Customizable - attributes & objects ➡ Partial updates -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push ➡ Fast - validated asynchronously ➡ Customizable - attributes & objects ➡ Partial updates -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push ➡ Fast - validated asynchronously ➡ Customizable - attributes & objects ➡ Partial updates -
Pushing Objects ➡ Simple Push API ➡ https://push.hubapp.io ➡ Secure
- unique token per push ➡ Fast - validated asynchronously ➡ Customizable - attributes & objects ➡ Partial updates -
Push Example - Single { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "email": "[email protected]", "currency": "USD", ... } ] } POST -
Push Example - Single { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "email": "[email protected]", "currency": "USD", ... } ] } POST { "orders": 1 } Response: 202 -
Push Example - Multiple { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "email": "[email protected]", "currency": "USD" } , { "id": "R154085347", "status": "complete", "channel": "spree", POST -
Push Example - Multiple { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "email": "[email protected]", "currency": "USD" } , { "id": "R154085347", "status": "complete", "channel": "spree", POST { "orders": 2 } Response: 202 -
Push Example - Objects { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "email": "[email protected]", "currency": "USD" } ] "products": [ { "id": "ROR-123", "name": "Ruby on Rails Tote", POST -
Push Example - Objects { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "email": "[email protected]", "currency": "USD" } ] "products": [ { "id": "ROR-123", "name": "Ruby on Rails Tote", POST { "orders": 1, "products": 1 } Response: 202 -
Push Example - Custom Object { "pirates": [ { "id":
"ARRGH1", "status": "angry", "name": "Captain Blue Beard", "email": "[email protected]", "ships": [ { "name": "Blue Bell", "type": "frigate" } ] POST -
Push Example - Custom Object { "pirates": [ { "id":
"ARRGH1", "status": "angry", "name": "Captain Blue Beard", "email": "[email protected]", "ships": [ { "name": "Blue Bell", "type": "frigate" } ] POST { "pirates": 1 } Response: 202 -
Push Example - Partial { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "currency": "USD", ... } ] } Push 1 -
Push Example - Partial { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "currency": "USD", ... } ] } Push 1 { "orders": [ { "id": "R154085346", "status": "cancelled" } ] } Push 2 -
Push Example - Partial { "orders": [ { "id": "R154085346",
"status": "complete", "channel": "spree", "currency": "USD", ... } ] } Push 1 { "orders": [ { "id": "R154085346", "status": "cancelled" } ] } Push 2 { "order": { "id": "R154085346", "status": "cancelled", "channel": "spree", "currency": "USD" ... } } Result -
Authentication ➡ HMAC ➡ json + secret key + timestamp
(UTC) ➡ Each push is only valid for: -
Authentication ➡ HMAC ➡ json + secret key + timestamp
(UTC) ➡ Each push is only valid for: ➡ the exact body you intended -
Authentication ➡ HMAC ➡ json + secret key + timestamp
(UTC) ➡ Each push is only valid for: ➡ the exact body you intended ➡ a small time window -
Authentication STORE_ID = "5180e2507575e48dd0000001" SECRET_KEY = "1234567890" timestamp = Time.now.utc().to_i
json_payload = JSON.generate({ orders: [ { id: 'R1234', status: 'cancelled' } ] }) data = "#{json_payload}@#{timestamp}" SHA1 = OpenSSL::Digest::Digest.new('sha1') hmac = OpenSSL::HMAC.hexdigest(SHA1, SECRET_KEY, data) response = HTTParty.post(‘https://hub.spreecommerce.com/push’, { body: json_payload, headers: { 'X-Hub-Store' => STORE_ID, 'X-Hub-Token' => hmac, 'X-Hub-Timestamp' => timestamp.to_s, 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' } }) -
Authentication STORE_ID = "5180e2507575e48dd0000001" SECRET_KEY = "1234567890" timestamp = Time.now.utc().to_i
json_payload = JSON.generate({ orders: [ { id: 'R1234', status: 'cancelled' } ] }) data = "#{json_payload}@#{timestamp}" SHA1 = OpenSSL::Digest::Digest.new('sha1') hmac = OpenSSL::HMAC.hexdigest(SHA1, SECRET_KEY, data) response = HTTParty.post(‘https://hub.spreecommerce.com/push’, { body: json_payload, headers: { 'X-Hub-Store' => STORE_ID, 'X-Hub-Token' => hmac, 'X-Hub-Timestamp' => timestamp.to_s, 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' } }) -
Authentication STORE_ID = "5180e2507575e48dd0000001" SECRET_KEY = "1234567890" timestamp = Time.now.utc().to_i
json_payload = JSON.generate({ orders: [ { id: 'R1234', status: 'cancelled' } ] }) data = "#{json_payload}@#{timestamp}" SHA1 = OpenSSL::Digest::Digest.new('sha1') hmac = OpenSSL::HMAC.hexdigest(SHA1, SECRET_KEY, data) response = HTTParty.post(‘https://hub.spreecommerce.com/push’, { body: json_payload, headers: { 'X-Hub-Store' => STORE_ID, 'X-Hub-Token' => hmac, 'X-Hub-Timestamp' => timestamp.to_s, 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' } }) -
Authentication STORE_ID = "5180e2507575e48dd0000001" SECRET_KEY = "1234567890" timestamp = Time.now.utc().to_i
json_payload = JSON.generate({ orders: [ { id: 'R1234', status: 'cancelled' } ] }) data = "#{json_payload}@#{timestamp}" SHA1 = OpenSSL::Digest::Digest.new('sha1') hmac = OpenSSL::HMAC.hexdigest(SHA1, SECRET_KEY, data) response = HTTParty.post(‘https://hub.spreecommerce.com/push’, { body: json_payload, headers: { 'X-Hub-Store' => STORE_ID, 'X-Hub-Token' => hmac, 'X-Hub-Timestamp' => timestamp.to_s, 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' } }) -
Authentication STORE_ID = "5180e2507575e48dd0000001" SECRET_KEY = "1234567890" timestamp = Time.now.utc().to_i
json_payload = JSON.generate({ orders: [ { id: 'R1234', status: 'cancelled' } ] }) data = "#{json_payload}@#{timestamp}" SHA1 = OpenSSL::Digest::Digest.new('sha1') hmac = OpenSSL::HMAC.hexdigest(SHA1, SECRET_KEY, data) response = HTTParty.post(‘https://hub.spreecommerce.com/push’, { body: json_payload, headers: { 'X-Hub-Store' => STORE_ID, 'X-Hub-Token' => hmac, 'X-Hub-Timestamp' => timestamp.to_s, 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' } }) -
Push support for Spree ➡ Built-in to Spree 2.3 ➡
A new ‘core’ gem -
Push support for Spree ➡ Built-in to Spree 2.3 ➡
A new ‘core’ gem ➡ Disabled by default, activated via preference. -
Push support for Spree ➡ Built-in to Spree 2.3 ➡
A new ‘core’ gem ➡ Disabled by default, activated via preference. ➡ Will include both Push and Webhooks* -
Push support for Spree ➡ Built-in to Spree 2.3 ➡
A new ‘core’ gem ➡ Disabled by default, activated via preference. ➡ Will include both Push and Webhooks* ➡ Back-porting all the way to 1.3.x -
Events “Tom completed an order for 3 t-shirts” “Tom’s order
has been dispatched” -
Events “Tom completed an order for 3 t-shirts” “Tom’s order
has been dispatched” “A new user called Jane registered” -
Events “Tom completed an order for 3 t-shirts” “Tom’s order
has been dispatched” “A new user called Jane registered” “Jane added a hat to her cart” -
Events “Tom completed an order for 3 t-shirts” “Tom’s order
has been dispatched” “A new user called Jane registered” “Jane added a hat to her cart” “Jane’s cart has be inactive for 5 days” -
Events “Tom completed an order for 3 t-shirts” “Tom’s order
has been dispatched” “A new user called Jane registered” “Jane added a hat to her cart” “Jane’s cart has be inactive for 5 days” “We launched a new Tote product” -
Events “Tom completed an order for 3 t-shirts” “Tom’s order
has been dispatched” “A new user called Jane registered” “Jane added a hat to her cart” “Jane’s cart has be inactive for 5 days” “We launched a new Tote product” “There’s 200 Totes in stock in NYC” -
Events ➡ Created as objects change ➡ Two different ways
they can be generated: -
Events ➡ Created as objects change ➡ Two different ways
they can be generated: ➡ created vs. updated - automatic -
Events ➡ Created as objects change ➡ Two different ways
they can be generated: ➡ created vs. updated - automatic ➡ event builder - custom -
Events ➡ Created as objects change ➡ Two different ways
they can be generated: ➡ created vs. updated - automatic ➡ event builder - custom ➡ Connect objects to webhooks* -
Events: Create Vs. Update ➡ The first time the hub
receives an object: ➡ object:created ➡ order:created, inventory:created, pirate:created -
Events: Create Vs. Update ➡ The first time the hub
receives an object: ➡ object:created ➡ order:created, inventory:created, pirate:created ➡ Each time a real change is received: ➡ object:updated ➡ product:updated, customer:updated -
Events & Webhooks Event Webhook Integration shipment:ready /add_shipment order:created /add_order
shipment:confirm /update_shipment -
Evented Processing ➡ Decouples processing from the store front. ➡
Enables scability. -
Webhooks - Goals ➡ A set of common patterns for
processing events -
Webhooks - Goals ➡ A set of common patterns for
processing events ➡ Well documented -
Webhooks - Goals ➡ A set of common patterns for
processing events ➡ Well documented ➡ Easy to test -
Webhooks - Goals ➡ A set of common patterns for
processing events ➡ Well documented ➡ Easy to test -
Webhooks - Goals ➡ A set of common patterns for
processing events ➡ Well documented ➡ Easy to test ➡ Make integration development even easier -
Webhooks - Objects Standard naming convention for webhooks: ➡ add
- alerts target system of new object -
Webhooks - Objects Standard naming convention for webhooks: ➡ add
- alerts target system of new object ➡ update - sends object changes -
Webhooks - Objects Standard naming convention for webhooks: ➡ add
- alerts target system of new object ➡ update - sends object changes ➡ get - fetch object changes -
Webhooks - Objects ➡ add_order ➡ update_order ➡ get_orders Order
➡ add_product ➡ update_product ➡ get_products Product -
Webhooks - Objects ➡ add_order ➡ update_order ➡ get_orders Order
➡ add_product ➡ update_product ➡ get_products Product ➡ add_customer ➡ update_customer ➡ get_customers Customer -
Webhooks - Objects ➡ add_order ➡ update_order ➡ get_orders Order
➡ add_product ➡ update_product ➡ get_products Product ➡ add_customer ➡ update_customer ➡ get_customers Customer ➡ add_pirate ➡ update_pirate ➡ get_pirates Pirate -
Webhooks - Other ➡ get_inventory ➡ set_inventory Inventory ➡ send_email
➡ send_sms ➡ create_ticket ➡ add_to_list Comms. -
Implementing Webhooks ➡ An application capable of receiving a HTTP
POST request. ➡ Can use any language or framework. -
Implementing Webhooks ➡ An application capable of receiving a HTTP
POST request. ➡ Can use any language or framework. ➡ Can be standalone, or just a route on a larger app. -
Implementing Webhooks ➡ An application capable of receiving a HTTP
POST request. ➡ Can use any language or framework. ➡ Can be standalone, or just a route on a larger app. ➡ Needs to respond with JSON. -
Implementing Webhooks ➡ An application capable of receiving a HTTP
POST request. ➡ Can use any language or framework. ➡ Can be standalone, or just a route on a larger app. ➡ Needs to respond with JSON. ➡ Can be hosted anywhere. -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "summary": "Order imported to Quickbooks", } -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "summary": "Order imported to Quickbooks", } -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "summary": "Order imported to Quickbooks", } -
/update_product Webhook { "request_id": "52f367367575e449c3000001", "product": { "id": 58, "parent_id":
11, "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT-S", "description": "Awesome Spree T-Shirt", "price": 35.0, "cost_price": 22.33, "available_on": "2014-01-29T14:01:28.000Z", "permalink": "spree-tshirt", "meta_description": null, "meta_keywords": null, "shipping_category": "Default", POST -
/update_product Webhook { "request_id": "52f367367575e449c3000001", "product": { "id": 58, "parent_id":
11, "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT-S", "description": "Awesome Spree T-Shirt", "price": 35.0, "cost_price": 22.33, "available_on": "2014-01-29T14:01:28.000Z", "permalink": "spree-tshirt", "meta_description": null, "meta_keywords": null, "shipping_category": "Default", POST -
/update_product Webhook { "request_id": "52f367367575e449c3000001", "product": { "id": 58, "parent_id":
11, "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT-S", "description": "Awesome Spree T-Shirt", "price": 35.0, "cost_price": 22.33, "available_on": "2014-01-29T14:01:28.000Z", "permalink": "spree-tshirt", "meta_description": null, "meta_keywords": null, "shipping_category": "Default", POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "summary": "Product updated in NetSuite", } -
/update_product Webhook { "request_id": "52f367367575e449c3000001", "product": { "id": 58, "parent_id":
11, "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT-S", "description": "Awesome Spree T-Shirt", "price": 35.0, "cost_price": 22.33, "available_on": "2014-01-29T14:01:28.000Z", "permalink": "spree-tshirt", "meta_description": null, "meta_keywords": null, "shipping_category": "Default", POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "summary": "Product updated in NetSuite", } -
/update_product Webhook { "request_id": "52f367367575e449c3000001", "product": { "id": 58, "parent_id":
11, "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT-S", "description": "Awesome Spree T-Shirt", "price": 35.0, "cost_price": 22.33, "available_on": "2014-01-29T14:01:28.000Z", "permalink": "spree-tshirt", "meta_description": null, "meta_keywords": null, "shipping_category": "Default", POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "summary": "Product updated in NetSuite", } -
Webhook: Parameters { "request_id": "52f367367575e449c3000001", "order": {}, "parameters": { "quickbooks.access_token":
"qyprd1vQF...", "quickbooks.access_secret": "xTrT6dckbY...", "quickbooks.realm": "1231232" } } POST -
Webhook: Parameters { "request_id": "52f367367575e449c3000001", "order": {}, "parameters": { "quickbooks.access_token":
"qyprd1vQF...", "quickbooks.access_secret": "xTrT6dckbY...", "quickbooks.realm": "1231232" } } POST -
Webhook: Parameters { "request_id": "52f367367575e449c3000001", "order": {}, "parameters": { "quickbooks.access_token":
"qyprd1vQF...", "quickbooks.access_secret": "xTrT6dckbY...", "quickbooks.realm": "1231232" } } POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "summary": "Order imported to Quickbooks", } -
/get_customers Webhook { "request_id": "52f367367575e449c3000001", "parameters": { "since": "2014-02-03T17:29:00.000Z }
} POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "customers": [ { "id": 1, "email": "[email protected]" }, { "id": 2, "first_name": "Sean", "last_name": "Schofield" ], "parameters": { "since": "2014-02-03T17:35:00.000Z" } } -
/get_customers Webhook { "request_id": "52f367367575e449c3000001", "parameters": { "since": "2014-02-03T17:29:00.000Z }
} POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "customers": [ { "id": 1, "email": "[email protected]" }, { "id": 2, "first_name": "Sean", "last_name": "Schofield" ], "parameters": { "since": "2014-02-03T17:35:00.000Z" } } -
/get_customers Webhook { "request_id": "52f367367575e449c3000001", "parameters": { "since": "2014-02-03T17:29:00.000Z }
} POST Response: 200 OK { "request_id": "52f367367575e449c3000001", "customers": [ { "id": 1, "email": "[email protected]" }, { "id": 2, "first_name": "Sean", "last_name": "Schofield" ], "parameters": { "since": "2014-02-03T17:35:00.000Z" } } -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST Response: 500 Error { "request_id": "52f367367575e449c3000001", "summary": "Order import failed for NetSuite", } -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST Response: 500 Error { "request_id": "52f367367575e449c3000001", "summary": "Order import failed for NetSuite", } -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST Response: 500 Error { "request_id": "52f367367575e449c3000001", "summary": "Order import failed for NetSuite", } -
Authentication ➡ With each webhook, the hub includes the following
headers: ➡ X-Hub-Store ➡ Unique store identifier -
Authentication ➡ With each webhook, the hub includes the following
headers: ➡ X-Hub-Store ➡ Unique store identifier ➡ X-Hub-Token ➡ Pre-shared secret to identify the hub is sending the POST. -
endpoint_base ➡ Supports both Sinatra & Rails endpoints, & provides:
➡ Authentication -
endpoint_base ➡ Supports both Sinatra & Rails endpoints, & provides:
➡ Authentication ➡ Helper methods & variables -
endpoint_base ➡ Supports both Sinatra & Rails endpoints, & provides:
➡ Authentication ➡ Helper methods & variables ➡ @payload & @config -
endpoint_base ➡ Supports both Sinatra & Rails endpoints, & provides:
➡ Authentication ➡ Helper methods & variables ➡ @payload & @config ➡ Response DSL -
endpoint_base ➡ Supports both Sinatra & Rails endpoints, & provides:
➡ Authentication ➡ Helper methods & variables ➡ @payload & @config ➡ Response DSL ➡ Rendering -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST -
/add_order Webhook { "request_id": "52f367367575e449c3000001", "order": { "id": "R154085346", "number":
"R154085346", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "updated_at": "2014-02-03T17:29:15.253Z", "status": "complete", "totals": { "item": 100.0, "adjustment": 5.0, "tax": 0.0, POST Response: 500 Error { "request_id": "52f367367575e449c3000001", "summary": "SKU ‘ROR-123’ is invalid.", } -
Retry Patterns: Back-off hub /add_order 500: fail! /add_order 200: success
Netsuite /add_order 500: fail! /add_order 500: fail! Order PUSH order:created -
Retry Patterns: Back-off hub /add_order 500: fail! /add_order 200: success
Netsuite /add_order 500: fail! /add_order 500: fail! Order PUSH -
Retry Patterns: Auto-recovery hub Netsuite Order PUSH order:created 500: fail!
/add_order 500: fail! /add_order -
Retry Patterns: Auto-recovery hub Netsuite Order PUSH order:created Order PUSH
500: fail! /add_order 500: fail! /add_order * -
Retry Patterns: Auto-recovery hub /add_order Netsuite Order PUSH order:created Order
PUSH 200: success 500: fail! /add_order 500: fail! /add_order * -
Retry Patterns: No retry hub order:created 500: fail! Netsuite Order
PUSH order:created -
Macros ➡ Embedded javascript functions ➡ Get applied to the
body of a webhook -
Macros ➡ Embedded javascript functions ➡ Get applied to the
body of a webhook ➡ before it’s sent to the integration -
Macros ➡ Embedded javascript functions ➡ Get applied to the
body of a webhook ➡ before it’s sent to the integration ➡ Has access to: -
Macros ➡ Embedded javascript functions ➡ Get applied to the
body of a webhook ➡ before it’s sent to the integration ➡ Has access to: ➡ entire body (including parameters). -
Macros ➡ Embedded javascript functions ➡ Get applied to the
body of a webhook ➡ before it’s sent to the integration ➡ Has access to: ➡ entire body (including parameters). ➡ underscore.js, helper methods, more. -
Communications Use Case: “I want to send a user an
email after they complete an order” ➡ Object: Order ➡ Event: order:created ➡ Webhook: POST /send_email -
Marcos - Use Case { "order": { "id": "R154085346", "status":
"complete", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "totals": { }, "line_items": [ { "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT", "external_ref": "", "quantity": 2, Order Object -
Marcos - Use Case { "order": { "id": "R154085346", "status":
"complete", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "totals": { }, "line_items": [ { "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT", "external_ref": "", "quantity": 2, Order Object { "request_id": "52f367367575e449c3000001", "email": { "to": "[email protected]", "from": "[email protected]", "subject": "Order R123456 was shipped!", "template": "order_shipped", "variables": { "customer_name": "John Smith", "order_total": "100.00", "order_tracking": "XYZ123" } } } /send_email webhook -
Marcos - Use Case { "order": { "id": "R154085346", "status":
"complete", "channel": "spree", "email": "[email protected]", "currency": "USD", "placed_on": "2014-02-03T17:29:15.219Z", "totals": { }, "line_items": [ { "name": "Spree T-Shirt", "sku": "SPREE-T-SHIRT", "external_ref": "", "quantity": 2, Order Object { "request_id": "52f367367575e449c3000001", "email": { "to": "[email protected]", "from": "[email protected]", "subject": "Order R123456 was shipped!", "template": "order_shipped", "variables": { "customer_name": "John Smith", "order_total": "100.00", "order_tracking": "XYZ123" } } } /send_email webhook -
Macro - Example var email = { variables: {} };
email.to = request.order.email; email.from = find_param('mandrill.order_confirimation_from'); email.template = find_param('mandrill.order_confirimation_template'); email.variables.order_number = request.order.number; email.variables.shipping_first_name = request.order.shipping_address.firstname; email.variables.shipping_last_name = request.order.shipping_address.lastname; email.variables.total = Number(payload.order.totals.order).toFixed(2); _.each(request.order.line_items, function(item){ email.variables.line_item_rows += '<tr><td>' + item.name + '</td>\ <td>' + item.quantity + '</td>\ <td>$' + Number(item.price).toFixed(2) + '</td></tr>'; }); request.email = email; -
Macro - Example var email = { variables: {} };
email.to = request.order.email; email.from = find_param('mandrill.order_confirimation_from'); email.template = find_param('mandrill.order_confirimation_template'); email.variables.order_number = request.order.number; email.variables.shipping_first_name = request.order.shipping_address.firstname; email.variables.shipping_last_name = request.order.shipping_address.lastname; email.variables.total = Number(payload.order.totals.order).toFixed(2); _.each(request.order.line_items, function(item){ email.variables.line_item_rows += '<tr><td>' + item.name + '</td>\ <td>' + item.quantity + '</td>\ <td>$' + Number(item.price).toFixed(2) + '</td></tr>'; }); request.email = email; -
Macro - Example var email = { variables: {} };
email.to = request.order.email; email.from = find_param('mandrill.order_confirimation_from'); email.template = find_param('mandrill.order_confirimation_template'); email.variables.order_number = request.order.number; email.variables.shipping_first_name = request.order.shipping_address.firstname; email.variables.shipping_last_name = request.order.shipping_address.lastname; email.variables.total = Number(payload.order.totals.order).toFixed(2); _.each(request.order.line_items, function(item){ email.variables.line_item_rows += '<tr><td>' + item.name + '</td>\ <td>' + item.quantity + '</td>\ <td>$' + Number(item.price).toFixed(2) + '</td></tr>'; }); request.email = email; -
Macro - Example var email = { variables: {} };
email.to = request.order.email; email.from = find_param('mandrill.order_confirimation_from'); email.template = find_param('mandrill.order_confirimation_template'); email.variables.order_number = request.order.number; email.variables.shipping_first_name = request.order.shipping_address.firstname; email.variables.shipping_last_name = request.order.shipping_address.lastname; email.variables.total = Number(payload.order.totals.order).toFixed(2); _.each(request.order.line_items, function(item){ email.variables.line_item_rows += '<tr><td>' + item.name + '</td>\ <td>' + item.quantity + '</td>\ <td>$' + Number(item.price).toFixed(2) + '</td></tr>'; }); request.email = email; -
Macro - Example var email = { variables: {} };
email.to = request.order.email; email.from = find_param('mandrill.order_confirimation_from'); email.template = find_param('mandrill.order_confirimation_template'); email.variables.order_number = request.order.number; email.variables.shipping_first_name = request.order.shipping_address.firstname; email.variables.shipping_last_name = request.order.shipping_address.lastname; email.variables.total = Number(payload.order.totals.order).toFixed(2); _.each(request.order.line_items, function(item){ email.variables.line_item_rows += '<tr><td>' + item.name + '</td>\ <td>' + item.quantity + '</td>\ <td>$' + Number(item.price).toFixed(2) + '</td></tr>'; }); request.email = email; -
Macro - Example var email = { variables: {} };
email.to = request.order.email; email.from = find_param('mandrill.order_confirimation_from'); email.template = find_param('mandrill.order_confirimation_template'); email.variables.order_number = request.order.number; email.variables.shipping_first_name = request.order.shipping_address.firstname; email.variables.shipping_last_name = request.order.shipping_address.lastname; email.variables.total = Number(payload.order.totals.order).toFixed(2); _.each(request.order.line_items, function(item){ email.variables.line_item_rows += '<tr><td>' + item.name + '</td>\ <td>' + item.quantity + '</td>\ <td>$' + Number(item.price).toFixed(2) + '</td></tr>'; }); request.email = email;