Extracta.ai
DashboardJoin Discord
  • extracta.ai
    • Introduction
    • Overview
  • API Reference
    • 🔓Authentication
    • 📁Supported File Types
  • Data Extraction - API
    • đŸ’ģAPI Endpoints - Data Extraction
      • 1. Create extraction
      • 2. View extraction
      • 3. Update extraction
      • 4. Delete extraction
      • 5. Upload Files
      • 6. Get results
    • Extraction Details
      • 🌎Supported Languages
      • âš™ī¸Options
      • 📋Fields
    • Polling vs Webhook
    • ❌Webhook (LEGACY)
    • 🆕Webhook
    • 🆕Webhook Event Types
    • đŸ•šī¸Postman Integration
  • Document Classification - API
    • đŸ’ģAPI Endpoints - Document Classification
      • 1. Create classification
      • 2. View classification
      • 3. Update classification
      • 4. Delete data
        • 4.1 Delete classification
        • 4.2 Delete batch
        • 4.3 Delete files
      • 5. Upload Files
      • 6. Get results
    • Classification Details
      • 📄Document Types
  • Documents
    • Custom Document
    • Resume / CV
    • Contract
    • Business Card
    • Email
    • Invoice
    • Receipt
    • Bank Statement
  • Support
    • 💁Tutorials
    • đŸŸĸAPI Status
  • Contact
    • 📧Contact Us
    • ❓FAQ
Powered by GitBook
On this page
  • Webhook Payload Structure
  • See all event types
  • Prerequisites
  • Step 1: Set Up Your Server
  • Step 2: Implement Webhook Endpoint
  • Step 3: Test Your Webhook Listener

Was this helpful?

  1. Data Extraction - API

Webhook

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


Webhook Payload Structure

Each webhook sent by Extracta.ai will include two primary fields in the request body:

  • event – A string identifying the type of event (e.g., extraction.processed, extraction.failed).

  • result – A list containing files data

Example payload:

{
  "event": "extraction.processed",
  "result": [
    {
      "extractionId": "extractionId",
      "batchId": "batchId",
      "fileId": "fileId",
      "fileName": "fileName",
      "status": "processed",
      "result": {},
      "url": "fileUrl"
    }
  ]
}

See all event types


Prerequisites

  • Node.js installed on your server

  • An Express.js application

  • A secret key obtained from the Extracta.ai 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:

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:

server.js
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 signatureRequest = req.headers["x-webhook-signature"];

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

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

    return next();
}

// Webhook endpoint
app.post('/webhook', validateSignature, async (req, res) => {
    try {
        let { event, result } = req.body;

        switch (event) {
            case "extraction.processed":
                console.log("extraction.processed", result);
                break;
            case "extraction.edited":
                console.log("extraction.edited", result);
                break;
            case "extraction.confirmed":
                console.log("extraction.confirmed", result);
                break;
            case "extraction.failed":
                console.log("extraction.failed", result);
                break;
            default:
                console.log("unknown event", event);
                break;
        }

        return res.send({
            event: event,
            message: "Webhook received",
            timestamp: new Date().toISOString()
        })
    } catch (error) {
        console.error("Error processing webhook", error);

        return res.status(500).send({
            message: "Error processing webhook",
            error: error.message,
            timestamp: new Date().toISOString()
        });
    }
})

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

Step 3: Test Your Webhook Listener

Once your webhook listener is set up, test it by triggering events from Extracta.ai. Confirm that:

  • The signature is validated correctly.

  • The event is identified.

  • The result is handled based on the event type.


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

PreviousWebhook (LEGACY)NextWebhook Event Types

Last updated 6 days ago

Was this helpful?

🆕
🆕Webhook Event Types