» Webhooks

Webhooks

What Are Webhooks?

Webhooks are a powerful tool that allows you to receive notifications about specific events or actions without the need for periodic API calls. By subscribing to webhooks, you can automate your app’s operations and trigger custom actions based on these events. For example, you can use webhooks to receive notifications when a customer adds a product to their cart or creates a new order. By subscribing to these webhooks, you can easily stay informed and execute your own code based on these actions.

Registering Webhooks

To register webhooks with WebCommander, you need to provide two pieces of information: the sourceUrl and the eventName. WebCommander will then trigger an action based on the specified event name and call the URL provided in the source URL. This URL can be one of your app’s endpoints where you have implemented the necessary code to handle the webhook and perform the desired operation.

Here is an example of how to register webhooks with WebCommander:

"webhooks": [
    {
      "sourceUrl": "https://yourapp.com/api/v1/cart/added-to-cart", // The url WebCommander will call when firing this hook
      "eventName": "added-to-cart", // A webhook event name. Check Webhook list to find details
      "renderScope": "", // Required for script tags
      "accessType": "webhook" // A data access type to define which way your plugin collecting data.    
    }
  ],

By leveraging webhooks, you can streamline your app’s processes, avoid unnecessary API calls, and enable real-time integration with external systems.

Installation

To register webhooks for a site using the /install endpoint in WebCommander, you’ll need to provide a list of event names and source URLs. Below is an example response format that illustrates how to set up webhooks:

{
  "webhooks": [
    {
      "sourceUrl": "https://yourapp.com/api/v1/cart/added-to-cart",
      "eventName": "added-to-cart",
      "renderScope": "",
      "accessType": "webhook"
    }
  ],
  "scriptTag": [
    {
      "sourceUrl": "https://yourapp.com/assets/js/script-tag.js",
      "eventName": "",
      "renderScope": "All",
      "accessType": "scriptTag"
    }
  ]
}

Example

curl --location 'https://yourapp.com/api/v1/cart/added-to-cart?uuid=F8A3-A88E-C6EF-B1CB' \
--header 'Content-Type: application/json' \
--data-raw '{
    "hook_name": "added-to-cart",
    "hook_Data": {
        "cartItems": [
            {
                "firstName": "second",
                "lastName": "Test",
                "email": "test1fdsfe4@mailinator.com"
            },
            {
                "eventId": "C60B89F8-3A90-4DED-937D-DD62867859E2",
                "value": 27.5,
                "items": [
                    {
                        "ProductID": "15",
                        "SKU": "PRODUCT-7E2BEE252B07",
                        "ProductName": "Vegetarian Pasta",
                        "Quantity": 1,
                        "ItemPrice": 27.5,
                        "RowTotal": 27.5,
                        "ProductURL": "http://localhost:1301/product/vegetarian-pasta-1",
                        "ImageURL": "http://localhost:8080resources/00000000/product/product-15//vegetarian-pasta.png"
                    }
                ]
            }
        ]
    }
}'

Hook Parameter

Hook parameters are the set of data that WebCommander will send you with the Hook name and the data related to the fired hook. Example:

{
    "hook_name": "added-to-cart",
    "hook_Data": {
        // Check Webhooks list for sample hook data
    }
}