{
  "name": "Koutei: quote, invoice and receipt for one job",
  "nodes": [
    {
      "parameters": {
        "content": "## Quote, invoice and receipt for one job\nOne row of job details makes three PDFs with the Koutei PDF API: a quote, an invoice that names the quote, and a receipt that names the invoice. All three share the job ID as their reference.\n\n**Set up (once)**\n1. In Koutei, open Settings and create an API key.\n2. In n8n, create a **Header Auth** credential. Name: `Authorization`. Value: `Bearer ` followed by your key.\n3. Select that credential in the three Koutei nodes.\n4. Edit **Job details**, or replace it with a Google Sheets node whose columns have the same names.\n\nGuide: https://kouteisystems.com/docs/n8n",
        "height": 380,
        "width": 460,
        "color": 4
      },
      "id": "a7f3c2d1-0b4e-4c8a-9f61-2d5e8b7a1c01",
      "name": "Sticky Note: set up",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -420
      ]
    },
    {
      "parameters": {
        "content": "## What a run costs\n**mode** in Job details decides: `preview` makes watermarked PDFs and uses no credit; `final` makes the real documents and uses 1 credit each.\n\nRunning the same row again within 24 hours returns the same documents and uses no credit.\n\nTo correct a document, edit the row **and** raise that document's revision (**quote_revision**, **invoice_revision** or **receipt_revision**). Only that document is made again, as a new document; the others come back unchanged, free. A column that several documents print, such as the client or the currency, needs each of their revisions raised: the note under Job details lists them. If you edit a row without raising the revisions it needs, Koutei refuses the request (`idempotency_key_reused`) instead of making a second, different document.",
        "height": 440,
        "width": 460,
        "color": 7
      },
      "id": "a7f3c2d1-0b4e-4c8a-9f61-2d5e8b7a1c02",
      "name": "Sticky Note: costs",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        460,
        -420
      ]
    },
    {
      "parameters": {},
      "id": "a7f3c2d1-0b4e-4c8a-9f61-2d5e8b7a1c03",
      "name": "Run the chain",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b1000000-0000-4000-8000-000000000001",
              "name": "job_id",
              "value": "JOB-0017",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000019",
              "name": "quote_revision",
              "value": 1,
              "type": "number"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000001a",
              "name": "invoice_revision",
              "value": 1,
              "type": "number"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000001b",
              "name": "receipt_revision",
              "value": 1,
              "type": "number"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000003",
              "name": "mode",
              "value": "preview",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000004",
              "name": "seller_name",
              "value": "Example Design Studio",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000005",
              "name": "seller_details",
              "value": "12 Example Street\nCape Town 8001\nhello@example.com",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000006",
              "name": "tax_id",
              "value": "",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000007",
              "name": "client_name",
              "value": "Example Client Ltd",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000008",
              "name": "client_details",
              "value": "Attn: Accounts\n34 Sample Road\nJohannesburg 2000",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000009",
              "name": "currency",
              "value": "ZAR",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000000a",
              "name": "items",
              "value": "Logo design | 1 | 4,500.00\nBrand guidelines | 1 | 2,500.00",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000000b",
              "name": "scope",
              "value": "Logo and brand guidelines for the spring launch.",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000000c",
              "name": "quote_number",
              "value": "Q-0017",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000000d",
              "name": "quote_date",
              "value": "2026-10-12",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000000e",
              "name": "valid_until",
              "value": "2026-10-26",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-00000000000f",
              "name": "invoice_number",
              "value": "INV-0017",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000010",
              "name": "invoice_date",
              "value": "2026-10-20",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000011",
              "name": "due_date",
              "value": "2026-11-03",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000012",
              "name": "payment_terms",
              "value": "Due within 14 days",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000013",
              "name": "payment_instructions",
              "value": "Example Bank, account 000 000 000. Use the invoice number as the reference.",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000014",
              "name": "receipt_number",
              "value": "R-0017",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000015",
              "name": "payment_date",
              "value": "2026-10-28",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000016",
              "name": "amount_received",
              "value": "7,000.00",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000017",
              "name": "payment_method",
              "value": "Bank transfer",
              "type": "string"
            },
            {
              "id": "b1000000-0000-4000-8000-000000000018",
              "name": "payment_reference",
              "value": "",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a7f3c2d1-0b4e-4c8a-9f61-2d5e8b7a1c04",
      "name": "Job details",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ],
      "notes": "After a document is made, change a column only together with the revision of each document it appears on (raise it by 1):\nquote_revision + invoice_revision + receipt_revision: seller_name, seller_details, tax_id, client_name, client_details, currency\nquote_revision + invoice_revision: items, quote_number\nquote_revision + receipt_revision: scope\nquote_revision: quote_date, valid_until\ninvoice_revision + receipt_revision: invoice_number\ninvoice_revision: invoice_date, due_date, payment_terms, payment_instructions\nreceipt_revision: receipt_number, payment_date, amount_received, payment_method, payment_reference",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://kouteisystems.com/api/v1/documents",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/pdf"
            },
            {
              "name": "Koutei-Version",
              "value": "2026-10-01"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{ $('Job details').item.json.job_id }}-quote-r{{ $('Job details').item.json.quote_revision }}{{ $('Job details').item.json.mode === 'final' ? '' : '-preview' }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  template: 'quote',\n  mode: $('Job details').item.json.mode,\n  reference: String($('Job details').item.json.job_id),\n  fields: {\n    document_title: 'Quote',\n    seller_name: $('Job details').item.json.seller_name,\n    seller_details: $('Job details').item.json.seller_details,\n    tax_id: $('Job details').item.json.tax_id,\n    client_name: $('Job details').item.json.client_name,\n    client_details: $('Job details').item.json.client_details,\n    quote_number: $('Job details').item.json.quote_number,\n    date: $('Job details').item.json.quote_date,\n    valid_until: $('Job details').item.json.valid_until,\n    scope: $('Job details').item.json.scope,\n    currency: $('Job details').item.json.currency,\n    items: $('Job details').item.json.items\n  }\n}) }}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "file",
              "outputPropertyName": "quote"
            }
          },
          "timeout": 60000
        }
      },
      "id": "a7f3c2d1-0b4e-4c8a-9f61-2d5e8b7a1c05",
      "name": "Make the quote",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://kouteisystems.com/api/v1/documents",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/pdf"
            },
            {
              "name": "Koutei-Version",
              "value": "2026-10-01"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{ $('Job details').item.json.job_id }}-invoice-r{{ $('Job details').item.json.invoice_revision }}{{ $('Job details').item.json.mode === 'final' ? '' : '-preview' }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  template: 'invoice',\n  mode: $('Job details').item.json.mode,\n  reference: String($('Job details').item.json.job_id),\n  fields: {\n    seller_name: $('Job details').item.json.seller_name,\n    seller_details: $('Job details').item.json.seller_details,\n    tax_id: $('Job details').item.json.tax_id,\n    client_name: $('Job details').item.json.client_name,\n    client_details: $('Job details').item.json.client_details,\n    invoice_number: $('Job details').item.json.invoice_number,\n    date: $('Job details').item.json.invoice_date,\n    due_date: $('Job details').item.json.due_date,\n    related_document: $('Job details').item.json.quote_number,\n    currency: $('Job details').item.json.currency,\n    items: $('Job details').item.json.items,\n    payment_terms: $('Job details').item.json.payment_terms,\n    payment_instructions: $('Job details').item.json.payment_instructions\n  }\n}) }}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "file",
              "outputPropertyName": "invoice"
            }
          },
          "timeout": 60000
        }
      },
      "id": "a7f3c2d1-0b4e-4c8a-9f61-2d5e8b7a1c06",
      "name": "Make the invoice",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://kouteisystems.com/api/v1/documents",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/pdf"
            },
            {
              "name": "Koutei-Version",
              "value": "2026-10-01"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{ $('Job details').item.json.job_id }}-receipt-r{{ $('Job details').item.json.receipt_revision }}{{ $('Job details').item.json.mode === 'final' ? '' : '-preview' }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  template: 'receipt',\n  mode: $('Job details').item.json.mode,\n  reference: String($('Job details').item.json.job_id),\n  fields: {\n    seller_name: $('Job details').item.json.seller_name,\n    seller_details: $('Job details').item.json.seller_details,\n    tax_id: $('Job details').item.json.tax_id,\n    client_name: $('Job details').item.json.client_name,\n    client_details: $('Job details').item.json.client_details,\n    receipt_number: $('Job details').item.json.receipt_number,\n    payment_date: $('Job details').item.json.payment_date,\n    related_document: $('Job details').item.json.invoice_number,\n    description: $('Job details').item.json.scope,\n    currency: $('Job details').item.json.currency,\n    amount: $('Job details').item.json.amount_received,\n    payment_method: $('Job details').item.json.payment_method,\n    payment_reference: $('Job details').item.json.payment_reference\n  }\n}) }}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "file",
              "outputPropertyName": "receipt"
            }
          },
          "timeout": 60000
        }
      },
      "id": "a7f3c2d1-0b4e-4c8a-9f61-2d5e8b7a1c07",
      "name": "Make the receipt",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ]
    }
  ],
  "connections": {
    "Run the chain": {
      "main": [
        [
          {
            "node": "Job details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Job details": {
      "main": [
        [
          {
            "node": "Make the quote",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Make the quote": {
      "main": [
        [
          {
            "node": "Make the invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Make the invoice": {
      "main": [
        [
          {
            "node": "Make the receipt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
