{
  "name": "GST Reconciliation Agent (AllPDFMagic + n8n)",
  "nodes": [
    {
      "parameters": {
        "content": "## GST Reconciliation Agent\nRuns monthly, compares your purchase register against your GSTR-2B export, and emails you a plain summary of what doesn't match.\n\n**Setup:**\n1. Add your AllPDFMagic API credential (Developer plan or above — get a key at allpdfmagic.com/dashboard/api) to the *Reconcile Documents* node.\n2. Swap the two 'Load (sample)' nodes for wherever your files actually live — Google Drive, Dropbox, an email attachment, etc. They just need to output binary PDF data under the 'data' property (the default for most file-source nodes).\n3. Add your Gmail credential to the *Notify Accountant* node and set the recipient.\n4. Adjust the schedule (defaults to the 1st of every month, 9am).\n\nThe reconciliation matching itself is deterministic (GSTIN + invoice number + amount) — nothing here is LLM-guessed. If you want a natural-language summary on top of the JSON report, drop an LLM node between *Reconcile Documents* and *Notify Accountant* and prompt it with the JSON output — just don't let it touch the numbers, only the wording.",
        "height": 440,
        "width": 460
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000001",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-900, -460]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 1 * *"
            }
          ]
        }
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000002",
      "name": "Monthly Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [-900, 0]
    },
    {
      "parameters": {
        "operation": "read",
        "fileSelector": "/data/purchase_register.pdf",
        "options": {}
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000003",
      "name": "Load Purchase Register (sample)",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [-640, -120],
      "notes": "Replace with a Google Drive / Dropbox / email-attachment node. Must output the PDF as binary data under property 'data'."
    },
    {
      "parameters": {
        "operation": "read",
        "fileSelector": "/data/gstr2b_export.pdf",
        "options": {}
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000004",
      "name": "Load GSTR-2B Export (sample)",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [-640, 140],
      "notes": "Replace with wherever you download your GSTR-2B JSON/PDF export from the GST portal. Must output binary data under property 'data'."
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $input.all().map(item => ({\n  json: item.json,\n  binary: { data2: item.binary.data },\n}));"
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000005",
      "name": "Rename GSTR-2B Binary Key",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-400, 140],
      "notes": "Both file sources default to binary property 'data'. This renames the second file to 'data2' so the Merge node below can combine them into one item without a key collision."
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000006",
      "name": "Combine Into One Item",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [-160, 0]
    },
    {
      "parameters": {
        "operation": "reconcileDocuments",
        "binaryPropertyNames": "data,data2",
        "reconciliationType": "auto"
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000007",
      "name": "Reconcile Documents",
      "type": "n8n-nodes-allpdfmagic.allPdfMagic",
      "typeVersion": 1,
      "position": [80, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "a1e6c2d0-0001-4a1b-9c1d-000000000008",
              "leftValue": "={{ $json.unmatched_items }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000009",
      "name": "Any Mismatches?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [320, 0]
    },
    {
      "parameters": {
        "sendTo": "accountant@example.com",
        "subject": "=GSTR-2B Reconciliation — {{ $json.unmatched_items }} item(s) need review",
        "message": "=Reconciliation ran against: {{ $json.documents.join(', ') }}\n\nMatched: {{ $json.matched_items }} / {{ $json.total_items }}\nUnmatched: {{ $json.unmatched_items }}\nDiscrepancies found: {{ $json.report.summary.discrepancies_found }}\nStatus: {{ $json.report.status }}\n\nItems only in your purchase register (booked but missing from GSTR-2B — ITC at risk):\n{{ JSON.stringify($json.only_in_document1, null, 2) }}\n\nItems only in GSTR-2B (in 2B but not booked):\n{{ JSON.stringify($json.only_in_document2, null, 2) }}\n\n— Sent automatically by your AllPDFMagic + n8n reconciliation agent.",
        "options": {}
      },
      "id": "a1e6c2d0-0001-4a1b-9c1d-000000000010",
      "name": "Notify Accountant",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [560, -80]
    }
  ],
  "connections": {
    "Monthly Schedule": {
      "main": [
        [
          { "node": "Load Purchase Register (sample)", "type": "main", "index": 0 },
          { "node": "Load GSTR-2B Export (sample)", "type": "main", "index": 0 }
        ]
      ]
    },
    "Load Purchase Register (sample)": {
      "main": [
        [
          { "node": "Combine Into One Item", "type": "main", "index": 0 }
        ]
      ]
    },
    "Load GSTR-2B Export (sample)": {
      "main": [
        [
          { "node": "Rename GSTR-2B Binary Key", "type": "main", "index": 0 }
        ]
      ]
    },
    "Rename GSTR-2B Binary Key": {
      "main": [
        [
          { "node": "Combine Into One Item", "type": "main", "index": 1 }
        ]
      ]
    },
    "Combine Into One Item": {
      "main": [
        [
          { "node": "Reconcile Documents", "type": "main", "index": 0 }
        ]
      ]
    },
    "Reconcile Documents": {
      "main": [
        [
          { "node": "Any Mismatches?", "type": "main", "index": 0 }
        ]
      ]
    },
    "Any Mismatches?": {
      "main": [
        [
          { "node": "Notify Accountant", "type": "main", "index": 0 }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
