Skip to content
cccskills
FreePublished on GitHub

extract-customs-declarations-to-spreadsheet

Extract HS codes, declared values, and duty amounts from customs declaration documents, then generate an XLSX import duty log.

The English summary is being prepared. Showing the original description.

Works withn8n
See how to install

Files included (1)

  • SKILL.md24.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Extract Customs Declarations to Spreadsheet

Import operations and trade compliance teams receive customs declaration documents for every inbound shipment and need to log HS codes, declared values, and duty amounts for compliance reporting and cost reconciliation. This pipeline extracts the key fields from each declaration and writes them into a formatted XLSX duty tracker.

APIs Used

Document Extraction (1 credit per page), Sheet Generation (1 credits/request)

Prerequisites

You need an Iteration Layer API key. Get one at platform.iterationlayer.com during the 7-day trial.

For full integration guidance (SDKs, auth, MCP, error handling), see the Iteration Layer Integration Guide.

Implementation

# Step 1: Extract customs declaration data from all three documents
EXTRACTION=$(curl -s -X POST https://api.iterationlayer.com/document-extraction/v1/extract \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "files": [
      {
        "type": "url",
        "name": "declaration-cn-electronics.pdf",
        "url": "https://example.com/customs/declaration-cn-electronics.pdf"
      },
      {
        "type": "url",
        "name": "declaration-de-machinery.pdf",
        "url": "https://example.com/customs/declaration-de-machinery.pdf"
      },
      {
        "type": "url",
        "name": "declaration-vn-textiles.pdf",
        "url": "https://example.com/customs/declaration-vn-textiles.pdf"
      }
    ],
    "schema": {
      "fields": [
        {
          "name": "declarations",
          "type": "ARRAY",
          "description": "One entry per customs declaration document",
          "fields": [
            { "name": "declaration_number", "type": "TEXT", "description": "Customs declaration reference number" },
            { "name": "declaration_date", "type": "DATE", "description": "Date of customs declaration" },
            { "name": "country_of_origin", "type": "TEXT", "description": "Country where goods were manufactured" },
            { "name": "hs_code", "type": "TEXT", "description": "Harmonized System tariff code" },
            { "name": "goods_description", "type": "TEXT", "description": "Description of imported goods" },
            { "name": "declared_value", "type": "CURRENCY_AMOUNT", "description": "Customs declared value of goods" },
            { "name": "currency", "type": "CURRENCY_CODE", "description": "Currency of declared value" },
            { "name": "duty_amount", "type": "CURRENCY_AMOUNT", "description": "Duty assessed on this declaration" }
          ]
        }
      ]
    }
  }')

# Step 2: Generate XLSX import duty log from the extracted declaration data
curl -X POST https://api.iterationlayer.com/sheet-generation/v1/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "format": "xlsx",
    "styles": {
      "header": {
        "font_family": "Helvetica",
        "font_size_in_pt": 11,
        "is_bold": true,
        "background_color": "#374151",
        "font_color": "#FFFFFF"
      },
      "body": {
        "font_family": "Helvetica",
        "font_size_in_pt": 11,
        "font_color": "#333333"
      }
    },
    "sheets": [
      {
        "name": "Import Duty Log — Q1 2026",
        "columns": [
          { "name": "Declaration #", "width": 18 },
          { "name": "Date", "width": 12 },
          { "name": "Origin", "width": 14 },
          { "name": "HS Code", "width": 14 },
          { "name": "Description", "width": 30 },
          { "name": "Declared Value", "width": 16 },
          { "name": "Duty", "width": 14 },
          { "name": "Currency", "width": 10 }
        ],
        "rows": [
          [
            { "value": "IMP-2026-CN-00841" },
            { "value": "2026-01-14", "format": "date" },
            { "value": "China" },
            { "value": "8471.30" },
            { "value": "Laptop computers and portable data processing machines" },
            { "value": 48750.00, "format": "currency" },
            { "value": 2437.50, "format": "currency" },
            { "value": "USD" }
          ],
          [
            { "value": "IMP-2026-DE-00392" },
            { "value": "2026-02-03", "format": "date" },
            { "value": "Germany" },
            { "value": "8457.10" },
            { "value": "Machining centres for working metal" },
            { "value": 124300.00, "format": "currency" },
            { "value": 0.00, "format": "currency" },
            { "value": "USD" }
          ],
          [
            { "value": "IMP-2026-VN-01175" },
            { "value": "2026-03-07", "format": "date" },
            { "value": "Vietnam" },
            { "value": "6204.62" },
            { "value": "Women's trousers and shorts of cotton" },
            { "value": 18420.00, "format": "currency" },
            { "value": 2947.20, "format": "currency" },
            { "value": "USD" }
          ],
          [
            { "value": "Total" },
            { "value": null },
            { "value": null },
            { "value": null },
            { "value": null },
            { "value": null },
            { "value": null },
            { "value": null }
          ]
        ],
        "formulas": [
          {
            "row": 4,
            "col": 6,
            "expression": "=SUM(F2:F4)"
          },
          {
            "row": 4,
            "col": 7,
            "expression": "=SUM(G2:G4)"
          }
        ]
      }
    ]
  }'
import { IterationLayer } from "iterationlayer";
const client = new IterationLayer({ apiKey: "YOUR_API_KEY" });

// Step 1: Extract customs declaration data from all three documents
const extraction = await client.extractDocument({
  files: [
    {
      type: "url",
      name: "declaration-cn-electronics.pdf",
      url: "https://example.com/customs/declaration-cn-electronics.pdf",
    },
    {
      type: "url",
      name: "declaration-de-machinery.pdf",
      url: "https://example.com/customs/declaration-de-machinery.pdf",
    },
    {
      type: "url",
      name: "declaration-vn-textiles.pdf",
      url: "https://example.com/customs/declaration-vn-textiles.pdf",
    },
  ],
  schema: {
    fields: [
      {
        name: "declarations",
        type: "ARRAY",
        description: "One entry per customs declaration document",
        fields: [
          {
            name: "declaration_number",
            type: "TEXT",
            description: "Customs declaration reference number",
          },
          {
            name: "declaration_date",
            type: "DATE",
            description: "Date of customs declaration",
          },
          {
            name: "country_of_origin",
            type: "TEXT",
            description: "Country where goods were manufactured",
          },
          {
            name: "hs_code",
            type: "TEXT",
            description: "Harmonized System tariff code",
          },
          {
            name: "goods_description",
            type: "TEXT",
            description: "Description of imported goods",
          },
          {
            name: "declared_value",
            type: "CURRENCY_AMOUNT",
            description: "Customs declared value of goods",
          },
          {
            name: "currency",
            type: "CURRENCY_CODE",
            description: "Currency of declared value",
          },
          {
            name: "duty_amount",
            type: "CURRENCY_AMOUNT",
            description: "Duty assessed on this declaration",
          },
        ],
      },
    ],
  },
});

const declarations = extraction.declarations.value as Array<
  Record<string, { value: unknown }>
>;

// Step 2: Generate XLSX import duty log from the extracted declaration data
const sheet = await client.generateSheet({
  format: "xlsx",
  styles: {
    header: {
      font_family: "Helvetica",
      font_size_in_pt: 11,
      is_bold: true,
      background_color: "#374151",
      font_color: "#FFFFFF",
    },
    body: {
      font_family: "Helvetica",
      font_size_in_pt: 11,
      font_color: "#333333",
    },
  },
  sheets: [
    {
      name: "Import Duty Log — Q1 2026",
      columns: [
        { name: "Declaration #", width: 18 },
        { name: "Date", width: 12 },
        { name: "Origin", width: 14 },
        { name: "HS Code", width: 14 },
        { name: "Description", width: 30 },
        { name: "Declared Value", width: 16 },
        { name: "Duty", width: 14 },
        { name: "Currency", width: 10 },
      ],
      rows: [
        ...declarations.map((declaration) => [
          { value: String(declaration.declaration_number.value) },
          { value: String(declaration.declaration_date.value), format: "date" },
          { value: String(declaration.country_of_origin.value) },
          { value: String(declaration.hs_code.value) },
          { value: String(declaration.goods_description.value) },
          {
            value: (declaration.declared_value.value as { amount: string })
              .amount,
            format: "currency",
          },
          {
            value: (declaration.duty_amount.value as { amount: string }).amount,
            format: "currency",
          },
          { value: String(declaration.currency.value) },
        ]),
        [
          { value: "Total" },
          { value: null },
          { value: null },
          { value: null },
          { value: null },
          { value: null },
          { value: null },
          { value: null },
        ],
      ],
      formulas: [
        {
          row: declarations.length + 1,
          col: 6,
          expression: `=SUM(F2:F${declarations.length + 1})`,
        },
        {
          row: declarations.length + 1,
          col: 7,
          expression: `=SUM(G2:G${declarations.length + 1})`,
        },
      ],
    },
  ],
});
from iterationlayer import IterationLayer
client = IterationLayer(api_key="YOUR_API_KEY")

# Step 1: Extract customs declaration data from all three documents
extraction = client.extract_document(
    files=[
        {
            "type": "url",
            "name": "declaration-cn-electronics.pdf",
            "url": "https://example.com/customs/declaration-cn-electronics.pdf",
        },
        {
            "type": "url",
            "name": "declaration-de-machinery.pdf",
            "url": "https://example.com/customs/declaration-de-machinery.pdf",
        },
        {
            "type": "url",
            "name": "declaration-vn-textiles.pdf",
            "url": "https://example.com/customs/declaration-vn-textiles.pdf",
        },
    ],
    schema={
        "fields": [
            {
                "name": "declarations",
                "type": "ARRAY",
                "description": "One entry per customs declaration document",
                "fields": [
                    {"name": "declaration_number", "type": "TEXT", "description": "Customs declaration reference number"},
                    {"name": "declaration_date", "type": "DATE", "description": "Date of customs declaration"},
                    {"name": "country_of_origin", "type": "TEXT", "description": "Country where goods were manufactured"},
                    {"name": "hs_code", "type": "TEXT", "description": "Harmonized System tariff code"},
                    {"name": "goods_description", "type": "TEXT", "description": "Description of imported goods"},
                    {"name": "declared_value", "type": "CURRENCY_AMOUNT", "description": "Customs declared value of goods"},
                    {"name": "currency", "type": "CURRENCY_CODE", "description": "Currency of declared value"},
                    {"name": "duty_amount", "type": "CURRENCY_AMOUNT", "description": "Duty assessed on this declaration"},
                ],
            }
        ]
    },
)

declarations = extraction["declarations"]["value"]

# Step 2: Generate XLSX import duty log from the extracted declaration data
sheet = client.generate_sheet(
    format="xlsx",
    styles={
        "header": {
            "font_family": "Helvetica",
            "font_size_in_pt": 11,
            "is_bold": True,
            "background_color": "#374151",
            "font_color": "#FFFFFF",
        },
        "body": {
            "font_family": "Helvetica",
            "font_size_in_pt": 11,
            "font_color": "#333333",
        },
    },
    sheets=[
        {
            "name": "Import Duty Log — Q1 2026",
            "columns": [
                {"name": "Declaration #", "width": 18},
                {"name": "Date", "width": 12},
                {"name": "Origin", "width": 14},
                {"name": "HS Code", "width": 14},
                {"name": "Description", "width": 30},
                {"name": "Declared Value", "width": 16},
                {"name": "Duty", "width": 14},
                {"name": "Currency", "width": 10},
            ],
            "rows": [
                *[
                    [
                        {"value": declaration["declaration_number"]["value"]},
                        {"value": declaration["declaration_date"]["value"], "format": "date"},
                        {"value": declaration["country_of_origin"]["value"]},
                        {"value": declaration["hs_code"]["value"]},
                        {"value": declaration["goods_description"]["value"]},
                        {"value": declaration["declared_value"]["value"]["amount"], "format": "currency"},
                        {"value": declaration["duty_amount"]["value"]["amount"], "format": "currency"},
                        {"value": declaration["currency"]["value"]},
                    ]
                    for declaration in declarations
                ],
                [
                    {"value": "Total"},
                    {"value": None},
                    {"value": None},
                    {"value": None},
                    {"value": None},
                    {"value": None},
                    {"value": None},
                    {"value": None},
                ],
            ],
            "formulas": [
                {
                    "row": len(declarations) + 1,
                    "col": 6,
                    "expression": f"=SUM(F2:F{len(declarations) + 1})",
                },
                {
                    "row": len(declarations) + 1,
                    "col": 7,
                    "expression": f"=SUM(G2:G{len(declarations) + 1})",
                },
            ],
        }
    ],
)
package main

import il "github.com/iterationlayer/sdk-go"

func main() {
	client := il.NewClient("YOUR_API_KEY")

	result, err := client.ExtractDocument(il.ExtractDocumentRequest{
		Files: []il.FileInput{
			il.FileInput{
				Type: "url",
				Name: "declaration-cn-electronics.pdf",
				Url: "https://example.com/customs/declaration-cn-electronics.pdf",
			},
			il.FileInput{
				Type: "url",
				Name: "declaration-de-machinery.pdf",
				Url: "https://example.com/customs/declaration-de-machinery.pdf",
			},
			il.FileInput{
				Type: "url",
				Name: "declaration-vn-textiles.pdf",
				Url: "https://example.com/customs/declaration-vn-textiles.pdf",
			},
		},
		Schema: il.ExtractionSchema{
			Fields: []any{
				il.ArrayFieldConfig{
					Name: "declarations",
					Type: "ARRAY",
					Description: "One entry per customs declaration document",
					Fields: []any{
						il.TextFieldConfig{
							Name: "declaration_number",
							Type: "TEXT",
							Description: "Customs declaration reference number",
						},
						il.DateFieldConfig{
							Name: "declaration_date",
							Type: "DATE",
							Description: "Date of customs declaration",
						},
						il.TextFieldConfig{
							Name: "country_of_origin",
							Type: "TEXT",
							Description: "Country where goods were manufactured",
						},
						il.TextFieldConfig{
							Name: "hs_code",
							Type: "TEXT",
							Description: "Harmonized System tariff code",
						},
						il.TextFieldConfig{
							Name: "goods_description",
							Type: "TEXT",
							Description: "Description of imported goods",
						},
						il.CurrencyAmountFieldConfig{
							Name: "declared_value",
							Type: "CURRENCY_AMOUNT",
							Description: "Customs declared value of goods",
						},
						il.CurrencyCodeFieldConfig{
							Name: "currency",
							Type: "CURRENCY_CODE",
							Description: "Currency of declared value",
						},
						il.CurrencyAmountFieldConfig{
							Name: "duty_amount",
							Type: "CURRENCY_AMOUNT",
							Description: "Duty assessed on this declaration",
						},
					},
				},
			},
		},
	})
	if err != nil {
		panic(err)
	}

	_ = result
}
{
  "name": "Extract Customs Declarations to Spreadsheet",
  "nodes": [
    {
      "parameters": {
        "content": "## Extract Customs Declarations to Spreadsheet\n\nImport operations and trade compliance teams receive customs declaration documents for every inbound shipment and need to log HS codes, declared values, and duty amounts for compliance reporting and cost reconciliation. This pipeline extracts the key fields from each declaration and writes them into a formatted XLSX duty tracker.\n\n**Note:** This workflow uses the Iteration Layer community node (`n8n-nodes-iterationlayer`). Install it via Settings > Community Nodes on self-hosted n8n, or add it directly on n8n Cloud with Verified Community Nodes enabled.",
        "height": 280,
        "width": 500,
        "color": 2
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        200,
        40
      ],
      "id": "8719816b-8100-441b-ad4e-4171ae3b585d",
      "name": "Overview"
    },
    {
      "parameters": {
        "content": "### Step 1: Extract Declaration Data\nResource: **Document Extraction**\n\nConfigure the Document Extraction parameters below, then connect your credentials.",
        "height": 160,
        "width": 300,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        475,
        100
      ],
      "id": "883c0bca-0a24-4d06-ba03-8ee134c8a714",
      "name": "Step 1 Note"
    },
    {
      "parameters": {
        "content": "### Step 2: Generate Import Duty Log\nResource: **Sheet Generation**\n\nConfigure the Sheet Generation parameters below, then connect your credentials.",
        "height": 160,
        "width": 300,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        725,
        100
      ],
      "id": "11b08cf6-37c0-414c-b1db-9beed2c32d41",
      "name": "Step 2 Note"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ],
      "id": "4d5e6f7a-8b9c-0123-def0-345678901234",
      "name": "Manual Trigger"
    },
    {
      "parameters": {
        "resource": "documentExtraction",
        "schemaInputMode": "rawJson",
        "schemaJson": "[\n  {\n    \"name\": \"declarations\",\n    \"type\": \"ARRAY\",\n    \"description\": \"One entry per customs declaration document\",\n    \"children\": [\n      {\n        \"name\": \"declaration_number\",\n        \"type\": \"TEXT\",\n        \"description\": \"Customs declaration reference number\"\n      },\n      {\n        \"name\": \"declaration_date\",\n        \"type\": \"DATE\",\n        \"description\": \"Date of customs declaration\"\n      },\n      {\n        \"name\": \"country_of_origin\",\n        \"type\": \"TEXT\",\n        \"description\": \"Country where goods were manufactured\"\n      },\n      {\n        \"name\": \"hs_code\",\n        \"type\": \"TEXT\",\n        \"description\": \"Harmonized System tariff code\"\n      },\n      {\n        \"name\": \"goods_description\",\n        \"type\": \"TEXT\",\n        \"description\": \"Description of imported goods\"\n      },\n      {\n        \"name\": \"declared_value\",\n        \"type\": \"CURRENCY_AMOUNT\",\n        \"description\": \"Customs declared value of goods\"\n      },\n      {\n        \"name\": \"currency\",\n        \"type\": \"CURRENCY_CODE\",\n        \"description\": \"Currency of declared value\"\n      },\n      {\n        \"name\": \"duty_amount\",\n        \"type\": \"CURRENCY_AMOUNT\",\n        \"description\": \"Duty assessed on this declaration\"\n      }\n    ]\n  }\n]",
        "files": {
          "fileValues": [
            {
              "inputMode": "url",
              "fileUrl": "https://example.com/customs/declaration-cn-electronics.pdf"
            },
            {
              "inputMode": "url",
              "fileUrl": "https://example.com/customs/declaration-de-machinery.pdf"
            },
            {
              "inputMode": "url",
              "fileUrl": "https://example.com/customs/declaration-vn-textiles.pdf"
            }
          ]
        }
      },
      "type": "n8n-nodes-iterationlayer.iterationLayer",
      "typeVersion": 1,
      "position": [
        500,
        300
      ],
      "id": "5e6f7a8b-9c0d-1234-ef01-456789012345",
      "name": "Extract Declaration Data",
      "credentials": {
        "iterationLayerApi": {
          "id": "1",
          "name": "Iteration Layer API"
        }
      }
    },
    {
      "parameters": {
        "resource": "sheetGeneration",
        "sheetFormat": "xlsx",
        "sheetsJson": "[\n  {\n    \"name\": \"Import Duty Log \u2014 Q1 2026\",\n    \"columns\": [\n      { \"name\": \"Declaration #\", \"width\": 18 },\n      { \"name\": \"Date\", \"width\": 12 },\n      { \"name\": \"Origin\", \"width\": 14 },\n      { \"name\": \"HS Code\", \"width\": 14 },\n      { \"name\": \"Description\", \"width\": 30 },\n      { \"name\": \"Declared Value\", \"width\": 16 },\n      { \"name\": \"Duty\", \"width\": 14 },\n      { \"name\": \"Currency\", \"width\": 10 }\n    ],\n    \"rows\": \"{{ $json.declarations }}\"\n  }\n]",
        "sheetStylesJson": "{\n  \"header\": {\n    \"font_family\": \"Helvetica\",\n    \"font_size_in_pt\": 11,\n    \"is_bold\": true,\n    \"background_color\": \"#374151\",\n    \"font_color\": \"#FFFFFF\"\n  },\n  \"body\": {\n    \"font_family\": \"Helvetica\",\n    \"font_size_in_pt\": 11,\n    \"font_color\": \"#333333\"\n  }\n}"
      },
      "type": "n8n-nodes-iterationlayer.iterationLayer",
      "typeVersion": 1,
      "position": [
        750,
        300
      ],
      "id": "6f7a8b9c-0d1e-2345-f012-567890123456",
      "name": "Generate Import Duty Log",
      "credentials": {
        "iterationLayerApi": {
          "id": "1",
          "name": "Iteration Layer API"
        }
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Extract Declaration Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Declaration Data": {
      "main": [
        [
          {
            "node": "Generate Import Duty Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
Extract customs declaration data from the files at [file URL 1], [file URL 2], and [file URL 3], then generate an import duty spreadsheet. Use the extract_document tool with these fields:

- declarations (ARRAY): One entry per customs declaration, each with:
  - declaration_number (TEXT): Customs declaration reference number
  - declaration_date (DATE): Date of customs declaration
  - country_of_origin (TEXT): Country where goods were manufactured
  - hs_code (TEXT): Harmonized System tariff code
  - goods_description (TEXT): Description of imported goods
  - declared_value (CURRENCY_AMOUNT): Customs declared value of goods
  - currency (CURRENCY_CODE): Currency of declared value
  - duty_amount (CURRENCY_AMOUNT): Duty assessed on this declaration

Then use the generate_sheet tool to create an XLSX import duty log with the extracted rows.

Response

{
  "success": true,
  "data": {
    "buffer": "UEsDBBQAAAAIAA...",
    "mime_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  }
}

Links

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Resize, sharpen, and compress an image to fit email platform size limits in a single pipeline.

The English summary is being prepared. Showing the original description.

iterationlayer/skills4Updated Jun 9, 2026

Compress an image to fit within a specific file size in bytes using quality-first compression.

The English summary is being prepared. Showing the original description.

iterationlayer/skills4Updated Jun 9, 2026

Convert a contract PDF to clean markdown for clause extraction or LLM analysis.

The English summary is being prepared. Showing the original description.

iterationlayer/skills4Updated Jun 9, 2026

Convert external documents — specs, contracts, reports — to markdown for knowledge base ingestion.

The English summary is being prepared. Showing the original description.

iterationlayer/skills4Updated Jun 9, 2026

Convert a document to clean markdown suitable for chunking and embedding in a RAG pipeline.

The English summary is being prepared. Showing the original description.

iterationlayer/skills4Updated Jun 9, 2026

Convert an image between PNG, JPEG, and WebP formats with quality control for web optimization.

The English summary is being prepared. Showing the original description.

iterationlayer/skills4Updated Jun 9, 2026

See all skills by iterationlayer

Report a problem with this skill