Conversion Events

Webhooks for document processing with structured data extraction

Conversion Webhooks

Conversion webhooks are sent during document processing when using a specific document type to extract structured data.

Conversion Events

Conversion Started (CONVERSION_STARTED)

Sent when document processing begins:

{
  "conversion_id": "clm123abc456def",
  "status": "PROCESSING",
  "request_timestamp": "2024-01-15T10:30:00.000Z",
  "document_type_code": "invoice",
  "original_filename": "invoice-001.pdf",
  "document_metadata": {
    "client_id": "ABC123",
    "department": "finance"
  }
}

Fields:

  • conversion_id (string): Unique conversion ID
  • status (string): Current status, always "PROCESSING" for this event
  • request_timestamp (string): ISO 8601 timestamp of when conversion started
  • document_type_code (string): Code of the document type used
  • original_filename (string, optional): Original name of the processed file
  • document_metadata (object, optional): Custom metadata sent with the conversion

Conversion Completed (CONVERSION_COMPLETED)

Sent when conversion finishes successfully:

{
  "conversion_id": "clm123abc456def",
  "status": "SUCCESS",
  "request_timestamp": "2024-01-15T10:30:00.000Z",
  "response_timestamp": "2024-01-15T10:30:15.000Z",
  "document_type_code": "invoice",
  "original_filename": "invoice-001.pdf",
  "document_metadata": {
    "client_id": "ABC123",
    "department": "finance"
  },
  "data": {
    "invoiceNumber": "INV-2024-001",
    "amount": 1250.00,
    "vendor": "ABC Company Inc.",
    "date": "2024-01-15"
  }
}

Fields:

  • conversion_id (string): Unique conversion ID
  • status (string): Current status, always "SUCCESS" for this event
  • request_timestamp (string): ISO 8601 timestamp of when conversion started
  • response_timestamp (string): ISO 8601 timestamp of when conversion completed
  • document_type_code (string): Code of the document type used
  • original_filename (string, optional): Original name of the processed file
  • document_metadata (object, optional): Custom metadata sent with the conversion
  • data (object): Extracted data from the document according to the document type schema

Conversion Failed (CONVERSION_FAILED)

Sent when conversion fails:

{
  "conversion_id": "clm123abc456def",
  "status": "ERROR",
  "request_timestamp": "2024-01-15T10:30:00.000Z",
  "response_timestamp": "2024-01-15T10:30:10.000Z",
  "document_type_code": "invoice",
  "original_filename": "invoice-001.pdf",
  "document_metadata": {
    "client_id": "ABC123",
    "department": "finance"
  },
  "error": "Error during OCR processing: Unable to process image"
}

Fields:

  • conversion_id (string): Unique conversion ID
  • status (string): Current status, always "ERROR" for this event
  • request_timestamp (string): ISO 8601 timestamp of when conversion started
  • response_timestamp (string): ISO 8601 timestamp of when conversion failed
  • document_type_code (string): Code of the document type used
  • original_filename (string, optional): Original name of the processed file
  • document_metadata (object, optional): Custom metadata sent with the conversion
  • error (string): Descriptive error message

Implementation Example

app.post('/webhooks/docutray', (req, res) => {
  const eventType = req.headers['x-docutray-event'];
  const data = JSON.parse(req.body);

  switch (eventType) {
    case 'CONVERSION_STARTED':
      console.log(`Conversion started: ${data.conversion_id}`);
      // Update database with "processing" status
      break;

    case 'CONVERSION_COMPLETED':
      console.log(`Conversion completed: ${data.conversion_id}`);
      console.log('Extracted data:', data.data);
      // Save extracted data to database
      // Send notification to user
      break;

    case 'CONVERSION_FAILED':
      console.log(`Conversion failed: ${data.conversion_id}`);
      console.log('Error:', data.error);
      // Log error and notify user
      break;
  }

  res.status(200).send('OK');
});

On this page