Skip to main content

Invoice Extraction Workflow

Automated extraction of supplier invoice data from bulk-scanned PDF documents using Claude AI Vision.

System: Invoice Extraction Server (Node.js + Claude API) Integration: Zoho Creator → Extraction Server → Zoho Creator Processing time: ~2-5 minutes per bulk PDF (depends on page count)


Overview

The invoice extraction workflow processes bulk-scanned PDFs from Australian auto parts suppliers, automatically splitting them into individual invoices and extracting structured data for matching against purchase orders.

What It Extracts

FieldDescriptionExample
supplier_nameSupplier/vendor name"Australian Automotive Group"
invoice_numberInvoice identifier"INV-2024-12345"
customer_accountCrashClaim's account number"ACC12345"
po_numberPurchase order reference"PO-2024-001"
invoice_dateInvoice date"15/07/2026"
vehicle_id / regoVehicle registration"ABC123"
sub_totalSubtotal excluding GST450.50
invoice_totalTotal including GST495.55
freightFreight/delivery charge12.00
line_items[]Array of invoice line itemsSee below

Line Item Structure:

  • description - Part description
  • part_number - Manufacturer part number
  • quantity - Quantity ordered
  • unit_list - List price ex GST
  • unit_net - Net price ex GST (expected)
  • total - Line total ex GST

Process Flow

graph TD
A[User uploads bulk PDF to Zoho] --> B[Zoho Creator webhook triggers]
B --> C[Extraction Server: Download PDF]
C --> D[Split PDF into pages]
D --> E[Detect blank pages]
E --> F[Group pages into invoices]
F --> G[Extract data with Claude Vision]
G --> H[Validate extracted data]
H --> I[Send data to Zoho API]
I --> J[Zoho creates/updates records]
J --> K[Send push notification]
K --> L[Complete]

Step-by-Step Process

1. File Upload & Trigger

Who: Parts team, Claims handlers Where: Zoho Creator → Upload Parts/Order Invoice report What happens:

  • User uploads bulk-scanned PDF containing multiple invoices
  • Zoho Creator webhook fires immediately
  • Webhook payload includes:
    • Record ID
    • File URL
    • Environment (dev/production)

2. PDF Download

System: Invoice Extraction Server What happens:

  • Server downloads PDF from Zoho Creator using OAuth token
  • Saves to temporary directory: temp/{job_id}/
  • Retry mechanism: 3 attempts with 3-second intervals

:::info Retry Logic If the download fails (network error, timeout, etc.), the server automatically retries up to 3 times with a 3-second delay between attempts. This handles transient network issues without manual intervention. :::

3. PDF Processing

Technology: pdf2pic + GraphicsMagick What happens:

  • PDF split into individual page images (PNG format)
  • Each page converted to high-resolution image for Vision AI
  • Blank pages detected using pixel analysis
  • Output: Array of page images in temp/{job_id}/pages/

4. Invoice Grouping

Algorithm: Sequential page analysis What happens:

  • Analyzes page patterns to identify invoice boundaries
  • Groups consecutive pages belonging to same invoice
  • Tracks page ranges: {invoiceNumber: 1, startPage: 1, endPage: 3}

5. Data Extraction (Claude Vision)

Model: Claude Opus 4 (Anthropic) What happens:

  • Each invoice (group of pages) sent to Claude Vision API
  • AI extracts all header fields and line items
  • Returns structured JSON matching schema
  • No retry mechanism - single attempt per invoice

Prompt engineering:

  • Supplier-specific extraction rules
  • Australian invoice format handling
  • GST calculation validation
  • Part number normalization

6. Data Validation

Checks performed:

  • Required fields present (supplier, invoice number, total)
  • Date format validation (dd/MM/yyyy)
  • Numeric field validation (totals, quantities)
  • GST calculation verification (10% of subtotal)
  • Line item total = sum of all line totals

7. Send to Zoho API

Endpoint: Custom Zoho Creator API Environment-aware:

  • Development: dev_invoice_extraction
  • Production: Invoice_Extraction_Integration

Payload:

{
"record_id": "1234567890",
"invoice_number": "Invoice_1",
"page_count": 3,
"start_page": 1,
"end_page": 3,
"extraction_success": true,
"supplier_name": "Australian Automotive Group",
"customer_account": "ACC12345",
"po_number": "PO-2024-001",
"invoice_date": "15/07/2026",
"freight": 12.00,
"vehicle_id": "ABC123",
"rego": "ABC123",
"sub_total": 450.50,
"invoice_total": 495.55,
"line_items": [...]
}

No retry mechanism - single attempt

8. Zoho Record Creation

What happens in Zoho:

  • Creates individual invoice record per extracted invoice
  • Links to original bulk upload record
  • Stores extracted data in structured fields
  • Updates bulk upload status to "completed"

9. Push Notification

Trigger: After all invoices processed Who gets notified: Parts team Channel: Zoho notification system


Error Handling

Error TypeHandling
File download failureRetry 3 times with 3s delay, then fail job
PDF processing errorMark invoice as failed, continue with others
Claude API errorMark invoice as failed, log error, no retry
Zoho API errorMark invoice as failed, log error, no retry
Validation failureMark as failed with validation errors

:::caution No Automatic Retries for AI/API Calls Claude API calls and Zoho API calls do NOT have automatic retry mechanisms. If these fail, the invoice is marked as failed and requires manual review. :::


Environment Configuration

The system supports two environments:

EnvironmentZoho APIUse Case
Developmentdev_invoice_extractionTesting, UAT
ProductionInvoice_Extraction_IntegrationLive processing

Environment is specified in the webhook payload.


Monitoring & Status Tracking

Job Status Endpoint: GET /api/jobs/:job_id

Status values:

  • processing - Extraction in progress
  • completed - All invoices processed successfully
  • failed - Critical error occurred

Progress tracking:

  • Total invoices detected
  • Invoices processed so far
  • Invoices failed
  • Current step description

Temporary File Cleanup

When: After job completion (success or failure) What: Deletes entire temp/{job_id}/ directory Why: Prevent disk space issues, remove sensitive data


Best Practices

For Parts Team

  1. Scan quality matters - Clear, high-contrast scans extract better
  2. One supplier per PDF - Better grouping accuracy
  3. Remove blank pages - Faster processing
  4. Check extraction results - Review failed invoices manually

For IT/Developers

  1. Monitor logs - CloudWatch/server logs show extraction issues
  2. Failed invoice review - Manual intervention needed for extraction failures
  3. API rate limits - Claude API has rate limits, batch uploads carefully
  4. Test in dev first - Always test bulk uploads in development environment

Troubleshooting

Common Issues

IssueCauseSolution
File download fails after 3 retriesZoho API timeout, invalid URLCheck Zoho file URL, verify OAuth token
All invoices fail extractionClaude API key invalid/expiredVerify ANTHROPIC_API_KEY in environment
Wrong invoice groupingPoor scan quality, missing pagesRescan with higher quality, include all pages
Missing line itemsLow image resolutionIncrease scan DPI to 300+
Zoho API errorsWrong environment, invalid payloadCheck environment setting, verify API keys

Technical Details

Server: Node.js 20 + Express Deployment: Docker container on EC2 Image: AWS ECR (invoice-extraction-server:latest) Dependencies:

  • @anthropic-ai/sdk - Claude AI API
  • pdf2pic - PDF to image conversion
  • sharp - Image processing
  • axios - HTTP client
  • pdf-lib - PDF manipulation

Resource requirements:

  • Memory: 2GB minimum
  • Disk: 10GB temporary storage
  • Network: Stable connection to Zoho + Anthropic APIs


For technical support or issues, contact the development team.