Webhooks setup

To integrate webhook events into your application, follow these steps:

  1. Create Webhook Endpoint: Develop an HTTP endpoint to receive POST requests containing webhook events.
  2. Register Endpoint: Register your endpoint with the widget the admin page.
  3. Secure Endpoint: Implement request verification to ensure that incoming requests are from the Axitech Widget Webhook Service.
  4. Handling Events: Process the received webhook events based on the payload provided in the request body.
  5. Return Success Code: Return a 2XX status code upon successful receipt of the event to acknowledge receipt and prevent retries (make sure the endpoint operations are idempotent and accidental retries/duplications do not break your logic).

The Event Object

Properties:

  • created_at: string
    • Timestamp indicating when the event was created. Format: 'YYYY-MM-DDTHH:mm:ss'.
  • api_version: string
    • Version of the Axitech Widget Webhook Service API.
  • group_type: string
    • Specifies the group that the specific event belongs to. (e.g., "WidgetEvent").
  • event_type: string
    • Type of the event inside the specified group (e.g., "submission.created").
  • data: object
    • Specific data related to the event. The structure depends on the event type.

The session.submitted Event

  • sessionId: string
    • Unique identifier for the session.
  • date: string
    • Timestamp indicating the claim date for example the time of accident if the session is an accident claim. Format: 'YYYY-MM-DDTHH:mm:ss'.
  • integrations: array of objects
    • List of integrations associated with the session.
      • key: string
        • Integration key.
      • id: string
        • Unique identifier for the integration.
      • reference: string
        • Reference identifier for the integration.
      • name: string
        • Name of the integration.
      • status: string
        • Status of the integration (e.g., "success").
  • meta: object
    • Additional metadata related to the session. Basically everything that was sent as a request when creating the session

Example:

Full Payload Example:

{
  "created_at": "2023-01-01T12:00:00Z",
  "api_version": "v1",
  "group_type": "WidgetEvent",
  "event_type": "session.submitted",
  "data": {
    "sessionId": "52nmBydtBQpGYjXGWXu3",
    "date": "2023-01-01T12:00:00Z",
    "integrations": [
      {
        "key": "brokerDirect",
        "id": "750800",
        "reference": "MIS/708194",
        "name": "Broker Direct",
        "status": "success"
      }
    ],
    "meta": {
      // everything that was sent as a request when creating the session
      "contact": {
        "phone": "123-456-7890",
        "email": "contact@example.com"
      },
      "policy": {
        "provider": "ABC Insurance",
        "number": "P12345",
        "validTo": "2001-01-01",
        "validFrom": "2000-01-01",
        "vehicle": {
          "licensePlate": "XYZ-123"
        },
        "holder": {
          "phone": "987-654-3210",
          "email": "user@example.com",
          "firstName": "John",
          "lastName": "Doe"
        },
        "linkedContacts": [
          {
            "firstName": "Jane",
            "lastName": "Doe",
            "email": "jane.doe@test.com"
          },
          {
            "firstName": "Test",
            "lastName": "User",
            "email": "test@test.com"
          }
        ]
      },
      "currentUserId": "test-123",
      "privacyPolicyUrl": "https://example.com/privacy-policy"
    }
  }
}

Implementation Example:

Node.js (Javascript)
const crypto = require('crypto');
const express = require('express');

const API_SECRET = 'wh_sec_YOUR_WEBHOOK_SECRET';

const app = express();

app.use(
  express.json({
    verify: (req, res, buffer) => {
      req.rawBody = buffer;
    },
  })
);

app.post('/', (req, res) => {
  const signature = generateSignature(req.method, req.url, req.headers['x-aw-timestamp'], req.rawBody);

  if (signature !== req.headers['x-aw-signature']) {
    return res.sendStatus(401);
  }

  console.log('Received webhook', req.body);
  res.sendStatus(200);
});

app.listen(9000, () => console.log('Node.js server started on port 9000.'));

function generateSignature(method, url, timestamp, body) {
  const hmac = crypto.createHmac('SHA256', API_SECRET);

  hmac.update(`${method.toUpperCase()}${url}${timestamp}`);

  if (body) {
    hmac.update(body);
  }

  return hmac.digest('hex');
}

This Node.js example demonstrates how to create an HTTP endpoint to receive webhook events, verify the request signature, process the event payload, and respond with a success status code.

Now you're ready to receive Axitech Widget Webhook Events in your app! ๐Ÿš€