n8n / Implementation guide

n8n customs-manifest parsing for CargoWise operations

n8n can receive customs documents, use the OpenAI Vision API where visual extraction is needed, ask an approved Claude model to propose structured fields, and stage validated records for CargoWise TMS. The valuable boundary is between extraction and declaration: a plausible JSON object is not proof that tariff classification, shipment totals or customs requirements are correct. Preserve source-page evidence and hold exceptions for a licensed or authorized operator.

Tools: n8n; Claude 3.5 Sonnet, OpenAI Vision API, CargoWise TMS
01

The industry-specific problem

A manifest may mix kilograms and pounds, merge header cells, repeat invoice totals on each page, or render a container number as an image. Copying these values manually delays clearance; blindly importing them can create a more expensive declaration error.

02

Step-by-step workflow

  1. Ingest PDF attachments in n8n into a restricted document store; record a content hash and document type.
  2. Extract searchable text first. Route image-only pages to the OpenAI Vision API only when the data-sharing arrangement permits it.
  3. Ask a currently supported Claude model for typed candidate fields and page references; the requested Claude 3.5 Sonnet label is a legacy requirement to verify, not a guaranteed runtime.
  4. Validate units, decimal precision, invoice sums, container-number checks and mandatory fields against a versioned CargoWise/EDI mapping.
  5. Import through your approved CargoWise interface or adapter. Queue unsupported schemas and conflicting source evidence for operator review; retain the original document.
03

Visual workflow

PDF hash → text extraction
  image page → OpenAI Vision → Claude candidate schema
  text page → Claude candidate schema
→ unit/totals validation → CargoWise staging OR customs review
04

Specific configuration example

This n8n Code-node fragment consumes a normalized, authenticated event from preceding integration steps. It demonstrates the decision boundary, not a complete API client. Fields are workflow-local mappings, not claimed vendor field names. Upstream credentials, schema validation, permissions, durable reservations and provider operations must be implemented separately. Numeric policy examples are illustrative, not Imperio service terms.

// n8n Code node: no silent mass-unit conversion
const manifest = $json;
const lines = manifest.lines ?? [];
const issues = [];
for (const line of lines) {
  if (line.weight_unit !== "KG") issues.push(`unit:${line.source_page}`);
  if (!line.hs_code_verified) issues.push(`classification:${line.source_page}`);
}
const sum = lines.reduce((n, x) => n + Number(x.invoice_value_minor), 0);
if (sum !== manifest.invoice_total_minor) issues.push("invoice_total_mismatch");
return [{ json: { ...manifest, importReady: issues.length === 0, issues } }];
05

Outcome to measure

Illustrative planning metrics only. Not verified client results.

Measure operator touch time per manifest, first-pass acceptance and amendment frequency. Illustrative baseline: reducing review from 12 to five minutes across 200 manifests saves about 23 hours, only if amendment rates do not worsen.

06

Compared with manual work or other tools

Template OCR is strong for stable supplier layouts. Claude-assisted extraction handles variation better but requires validation and evidence. A dedicated EDI integration remains preferable when a shipper already provides reliable structured data.

07

Work with Imperio Automation

Send Imperio anonymized manifest layouts and your approved CargoWise import specification for an exception-first parsing assessment.

Scope this workflow
08

Frequently asked questions

Can the model choose tariff codes?

It may propose candidates with source evidence, but classification needs an authorized verification process before filing.

What if a manifest repeats totals on every page?

Tag document-level totals separately from line values and reject double-counted sums.

Does valid JSON mean valid EDI?

No. Field lengths, code lists, required segments and partner-specific mappings need deterministic checks.

09

Technical and regulatory references