# Webhook (LEGACY)

## **Legacy Webhook Notice**

You are currently using an older version of the Extracta LABS webhook listener.

This version is still **functional**, but it does **not support newer features** such as event types and structured payload handling ([Webhook Event Types](/data-extraction-api/webhook-event-types.md)). To access the latest improvements, we recommend upgrading your webhook integration.

👉 Visit the **API page** in your **Extracta** **LABS dashboard** to update your webhook listener to the latest version. Upgrading ensures you get the most accurate, flexible, and future-proof webhook experience.

This is the new webhook: [Webhook](/data-extraction-api/webhook.md)

***

## Description

Webhooks allow you to receive real-time notifications of events happening within your Extracta  LABS extractions. This section will guide you through setting up a Node.js server with Express to listen for and handle webhook events securely.

***

## Prerequisites

* Node.js installed on your server
* An Express.js application
* A secret key obtained from the Extracta LABS dashboard

***

## Step 1: Set Up Your Server

First, ensure you have Express and the necessary packages installed in your project. If not, you can install them using npm:

```bash
npm install express body-parser crypto --save
```

***

## Step 2: Implement Webhook Endpoint

Create a basic HTTP server with Express to listen for webhook POST requests. Use the following code snippet as a starting point:

{% code title="server.js" lineNumbers="true" fullWidth="false" %}

```javascript
const express = require('express');
const crypto = require('crypto');
const bodyParser = require('body-parser');

const app = express();
const port = 4000;

app.use(bodyParser.json());

// Your webhook secret key from the dashboard
const secret = 'secretKey';

// Middleware to validate the webhook signature
function validateSignature(req, res, next) {
  const sigHeader = req.headers["x-webhook-signature"];

  const signature = crypto.createHmac('sha256', secret.replace('E_AI_K_', '')).update(req.body.result).digest('base64');

  if (signature !== sigHeader) {
    return res.status(401).send({ message: "Webhook is not properly signed" })
  }

  next()
}

// Webhook endpoint
app.post('/webhook', validateSignature, (req, res) => {
  console.log('Webhook received:', req.body);
  
  // Process the webhook payload as needed
  // ...

  res.send({ message: "Webhook received" })
})

app.listen(port, () => console.log(`Server listening on port ${port}!`))
```

{% endcode %}

***

## Step 3: Test Your Webhook Listener

After setting up your webhook listener, test it by sending a simulated files. Ensure your server validates the signature and processes the event correctly.

***

By following these steps, you can securely set up your application to receive and process webhook events from Extracta LABS, enabling real-time updates and actions based on the events transmitted to your endpoint.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.extracta.ai/data-extraction-api/webhook-legacy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
