By using this website you implicitly accept our cookies. For more informations read our Cookie policy

Using Webhooks

Use webhooks to notify other apps whenever any event occurs in your Marketcloud application. If you need further help, you can find us in our slack channel or writing us an email.

Note

To intercept webhooks you need a server sided app with a publicly available address. You can use services like Heroku, Azure and AWS to easily setup a web application able to listen for POST http requests.

Table of contents

  1. Create a webhook
  2. Receive a webhook
  3. Webhook data structure
  4. Events table

Create a webhook

Go to your dashboard and open your app's settings.

Click on the "webhooks" tab to show the list of your app's webhooks. If you did not create any webhook, you should see an empty list like the following imag.

Click on the "add" button on the upper right corner to create a new webhook. When the modal opens, select an event from the list, for example select orders.create to trigger this webhook whenever new order is created in your app.

In the second box, insert the URL which will be invoked whenever an order is created.

Note
The URL you provide will be invoked with a POST request.

Receive a webhook

Webhook data is sent as JSON in the POST request body. The full event object included and can be used directly, after parsing the JSON.


/*
  Accepting webhooks with PHP is as easy as creating a simple .php file
*/
$inputJSON = file_get_contents('php://input');

/*
  Your event object
*/
$event = json_decode($inputJSON); //convert JSON into array

                    

/*
  Using a framework like ExpressJS,
  we just need to create a new route
*/
app.post('/webhook',function(request,response,next){

  /*
    If you are not parsing JSON in a middleware,
    you have to do it here
  */
  var event = JSON.parse(request.body);

  res.send(200);
});

                    

Webhook data structure

When your code receives a webhook in the form of a HTTP request, the request's body will contain the relevant data for the captured event. Here's an example webhook generated when a product was updated.


{
  "apiVersion": "v0",
  "time": "2017-04-27T14:04:57.851Z",
  "event":"products.update",
  "data":{
    "status" : true,
    "data" : {
      "type":"simple_product",
      "id":20075,
      "application_id":10338,
      "name":"Javascript sticker",
      "slug":"javascript-sticker",
      "description":"",
      "images":[
         "http://www.example.com/image.jpg"
      ],
      "category_id":20862,
      "brand_id":20743,
      "price":3.99,
      "price_discount":2.99,
      "display_price":"3.99 EUR",
      "display_price_discount":"2.99 EUR",
      "stock_type":"status",
      "stock_status":"in_stock",
      "published":true
    }
  }
  "request": {
    "method": "PUT",
    "access": "admin",
    "path": "/v0/products/20075",
    "body": {
      "price": 3.99
    },
    "query": {}
  }
}    
           
        

Events table

Here's a list of the events you can listen for and process.

Event name Event description
products.create Triggered whenever a product is created
products.delete Triggered whenever a product is deleted
products.update Triggered whenever a product is updated
brands.create Triggered whenever a brand is created
brands.delete Triggered whenever a brand is deleted
brands.update Triggered whenever a brand is updated
categories.create Triggered whenever a category is created
categories.delete Triggered whenever a category is deleted
categories.update Triggered whenever a category is updated
orders.create Triggered whenever an order is created
orders.delete Triggered whenever an order is deleted
orders.update Triggered whenever an order is updated
carts.create Triggered whenever a cart is created
carts.delete Triggered whenever a cart is deleted
carts.update Triggered whenever a cart is updated
payments.create Triggered whenever a payment is created
payments.delete Triggered whenever a payment is deleted
payments.update Triggered whenever a payment is updated
shippings.create Triggered whenever a shipping is created
shippings.delete Triggered whenever a shipping is deleted
shippings.update Triggered whenever a shipping is updated
users.create Triggered whenever a user is created
users.update Triggered whenever a user is updated
users.delete Triggered whenever a user is deleted

Questions?

We're super happy to help with any question you might have! Send us an email, or get in touch with us in our Slack channel !