# Webhook Integration

## Introduction

Intelligems provides a powerful webhook system that allows you to send real-time data about experiments, user actions, and store events to external services. This enables you to build custom integrations, automate workflows, and connect Intelligems data with your existing tools and platforms.

## Overview

Webhooks are HTTP POST requests that Intelligems sends to your specified endpoints when certain events occur. This allows you to:

* Receive real-time notifications about experiment events
* Integrate Intelligems data with external analytics platforms
* Automate workflows based on A/B test results
* Send alerts to team communication tools like Slack
* Trigger custom business logic in your applications

## Available Webhook Events

Intelligems supports webhooks for the following experience event types:

#### Experience Events

* **Create Experience**: Triggered when a new A/B test or experiment is created
* **Start Experience**: Triggered when an experiment goes live
* **Pause Experience**: Triggered when an experiment is paused
* **End Experience**: Triggered when an experiment is stopped or completed
* **Update Experience**: Triggered when experiment settings are modified
* **Delete Experience**: Triggered when an experiment is deleted

## Setting Up Webhooks

#### 1. Configure Webhook Endpoints

To set up webhooks in Intelligems:

1. Navigate to **Settings** in your Intelligems dashboard
2. Enter your webhook endpoint URL
3. Select the events you want to receive
4. Click Add Webhook in the Webhooks section
5. Configure any authentication headers within your consuming application, if required
6. Test the webhook connection

#### 2. Webhook Security (Optional)

Intelligems signs all webhook payloads with a secret key to ensure authenticity:

```javascript
// Verify webhook signature (Node.js example)
const crypto = require('crypto');

function verifyWebhookSignature(payload, signature, secret) {
  const expectedSignature = crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');

  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expectedSignature)
  );
}
```

#### 3. Handling Webhook Retries

Intelligems will retry failed webhook deliveries:

* **Success Criteria**: HTTP status codes 200-299
* **Timeout**: 10 seconds per request
* **Maximum Retries**: 5 attempts

## Example Payloads

<details>

<summary>Create Experience</summary>

```
{
   "action":"createExperience",
   "timestamp":1771515006494,
   "experience":{
      "id":"be4b13da-26f7-4cbd-a642-9934fe26bab3",
      "name":"New Test",
      "isPreview":true,
      "description":"",
      "organizationId":"1a111-1a1-aaa1-a111-a1aa1aa11111",
      "type":"pricing",
      "category":"experiment",
      "status":"pending",
      "testTypes":{
         "hasTestPricing":true,
         "hasTestShipping":false,
         "hasTestCampaign":false,
         "hasTestContent":false,
         "hasTestContentUrl":false,
         "hasTestContentAdvanced":false,
         "hasTestContentOnsite":false,
         "hasTestContentTemplate":false,
         "hasTestContentTheme":false,
         "hasTestOnsiteInjections":false,
         "hasTestCheckoutBlocks":false
      },
      "experienceActions":[
         
      ],
      "currency":{
         "code":"USD",
         "symbol":"$"
      },
      "variations":[
         {
            "id":"b682fdfe-a2f6-45eb-82cc-53d1989b43e9",
            "experienceId":"be4b13da-26f7-4cbd-a642-9934fe26bab3",
            "name":"Control Group",
            "percentage":50,
            "isControl":true,
            "order":0,
            "priceChange":null,
            "priceChangeUnit":"percent",
            "priceRoundingType":null,
            "priceRoundingAmount":null,
            "onsiteEdits":[
               
            ],
            "onsiteInjections":null,
            "offer":null,
            "shippingRateGroups":[
               
            ],
            "excludeProducts":false,
            "includeProducts":false,
            "testExperienceId":null,
            "functionSyncError":false,
            "redirects":[
               
            ],
            "userInterfaces":[
               
            ],
            "checkoutBlocks":[
               
            ]
         },
         {
            "id":"ac6bafaf-73de-4916-abdd-3fd2e708d511",
            "experienceId":"be4b13da-26f7-4cbd-a642-9934fe26bab3",
            "name":"New Group 1",
            "percentage":50,
            "isControl":false,
            "order":1,
            "priceChange":null,
            "priceChangeUnit":"percent",
            "priceRoundingType":null,
            "priceRoundingAmount":null,
            "onsiteEdits":[
               
            ],
            "onsiteInjections":null,
            "offer":null,
            "shippingRateGroups":[
               
            ],
            "excludeProducts":false,
            "includeProducts":false,
            "testExperienceId":null,
            "functionSyncError":false,
            "redirects":[
               
            ],
            "userInterfaces":[
               
            ],
            "checkoutBlocks":[
               
            ]
         }
      ],
      "createdAtTs":1771514995763,
      "isDeleted":false,
      "lastUpdateTs":1771514995763,
      "productVariantCount":0,
      "sourceExperienceId":null,
      "sourceAction":null
   },
   "organization":{
      "id":"1a111-1a1-aaa1-a111-a1aa1aa11111",
      "name":"example",
      "shopId":"example.myshopify.com"
   }
}
```

</details>

<details>

<summary>Start Experience</summary>

```
{
   "action":"startExperience",
   "timestamp":1771515680494,
   "experience":{
      "id":"9d939485-5c41-45ea-861a-0c00b86d466b",
      "name":"Theme Test",
      "isPreview":true,
      "description":"",
      "organizationId":"1a111-1a1-aaa1-a111-a1aa1aa11111",
      "type":"content/theme",
      "category":"experiment",
      "status":"paused",
      "testTypes":{
         "hasTestPricing":false,
         "hasTestShipping":false,
         "hasTestCampaign":false,
         "hasTestContent":false,
         "hasTestContentUrl":false,
         "hasTestContentAdvanced":false,
         "hasTestContentOnsite":false,
         "hasTestContentTemplate":false,
         "hasTestContentTheme":true,
         "hasTestOnsiteInjections":false,
         "hasTestCheckoutBlocks":false
      },
      "experienceActions":[
         {
            "id":"89bb6f5b-fb92-4a74-ba2b-3cf732b30011",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "action":"pause",
            "actionTs":1770050720119
         },
         {
            "id":"b952b435-76c5-4d7b-8183-74850524ab03",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "action":"start",
            "actionTs":1770050707402
         },
         {
            "id":"bee36cb0-6828-46c1-b752-c1429ef46eb7",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "action":"pause",
            "actionTs":1770050614891
         },
         {
            "id":"c43f24cb-bfb2-4766-b58d-3f15376df5ff",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "action":"start",
            "actionTs":1770050602503
         },
         {
            "id":"1b24d283-09fb-4a0b-a97c-144bfe9f83e0",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "action":"pause",
            "actionTs":1767976474802
         },
         {
            "id":"8603294c-813b-43ca-8d67-f8cf7d06c2b8",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "action":"start",
            "actionTs":1767976456167
         }
      ],
      "currency":null,
      "variations":[
         {
            "id":"57b1e27d-058d-458f-b4db-936e1cc3e5e9",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "name":"Control Group",
            "percentage":50,
            "isControl":true,
            "order":0,
            "priceChange":null,
            "priceChangeUnit":"percent",
            "priceRoundingType":null,
            "priceRoundingAmount":null,
            "onsiteEdits":[
               
            ],
            "onsiteInjections":null,
            "offer":null,
            "shippingRateGroups":[
               
            ],
            "excludeProducts":false,
            "includeProducts":false,
            "testExperienceId":null,
            "functionSyncError":false,
            "redirects":[
               {
                  "id":"ec5f497a-247e-4f44-a1b1-269eb256a8df",
                  "group":1,
                  "variationId":"57b1e27d-058d-458f-b4db-936e1cc3e5e9",
                  "originUrl":"",
                  "destinationUrl":"",
                  "queryParams":[
                     {
                        "key":"preview_theme_id",
                        "value":"133068324949"
                     }
                  ],
                  "skip":false,
                  "isThemeTest":true,
                  "isTemplateTest":false,
                  "templateType":null,
                  "templateSuffixes":[
                     
                  ],
                  "redirectOnce":false,
                  "filter":"none",
                  "find":null,
                  "redirectType":"fullReplacement"
               }
            ],
            "userInterfaces":[
               
            ],
            "checkoutBlocks":[
               
            ]
         },
         {
            "id":"4e6b74df-4816-4ba6-9261-cb5cfe5dc7b2",
            "experienceId":"9d939485-5c41-45ea-861a-0c00b86d466b",
            "name":"New Group 1",
            "percentage":50,
            "isControl":false,
            "order":1,
            "priceChange":null,
            "priceChangeUnit":"percent",
            "priceRoundingType":null,
            "priceRoundingAmount":null,
            "onsiteEdits":[
               
            ],
            "onsiteInjections":null,
            "offer":null,
            "shippingRateGroups":[
               
            ],
            "excludeProducts":false,
            "includeProducts":false,
            "testExperienceId":null,
            "functionSyncError":false,
            "redirects":[
               {
                  "id":"696c3924-9ac7-4741-a3df-6ef6b14274f9",
                  "group":1,
                  "variationId":"4e6b74df-4816-4ba6-9261-cb5cfe5dc7b2",
                  "originUrl":"",
                  "destinationUrl":"",
                  "queryParams":[
                     {
                        "key":"preview_theme_id",
                        "value":"133068292181"
                     }
                  ],
                  "skip":false,
                  "isThemeTest":true,
                  "isTemplateTest":false,
                  "templateType":null,
                  "templateSuffixes":[
                     
                  ],
                  "redirectOnce":false,
                  "filter":"none",
                  "find":null,
                  "redirectType":"fullReplacement"
               }
            ],
            "userInterfaces":[
               
            ],
            "checkoutBlocks":[
               
            ]
         }
      ],
      "createdAtTs":1767904006314,
      "isDeleted":false,
      "lastUpdateTs":1767904006314,
      "productVariantCount":0,
      "sourceExperienceId":null,
      "sourceAction":null
   },
   "organization":{
      "name":"example",
      "id":"1a111-1a1-aaa1-a111-a1aa1aa11111",
      "shopId":"example.myshopify.com"
   }
}
```

</details>

<details>

<summary>End Experience</summary>

```
{
   "action":"endExperience",
   "timestamp":1771515803205,
   "experience":{
      "id":"93b908f2-0b5f-4a11-9318-3aa8bbbeaf60",
      "name":"$Off vs %Off",
      "isPreview":false,
      "description":"",
      "organizationId":"1a111-1a1-aaa1-a111-a1aa1aa11111",
      "type":"personalization/offer",
      "category":"experiment",
      "status":"started",
      "testTypes":{
         "hasTestPricing":false,
         "hasTestShipping":false,
         "hasTestCampaign":true,
         "hasTestContent":false,
         "hasTestContentUrl":false,
         "hasTestContentAdvanced":false,
         "hasTestContentOnsite":false,
         "hasTestContentTemplate":false,
         "hasTestContentTheme":false,
         "hasTestOnsiteInjections":false,
         "hasTestCheckoutBlocks":false
      },
      "experienceActions":[
         {
            "id":"3a45c2f6-e21c-45a3-a15d-ff9937e7c285",
            "experienceId":"93b908f2-0b5f-4a11-9318-3aa8bbbeaf60",
            "action":"start",
            "actionTs":1768924166952
         }
      ],
      "currency":null,
      "variations":[
         {
            "id":"3fb9ff5a-5c0b-43da-90b8-2274533d80e4",
            "experienceId":"93b908f2-0b5f-4a11-9318-3aa8bbbeaf60",
            "name":"Control",
            "percentage":50,
            "isControl":true,
            "order":0,
            "priceChange":null,
            "priceChangeUnit":"percent",
            "priceRoundingType":null,
            "priceRoundingAmount":null,
            "onsiteEdits":[
               
            ],
            "onsiteInjections":null,
            "offer":{
               "id":"fc18d01f-a4d9-432f-bbea-def37af6aa55",
               "variationId":"3fb9ff5a-5c0b-43da-90b8-2274533d80e4",
               "enabled":false,
               "isTest":false,
               "isArchived":false,
               "name":"Discount",
               "unitType":"unit",
               "discountType":"dollar",
               "tiers":[
                  {
                     "id":"5244c63f-9eb4-4c86-997e-3b38b38a35cf",
                     "minimumUnits":0,
                     "maximumUnits":1,
                     "unitDiscount":10,
                     "discountTitle":"10DollarOff",
                     "giftWithPurchaseTitle":null,
                     "isFreeShipping":false,
                     "isGiftWithPurchase":false,
                     "giftWithPurchaseProductId":null,
                     "giftWithPurchaseVariantId":null,
                     "autoAddGiftWithPurchase":true,
                     "giftWithPurchaseHandle":null
                  }
               ],
               "maximumDollarDiscount":null,
               "discountApplicationType":"cartDiscount",
               "discountApplicationMethod":"perOrder",
               "combinesWithIntelligems":true,
               "combinesWithShopify":true,
               "shouldRejectCodes":false,
               "shippingDiscount":null,
               "requireSameItem":false
            },
            "shippingRateGroups":[
               
            ],
            "excludeProducts":false,
            "includeProducts":false,
            "testExperienceId":null,
            "functionSyncError":false,
            "redirects":[
               
            ],
            "userInterfaces":[
               
            ],
            "checkoutBlocks":[
               
            ]
         },
         {
            "id":"9735c942-a05e-4655-90a5-3660bc3ec904",
            "experienceId":"93b908f2-0b5f-4a11-9318-3aa8bbbeaf60",
            "name":"Test Group 1",
            "percentage":50,
            "isControl":false,
            "order":1,
            "priceChange":null,
            "priceChangeUnit":"percent",
            "priceRoundingType":null,
            "priceRoundingAmount":null,
            "onsiteEdits":[
               
            ],
            "onsiteInjections":null,
            "offer":{
               "id":"c3bfa635-8f73-4d38-a5e8-f75df029328e",
               "variationId":"9735c942-a05e-4655-90a5-3660bc3ec904",
               "enabled":false,
               "isTest":false,
               "isArchived":false,
               "name":"Discount",
               "unitType":"unit",
               "discountType":"percentage",
               "tiers":[
                  {
                     "id":"a30fc3f0-1cd8-4b1f-8e01-645c3771736a",
                     "minimumUnits":0,
                     "maximumUnits":1,
                     "unitDiscount":10,
                     "discountTitle":"10PercentOff",
                     "giftWithPurchaseTitle":null,
                     "isFreeShipping":false,
                     "isGiftWithPurchase":false,
                     "giftWithPurchaseProductId":null,
                     "giftWithPurchaseVariantId":null,
                     "autoAddGiftWithPurchase":true,
                     "giftWithPurchaseHandle":null
                  }
               ],
               "maximumDollarDiscount":null,
               "discountApplicationType":"cartDiscount",
               "discountApplicationMethod":"perOrder",
               "combinesWithIntelligems":true,
               "combinesWithShopify":true,
               "shouldRejectCodes":false,
               "shippingDiscount":null,
               "requireSameItem":false
            },
            "shippingRateGroups":[
               
            ],
            "excludeProducts":false,
            "includeProducts":false,
            "testExperienceId":null,
            "functionSyncError":false,
            "redirects":[
               
            ],
            "userInterfaces":[
               
            ],
            "checkoutBlocks":[
               
            ]
         }
      ],
      "createdAtTs":1767795979263,
      "isDeleted":false,
      "lastUpdateTs":1769704906937,
      "productVariantCount":0,
      "sourceExperienceId":null,
      "sourceAction":null
   },
   "organization":{
      "name":"example",
      "id":"1a111-1a1-aaa1-a111-a1aa1aa11111",
      "shopId":"example.myshopify.com"
   }
}
```

</details>

{% hint style="info" %}
Need more example payloads? Hook your webhooks up to a free tool like [Pipedream](https://pipedream.com/), trigger the webhook action in your Intelligems account, and see what the payload looks like in Pipedream.
{% endhint %}

## Example: Zapier to Slack Integration

This step-by-step example shows how to use Zapier to send Slack alerts when experiments launch.&#x20;

#### Step 1: Create a Zapier Webhook

1. Log into your [Zapier account](https://zapier.com)
2. Click **Create Zap**
3. Search for and select **Webhooks by Zapier** as the trigger app
4. Choose **Catch Hook** as the trigger event
5. Copy the webhook URL provided by Zapier

#### Step 2: Configure Intelligems Webhook

1. In your Intelligems dashboard, go to **Settings** > **Integrations**
2. Click **Add Webhook**
3. Paste the Zapier webhook URL
4. Select the **Start Experience** event (or any other experience event you want to track)
5. Save the configuration

#### Step 3: Set Up Slack Action in Zapier

1. In your Zapier workflow, click **Continue** after setting up the webhook trigger
2. Search for and select **Slack** as the action app
3. Choose **Send Channel Message** as the action event
4. Connect your Slack account if not already connected
5. Configure the Slack message:
   * **Channel**: Select your desired Slack channel (e.g., #marketing-alerts)
   * **Message Text**: Use dynamic fields from the webhook payload:

#### Step 4: Test the Integration

1. In Zapier, click **Test & Continue** to test the Slack message
2. Create a test experiment in Intelligems or trigger a test webhook
3. Verify that the Slack message appears in your chosen channel
4. Turn on your Zap to make it live

## Additional Integration Examples

### Google Sheets Integration

Track experiment results in a Google Sheet:

1. Use **Google Sheets** as the Zapier action app
2. Choose **Create Spreadsheet Row** as the action
3. Map webhook fields to spreadsheet columns:
   * Column A: Experience Name
   * Column B: Action Type
   * Column C: Experience Type
   * Column D: Timestamp
   * Column E: Experience ID
   * Column F: Triggered By Email

### Email Notifications

Send email alerts to your team:

1. Use **Email by Zapier** as the action app
2. Configure recipient email addresses
3. Create email templates with experience data
4. Set up different email templates for different action types

### Custom API Integration

Send data to your own API endpoint:

1. Use **Webhooks by Zapier** as the action app
2. Choose **POST** as the action event
3. Configure your API endpoint URL
4. Map webhook payload data to your API format
5. Add authentication headers if required

## Best Practices

#### 1. Webhook Endpoint Design

* **Respond Quickly**: Return HTTP 200 status within 10 seconds
* **Validate Signatures**: Always verify webhook authenticity
* **Log Events**: Keep records of received webhooks for debugging

#### 2. Error Handling

```javascript
// Example webhook handler with proper error handling
app.post('/webhook/intelligems', (req, res) => {
  try {
    // Verify signature
    if (!verifyWebhookSignature(req.body, req.headers['X-Intelligems-Signature'], secret)) {
      return res.status(401).send('Invalid signature');
    }

    // Process webhook
    processWebhookEvent(req.body);

    // Respond quickly
    res.status(200).send('OK');
  } catch (error) {
    console.error('Webhook processing error:', error);
    res.status(500).send('Internal server error');
  }
});
```

#### 3. Monitoring and Debugging

* Test webhooks thoroughly before going live

## Troubleshooting

### Common Issues

#### **Webhook Not Receiving Data**

* Verify the endpoint URL is correct and accessible
* Check that your server responds with HTTP 200
* Ensure firewall settings allow incoming requests
* Verify the webhook is enabled for the correct events

#### **Authentication Failures**

* Confirm webhook signature verification is implemented correctly
* Check that the secret key matches your configuration
* Verify timestamp tolerance in signature validation

#### **Zapier Integration Issues**

* Ensure the Zapier webhook URL is correctly configured in Intelligems
* Check that your Zap is turned on and active
* Verify field mappings in your Zapier action steps
* Test the integration with sample data
