{
  "name": "Download KSeF (Poland’s e-invoicing system) invoices to an Excel spreadsheet",
  "nodes": [
    {
      "id": "s1",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -768
      ],
      "parameters": {
        "width": 1048,
        "height": 442,
        "content": "## 🇵🇱 KSeF — Download Invoices to Spreadsheet\n\nDownloads invoice metadata from Poland's **KSeF** (Krajowy System e-Faktur) and exports it as an **XLSX spreadsheet**.\n\n### Quick Start\n1. Open the **⚙️ "
      }
    },
    {
      "id": "s2",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -272
      ],
      "parameters": {
        "width": 464,
        "height": 520,
        "content": "## 🔧 Configuration\nEdit the JSON below to set your:\n- **nip** — your 10-digit NIP number\n- **authToken** — KSeF authorization token\n- **startDate / endDate** — ISO 8601 format\n- **subjectType** —\n  `S"
      }
    },
    {
      "id": "s3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -272
      ],
      "parameters": {
        "width": 1884,
        "height": 520,
        "content": "## 🔐 Authentication Flow (v2 API)\nKSeF uses a multi-step auth:\n1. **Get Public Key** — fetch RSA certificate\n2. **Get Challenge** — get a challenge + timestamp\n3. **Encrypt Token** — RSA-OAEP encrypt "
      }
    },
    {
      "id": "s4",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2352,
        -272
      ],
      "parameters": {
        "width": 484,
        "height": 522,
        "content": "## 📊 Output\nInvoice metadata is flattened into columns:\nKSeF Number, Invoice Number, Issue Date, Seller/Buyer NIP & Name, Net/VAT/Gross amounts, Currency, Type.\n\nThe XLSX file is available as binary o"
      }
    },
    {
      "id": "n1",
      "name": "When clicking 'Test workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        0,
        0
      ]
    },
    {
      "id": "n2",
      "name": "⚙️ Config",
      "type": "n8n-nodes-base.set",
      "position": [
        224,
        0
      ]
    },
    {
      "id": "n3",
      "name": "Get Public Key",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        448,
        0
      ]
    },
    {
      "id": "n3b",
      "name": "Get Challenge",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        672,
        0
      ]
    },
    {
      "id": "n4",
      "name": "Encrypt Token",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        0
      ]
    },
    {
      "id": "n5",
      "name": "Init Auth",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1104,
        0
      ]
    },
    {
      "id": "n5a",
      "name": "Wait 2s",
      "type": "n8n-nodes-base.code",
      "position": [
        1328,
        0
      ]
    },
    {
      "id": "n5b",
      "name": "Check Auth Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1552,
        0
      ]
    },
    {
      "id": "n5c",
      "name": "Redeem Token",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1760,
        0
      ]
    },
    {
      "id": "n6",
      "name": "Query Invoices",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1984,
        0
      ]
    },
    {
      "id": "n7",
      "name": "Extract Invoices",
      "type": "n8n-nodes-base.code",
      "position": [
        2208,
        0
      ]
    },
    {
      "id": "n10",
      "name": "Format for Spreadsheet",
      "type": "n8n-nodes-base.code",
      "position": [
        2432,
        0
      ]
    },
    {
      "id": "n11",
      "name": "Write XLSX",
      "type": "n8n-nodes-base.spreadsheetFile",
      "position": [
        2640,
        0
      ]
    },
    {
      "id": "n9",
      "name": "Close Session",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2864,
        0
      ]
    }
  ],
  "connections": {
    "Wait 2s": {
      "main": [
        [
          {
            "node": "Check Auth Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Init Auth": {
      "main": [
        [
          {
            "node": "Wait 2s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write XLSX": {
      "main": [
        [
          {
            "node": "Close Session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redeem Token": {
      "main": [
        [
          {
            "node": "Query Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Encrypt Token": {
      "main": [
        [
          {
            "node": "Init Auth",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Challenge": {
      "main": [
        [
          {
            "node": "Encrypt Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "⚙️ Config": {
      "main": [
        [
          {
            "node": "Get Public Key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Public Key": {
      "main": [
        [
          {
            "node": "Get Challenge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query Invoices": {
      "main": [
        [
          {
            "node": "Extract Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Invoices": {
      "main": [
        [
          {
            "node": "Format for Spreadsheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Auth Status": {
      "main": [
        [
          {
            "node": "Redeem Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format for Spreadsheet": {
      "main": [
        [
          {
            "node": "Write XLSX",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Test workflow'": {
      "main": [
        [
          {
            "node": "⚙️ Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}