{
  "id": "bulk-payment-reminders-nocodb",
  "name": "A05: Bulk Generate Payment Reminder PDFs from NocoDB and Email as ZIP",
  "tags": [],
  "nodes": [
    {
      "id": "2c511a10-6407-49cc-8c4e-27af2ba99e40",
      "name": "Weekly Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        2464,
        1376
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ]
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "02203b42-9e35-40f9-8a49-c26f892612d8",
      "name": "Get Overdue Invoices",
      "type": "n8n-nodes-base.nocoDb",
      "position": [
        2704,
        1376
      ],
      "parameters": {
        "table": "YOUR_TABLE_ID",
        "options": {},
        "operation": "getAll",
        "projectId": "YOUR_NOCODB_BASE_ID",
        "returnAll": true,
        "authentication": "nocoDbApiToken"
      },
      "credentials": {
        "nocoDbApiToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "f9a88e7f-c613-4d77-a358-b41dbe7b1f70",
      "name": "Build Bulk Items",
      "type": "n8n-nodes-base.code",
      "position": [
        2928,
        1376
      ],
      "parameters": {
        "jsCode": "const rows = $input.all();\nconst today = new Date();\ntoday.setHours(0, 0, 0, 0);\n\nconst items = rows.map(row => {\n  const dueDate = new Date(row.json.due_date);\n  const diffMs = today.getTime() - dueDate.getTime();\n  const daysOverdue = Math.max(0, Math.floor(diffMs / (1000 * 60 * 60 * 24)));\n\n  return {\n    customerName: row.json.customer_name || '',\n    customerAddress: row.json.customer_address || '',\n    invoiceNumber: row.json.invoice_number || '',\n    amountDue: String(row.json.amount_due || '0.00'),\n    dueDate: row.json.due_date || '',\n    daysOverdue: String(daysOverdue),\n    companyName: row.json.company_name || ''\n  };\n});\n\nreturn [{ json: { documentId: 'YOUR_DOCUMENT_ID', items: JSON.stringify(items) } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "05562054-062f-4121-b22f-f20e77369845",
      "name": "Bulk Render Payment Reminders",
      "type": "n8n-nodes-autype.autype",
      "position": [
        3184,
        1376
      ],
      "parameters": {
        "items": "={{ $json.items }}",
        "resource": "bulkRender",
        "documentId": "={{ $json.documentId }}",
        "downloadOutput": true,
        "additionalFields": {}
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4d1b747a-5366-4558-b3de-0e034334026a",
      "name": "Send ZIP via Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        3408,
        1376
      ],
      "parameters": {
        "options": {
          "attachments": "data"
        },
        "subject": "=Payment Reminders \u2014 {{ $now.format('yyyy-MM-dd') }} ({{ $('Get Overdue Invoices').all().length }} documents)",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "805ee819-4af6-4540-b4a6-0b5e2db6e7bb",
      "name": "Run Setup Once",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        2928,
        832
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "72c5debc-9426-497c-914c-cd6e37706116",
      "name": "Create Project",
      "type": "n8n-nodes-autype.autype",
      "position": [
        3136,
        832
      ],
      "parameters": {
        "name": "Payment Reminders",
        "resource": "document",
        "operation": "createProject",
        "projectAdditionalFields": {
          "description": "Bulk payment reminder letters \u2014 created by n8n"
        }
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d414631e-d8b6-418f-9885-9e6428f1f263",
      "name": "Create Document",
      "type": "n8n-nodes-autype.autype",
      "position": [
        3360,
        832
      ],
      "parameters": {
        "title": "Payment Reminder \u2014 Template",
        "resource": "document",
        "operation": "createDocument",
        "projectId": "={{ $json.id }}",
        "additionalFields": {
          "content": "{\n  \"document\": {\n    \"size\": \"A4\",\n    \"type\": \"pdf\",\n    \"marginTop\": 2.5,\n    \"marginLeft\": 2.5,\n    \"marginRight\": 2.5,\n    \"orientation\": \"portrait\",\n    \"marginBottom\": 2.5\n  },\n  \"variables\": {\n    \"dueDate\": \"2026-01-01\",\n    \"amountDue\": \"0.00\",\n    \"companyName\": \"Company Name\",\n    \"daysOverdue\": \"0\",\n    \"customerName\": \"Customer Name\",\n    \"invoiceNumber\": \"INV-0000\",\n    \"customerAddress\": \"123 Main Street, Suite 100, New York, NY 10001\"\n  },\n  \"defaults\": {\n    \"chart\": {\n      \"colors\": [\n        \"#3b82f6\",\n        \"#ef4444\",\n        \"#10b981\",\n        \"#f59e0b\",\n        \"#8b5cf6\"\n      ],\n      \"borderColors\": [\n        \"#2563eb\",\n        \"#dc2626\",\n        \"#059669\",\n        \"#d97706\",\n        \"#7c3aed\"\n      ]\n    },\n    \"color\": \"#1a1a2e\",\n    \"footer\": {\n      \"excludeFirstPage\": false\n    },\n    \"header\": {\n      \"left\": {\n        \"src\": \"https://img.icons8.com/?size=100&id=e9femSksvyZL&format=png&color=6700FF\",\n        \"type\": \"image\",\n        \"width\": 40\n      },\n      \"right\": \"ACME Corp.\",\n      \"center\": \"\",\n      \"excludeFirstPage\": false\n    },\n    \"styles\": {\n      \"h1\": {\n        \"color\": \"#1a1a2e\",\n        \"fontSize\": 22,\n        \"fontWeight\": \"bold\"\n      },\n      \"h2\": {\n        \"color\": \"#1a1a2e\",\n        \"fontSize\": 16,\n        \"fontWeight\": \"bold\"\n      },\n      \"h3\": {\n        \"color\": \"#6700ff\",\n        \"fontSize\": 13,\n        \"fontWeight\": \"bold\"\n      },\n      \"text\": {\n        \"color\": \"#3d3d5c\",\n        \"fontSize\": 11\n      },\n      \"table\": {\n        \"rows\": {\n          \"align\": \"left\",\n          \"color\": \"#1a1a2e\",\n          \"backgroundColor\": \"#ffffff\",\n          \"alternateBackgroundColor\": \"#f5f0ff\"\n        },\n        \"header\": {\n          \"align\": \"left\",\n          \"color\": \"#ffffff\",\n          \"fontWeight\": \"bold\",\n          \"backgroundColor\": \"#6700ff\"\n        },\n        \"borders\": {\n          \"inner\": {\n            \"color\": \"#e0d4f5\",\n            \"style\": \"solid\",\n            \"width\": 1\n          },\n          \"outer\": {\n            \"color\": \"#6700ff\",\n            \"width\": 1\n          }\n        },\n        \"cellPadding\": {\n          \"top\": 6,\n          \"left\": 10,\n          \"right\": 10,\n          \"bottom\": 6\n        }\n      },\n      \"text2\": {\n        \"color\": \"#6b6b8a\",\n        \"fontSize\": 9\n      }\n    },\n    \"spacing\": {\n      \"after\": {\n        \"h1\": 15,\n        \"h2\": 12,\n        \"h3\": 10,\n        \"h4\": 8,\n        \"h5\": 6,\n        \"h6\": 5,\n        \"code\": 15,\n        \"list\": 10,\n        \"math\": 15,\n        \"text\": 10,\n        \"chart\": 15,\n        \"image\": 15,\n        \"table\": 15\n      },\n      \"before\": {\n        \"h1\": 20,\n        \"h2\": 18,\n        \"h3\": 16,\n        \"h4\": 14,\n        \"h5\": 12,\n        \"h6\": 10,\n        \"code\": 10,\n        \"list\": 10,\n        \"math\": 10,\n        \"text\": 0,\n        \"chart\": 10,\n        \"image\": 10,\n        \"table\": 10\n      }\n    },\n    \"fontSize\": 11,\n    \"fontFamily\": \"Arial\",\n    \"lineHeight\": 1.5\n  },\n  \"sections\": [\n    {\n      \"type\": \"flow\",\n      \"content\": [\n        {\n          \"id\": \"90188293-9f44-4955-802d-5db337b067ed\",\n          \"type\": \"spacer\",\n          \"height\": 1\n        },\n        {\n          \"id\": \"fdbce060-74f9-4b57-b73a-211733d90ca9\",\n          \"type\": \"h1\",\n          \"text\": \"Payment Reminder\"\n        },\n        {\n          \"id\": \"34f98687-22e4-41fb-ae69-601a85995afb\",\n          \"type\": \"spacer\",\n          \"height\": 0.5\n        },\n        {\n          \"id\": \"bac9709e-948c-4f76-842b-3620d8e9a0cd\",\n          \"type\": \"text\",\n          \"text\": \"Date: {{date/DD.MM.YYYY}}\",\n          \"align\": \"right\"\n        },\n        {\n          \"id\": \"1cff82c8-34aa-40cd-ac4b-5629f0eb54b8\",\n          \"type\": \"spacer\",\n          \"height\": 0.5\n        },\n        {\n          \"id\": \"091ce85f-c2a4-4ec9-956b-0e7bc71a8c2c\",\n          \"type\": \"text\",\n          \"text\": \"**To:** {{customerName}}\"\n        },\n        {\n          \"id\": \"6f0c0ef2-e8a9-498c-a510-20b4cba5883a\",\n          \"type\": \"variableRef\",\n          \"variable\": \"customerAddress\"\n        },\n        {\n          \"id\": \"14807236-2bab-4f49-892c-bd94ec413159\",\n          \"type\": \"text\",\n          \"text\": \"**Company:** {{companyName}}\"\n        },\n        {\n          \"id\": \"cdc2ed22-16f6-4a9f-bd3d-d89c1cb92995\",\n          \"type\": \"spacer\",\n          \"height\": 1\n        },\n        {\n          \"id\": \"acce4af3-1043-4678-aa37-5ef18f35e669\",\n          \"type\": \"h3\",\n          \"text\": \"Re: Outstanding Invoice {{invoiceNumber}}\",\n          \"align\": \"left\"\n        },\n        {\n          \"id\": \"ee95da49-6161-459b-8dc6-d2365e108bbe\",\n          \"type\": \"text\",\n          \"text\": \"Dear {{customerName}},\"\n        },\n        {\n          \"id\": \"2e7d822e-7494-4a2b-b683-d8be82274f05\",\n          \"type\": \"text\",\n          \"text\": \"We are writing to remind you that the following invoice remains unpaid and is now **{{daysOverdue}} days past due**. We kindly ask you to arrange payment at your earliest convenience.\"\n        },\n        {\n          \"id\": \"cdb9f391-be34-4f0e-92e4-0cb4ff9ade99\",\n          \"type\": \"table\",\n          \"headers\": [\n            \"Detail\",\n            \"Value\"\n          ],\n          \"rows\": [\n            [\n              \"Invoice Number\",\n              \"{{invoiceNumber}}\"\n            ],\n            [\n              \"Amount Due\",\n              \"$ {{amountDue}}\"\n            ],\n            [\n              \"Original Due Date\",\n              \"{{dueDate}}\"\n            ],\n            [\n              \"Days Overdue\",\n              \"{{daysOverdue}}\"\n            ]\n          ]\n        },\n        {\n          \"id\": \"5ebb7457-cfc6-4e01-9e52-1bcbc47961a1\",\n          \"type\": \"text\",\n          \"text\": \"If you have already made this payment, please disregard this notice. Otherwise, we would appreciate receiving your payment within the next **7 business days**.\"\n        },\n        {\n          \"id\": \"7adfaded-fd43-40a6-bab8-60cff9658f8d\",\n          \"type\": \"text\",\n          \"text\": \"For questions or payment arrangements, please contact our accounting department at **user@example.com** or call **+1234567890**.\"\n        },\n        {\n          \"id\": \"c3cd3caa-8a8e-4833-b150-5ea2cdf0dbaf\",\n          \"type\": \"spacer\",\n          \"height\": 1.5\n        },\n        {\n          \"id\": \"5f5aa06a-913c-4a7e-afe4-597db81ba37a\",\n          \"type\": \"text\",\n          \"text\": \"Kind regards,\"\n        },\n        {\n          \"id\": \"a34431e0-558f-4228-8c2e-74c6c5bc3f83\",\n          \"type\": \"spacer\",\n          \"height\": 0.5\n        },\n        {\n          \"id\": \"5407e705-3393-4457-9dca-36f4b23b20a7\",\n          \"type\": \"text\",\n          \"text\": \"**ACME Corp.**\"\n        },\n        {\n          \"id\": \"55ec3ddf-6c06-4b58-89c4-abbfccebb53e\",\n          \"type\": \"text2\",\n          \"text\": \"Accounting Department\"\n        },\n        {\n          \"id\": \"096415ff-cda2-4b26-83c6-f9b17bbd512a\",\n          \"type\": \"text2\",\n          \"text\": \"This is an automatically generated document. Invoice reference: {{invoiceNumber}}. Generated on {{date/DD.MM.YYYY}}.\"\n        }\n      ]\n    }\n  ]\n}",
          "description": "Payment reminder letter template with variable placeholders for bulk generation via n8n."
        }
      },
      "credentials": {
        "autypeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "19aa75b8-5b33-4c86-9d3a-67d900846bc2",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1904,
        672
      ],
      "parameters": {
        "width": 484,
        "height": 872,
        "content": "## Bulk Generate Payment Reminder PDFs from NocoDB\n\nThis workflow reads overdue invoices from a **NocoDB table**, generates a **personalized payment reminder PDF** for each record using the Autype Bulk Render API, and emails the resulting **ZIP archive** via SMTP \u2014 ideal for print-by-email services or internal distribution.\n\n### Variable Types Used\n- **String** \u2014 customer name, address, invoice number, company name, due date\n- **Number** \u2014 amount due (USD), days overdue (auto-calculated)\n\n### How it works\n1. **Weekly Schedule** \u2014 Triggers every Monday (configurable).\n2. **Get Overdue Invoices** \u2014 Reads all NocoDB rows where .\n3. **Build Bulk Items** \u2014 Transforms rows into variable sets. Calculates days overdue automatically.\n4. **Bulk Render** \u2014 Sends all items to Autype in a single batch. Downloads the ZIP.\n5. **Send ZIP via Email** \u2014 Attaches the ZIP to an email sent via SMTP.\n\n### One-time Setup\nUse the orange setup flow above to create the project and template document via API, then copy the document ID into the **Build Bulk Items** code node.\n\n### Requirements\n- **n8n-nodes-autype** community node (self-hosted n8n)\n- Autype API key from [app.autype.com](https://app.autype.com)\n- NocoDB instance with an \"Overdue Invoices or Cutomers\" table\n- SMTP credentials for email delivery"
      },
      "typeVersion": 1
    },
    {
      "id": "8edda517-e409-4f43-9e0e-05b363dd51ba",
      "name": "Sticky Note Setup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2896,
        688
      ],
      "parameters": {
        "color": 6,
        "width": 708,
        "height": 296,
        "content": "### One-time Setup\nRun once to create the Autype project and payment reminder template document. Copy the returned document ID into the Build Bulk Items node. Then disable these nodes."
      },
      "typeVersion": 1
    },
    {
      "id": "8896fde8-7fc4-4e25-a306-ffc9d3f991e1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2624,
        1104
      ],
      "parameters": {
        "color": 7,
        "width": 248,
        "height": 444,
        "content": "### 1. Get Overdue Invoices\nReads all rows from NocoDB where . Columns: \n- customer_name (text)\n- customer_address (text)\n- invoice_number (Number)\n- amount_due (Number)\n- due_date (date YYYY-MM-DD)\n- company_name (text)"
      },
      "typeVersion": 1
    },
    {
      "id": "3dffd950-396c-4cd5-917f-8c5579df2b95",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2896,
        1232
      ],
      "parameters": {
        "color": 7,
        "width": 200,
        "height": 312,
        "content": "### 2. Build Bulk Items\nMaps NocoDB rows to Autype variable sets. Calculates  from  vs. today. Sets the document ID."
      },
      "typeVersion": 1
    },
    {
      "id": "67588e30-a21c-4e9d-a9e9-9bac1ac04d4b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3120,
        1232
      ],
      "parameters": {
        "color": 7,
        "width": 216,
        "height": 312,
        "content": "### 3. Bulk Render\nSends all variable sets in one request. Downloads the output as a ZIP archive containing one PDF per invoice."
      },
      "typeVersion": 1
    },
    {
      "id": "f9cd7ce9-10f8-4523-98a2-c9dcb1ecf0d1",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3360,
        1232
      ],
      "parameters": {
        "color": 7,
        "width": 248,
        "height": 312,
        "content": "### 4. Send ZIP via Email\nEmails the ZIP to a printer service, accounting team, or archive mailbox via SMTP."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "a5-v3",
  "connections": {
    "Create Project": {
      "main": [
        [
          {
            "node": "Create Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Setup Once": {
      "main": [
        [
          {
            "node": "Create Project",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Schedule": {
      "main": [
        [
          {
            "node": "Get Overdue Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Bulk Items": {
      "main": [
        [
          {
            "node": "Bulk Render Payment Reminders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Overdue Invoices": {
      "main": [
        [
          {
            "node": "Build Bulk Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Bulk Render Payment Reminders": {
      "main": [
        [
          {
            "node": "Send ZIP via Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}