{
  "name": "Enroutia · Extract invoice fields to JSON",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Extract invoice fields",
        "formDescription": "Paste the text of an invoice (from a PDF, an email or OCR). The fields come back as JSON.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Invoice text",
              "fieldType": "textarea",
              "requiredField": true
            },
            {
              "fieldLabel": "Client",
              "placeholder": "Optional: the end client this invoice belongs to"
            }
          ]
        },
        "options": {}
      },
      "name": "Invoice form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "enroutia-invoice-form"
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": "=enroutia/invoices",
        "prompt": "={{ $json['Invoice text'] }}",
        "options": {
          "systemMessage": "You extract fields from invoice text. Return a JSON object with exactly these keys: supplier_name, supplier_tax_id, invoice_number, issue_date (YYYY-MM-DD), due_date (YYYY-MM-DD or null), currency (ISO 4217), subtotal, tax_rate_pct, tax_amount, total (numbers, dot as decimal separator), line_items (array of {description, quantity, unit_price, amount}). Use null for anything the text does not say. Never invent a value.",
          "jsonOutput": true,
          "temperature": 0,
          "maxTokens": 1500,
          "clientTag": "={{ $json.Client || '' }}"
        }
      },
      "name": "Extract fields",
      "type": "n8n-nodes-enroutia.enroutia",
      "typeVersion": 1,
      "position": [
        240,
        0
      ],
      "credentials": {
        "enroutiaApi": {
          "name": "Enroutia account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// The Enroutia node returns the answer as text; with Guaranteed JSON Output on it is\n// always valid JSON (an invalid answer is retried once and billed once).\nreturn $input.all().map((item) => {\n  const parsed = JSON.parse(item.json.text);\n  return { json: { ...parsed, model: item.json.model, resolvedModel: item.json.resolvedModel } };\n});\n"
      },
      "name": "Parse JSON",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        0
      ]
    }
  ],
  "connections": {
    "Invoice form": {
      "main": [
        [
          {
            "node": "Extract fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract fields": {
      "main": [
        [
          {
            "node": "Parse JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
