{ "name": "1 - WFDASH QUICKBOOKS TEST_NEXTJS", "nodes": [ { "parameters": { "httpMethod": "POST", "path": "wfdash-quickbooks-invoice-creator", "responseMode": "responseNode", "options": {} }, "id": "b328d90a-78d0-4d30-b5e5-906c6b28b363", "name": "Webhook Trigger", "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ -1648, 2064 ], "webhookId": "b9523463-a997-4103-8a6c-75885a178e01" }, { "parameters": { "jsCode": "const body = $json.body ?? $json;\n\n// Public webhook mode: do not require X-Webhook-Token.\nconst orderNumber = (body.order_number ?? '').toString().trim();\nconst billingCompany = (body.billing_company ?? '').toString().trim().toUpperCase();\nconst invoiceCompany = (body.invoice_company ?? body.company ?? '').toString().trim();\nconst customerId = (body.customer_id ?? body.qb_customer_id ?? '').toString().trim();\nconst customerName = (body.customer_name ?? '').toString().trim();\nconst items = Array.isArray(body.items) ? body.items : [];\nconst orderItemIds = Array.isArray(body.order_item_ids)\n ? body.order_item_ids.map((value) => value.toString().trim()).filter(Boolean)\n : [];\nconst sentById = (body.sent_by_id ?? '').toString().trim();\nconst sentByName = (body.sent_by_name ?? '').toString().trim();\n\nconsole.log(JSON.stringify({\n event: 'wfdash.invoice.request',\n order_number: orderNumber,\n billing_company: billingCompany,\n customer_id: customerId || null,\n line_count: items.length,\n order_item_count: orderItemIds.length,\n sent_by_id: sentById || null\n}));\n\nreturn [{\n json: {\n invoice_company: invoiceCompany,\n company: invoiceCompany,\n billing_company: billingCompany,\n order_number: orderNumber,\n customer_id: customerId,\n customer_name: customerName,\n order_item_ids: orderItemIds,\n sent_by_id: sentById,\n sent_by_name: sentByName,\n items,\n line_count: items.length,\n auth_ok: true\n }\n}];" }, "id": "a4d8411a-31b5-4df2-84fc-8802cfbe4321", "name": "Normalize Request", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -992, 2080 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "auth-ok-check", "leftValue": "={{ $json.auth_ok }}", "rightValue": true, "operator": { "type": "boolean", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "97221869-e6e6-4bb4-b360-4bdf62bf848a", "name": "Is Authorized?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ -768, 2080 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "unauth-status", "name": "status", "value": "error", "type": "string" }, { "id": "unauth-message", "name": "message", "value": "Unauthorized: invalid or missing X-Webhook-Token", "type": "string" }, { "id": "unauth-order", "name": "order_number", "value": "={{ $json.order_number }}", "type": "string" }, { "id": "unauth-billing", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "unauth-http", "name": "http_status", "value": 401, "type": "number" } ] }, "options": {} }, "id": "270daf1c-1015-4f7d-a1a2-fb433bd876b4", "name": "Unauthorized Response", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 5536, 2944 ] }, { "parameters": { "jsCode": "const errors = [];\nconst allowedCompanies = ['CNL', 'ISHERWOOD'];\n\nif (!allowedCompanies.includes($json.billing_company)) {\n errors.push('billing_company must be one of CNL, ISHERWOOD');\n}\n\nif (!$json.order_number || typeof $json.order_number !== 'string' || $json.order_number.trim() === '') {\n errors.push('order_number is required');\n}\n\nif (!$json.customer_id || typeof $json.customer_id !== 'string' || $json.customer_id.trim() === '') {\n errors.push('customer_id is required (select a QuickBooks customer from suggestions)');\n}\n\nif (!Array.isArray($json.items) || $json.items.length < 1) {\n errors.push('items must be an array with at least 1 item');\n}\n\nif (Array.isArray($json.items)) {\n $json.items.forEach((item, index) => {\n const row = index + 1;\n if (!item || typeof item.name !== 'string' || item.name.trim() === '') {\n errors.push(`items[${row}] name is required`);\n }\n if (typeof item.qty !== 'number' || Number(item.qty) <= 0) {\n errors.push(`items[${row}] qty must be > 0`);\n }\n if (typeof item.price !== 'number' || Number(item.price) < 0) {\n errors.push(`items[${row}] price must be >= 0`);\n }\n });\n}\n\nif (!Array.isArray($json.order_item_ids) || $json.order_item_ids.length < 1) {\n errors.push('order_item_ids must be an array with at least 1 id');\n}\n\nif (!$json.sent_by_id || typeof $json.sent_by_id !== 'string' || $json.sent_by_id.trim() === '') {\n errors.push('sent_by_id is required');\n}\n\nif (!$json.sent_by_name || typeof $json.sent_by_name !== 'string' || $json.sent_by_name.trim() === '') {\n errors.push('sent_by_name is required');\n}\n\nif (errors.length > 0) {\n return [{\n json: {\n ...$json,\n status: 'error',\n message: `Validation failed: ${errors.join('; ')}`,\n http_status: 400,\n valid: false\n }\n }];\n}\n\nreturn [{\n json: {\n ...$json,\n valid: true\n }\n}];" }, "id": "32daccc1-b90d-415b-acf4-57cb8c0b4a99", "name": "Validate Payload", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -544, 1984 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "payload-valid-check", "leftValue": "={{ $json.valid }}", "rightValue": true, "operator": { "type": "boolean", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "e855d190-290f-4c92-aa9d-2c7715e0a0dc", "name": "Is Payload Valid?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ -320, 1984 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "validation-status", "name": "status", "value": "={{ $json.status }}", "type": "string" }, { "id": "validation-message", "name": "message", "value": "={{ $json.message }}", "type": "string" }, { "id": "validation-order", "name": "order_number", "value": "={{ $json.order_number }}", "type": "string" }, { "id": "validation-billing", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "validation-http", "name": "http_status", "value": "={{ $json.http_status }}", "type": "number" } ] }, "options": {} }, "id": "f0e50754-9ced-4a22-94aa-4acb84a5a773", "name": "Validation Error Response", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 5504, 2736 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "set-cnl-context-item", "name": "qb_item_ref", "value": "1", "type": "string" }, { "id": "aa418315-fa29-4c57-b224-d05bd67e3b4d", "name": "qb_realm_id", "value": "123146321422364", "type": "string" }, { "id": "439061c4-f708-4e25-85e9-92e4e1f7acfb", "name": "letterhead", "value": "={{ $('Normalize Request').item.json.billing_company }}", "type": "string" } ] }, "includeOtherFields": true, "options": {} }, "id": "95072586-208b-422a-890b-995481c77666", "name": "Set CNL Context", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 128, 1808 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "set-isherwood-context-item", "name": "qb_item_ref", "value": "1", "type": "string" }, { "id": "36efc6b6-a874-4c66-a5a7-d705e8a75270", "name": "qb_realm_id", "value": "123146321437969", "type": "string" }, { "id": "2f5aca75-1314-41a0-8934-d605ed16e8b0", "name": "letterhead", "value": "={{ $('Normalize Request').item.json.billing_company }}", "type": "string" } ] }, "includeOtherFields": true, "options": {} }, "id": "36ef86f5-9801-4f12-ba2f-4716b794f2c1", "name": "Set ISHERWOOD Context", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 128, 2304 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "mapping-status", "name": "status", "value": "error", "type": "string" }, { "id": "mapping-message", "name": "message", "value": "Unsupported billing_company mapping", "type": "string" }, { "id": "mapping-order", "name": "order_number", "value": "={{ $json.order_number }}", "type": "string" }, { "id": "mapping-company", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "mapping-http", "name": "http_status", "value": 400, "type": "number" } ] }, "options": {} }, "id": "b75609b1-383c-494f-9872-70069e85cb38", "name": "Mapping Error Response", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 5552, 3120 ] }, { "parameters": { "jsCode": "return [{ json: { ...$json } }];" }, "id": "13f4d5b2-d334-44b9-9001-54985ca8c30f", "name": "QB Context", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 352, 1904 ] }, { "parameters": { "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/query?query=' + encodeURIComponent(\"select * from Invoice order by MetaData.CreateTime desc maxresults 200\") + '&minorversion=65' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "options": {} }, "id": "75e7da24-fa63-4d4e-a7e9-be626cdff752", "name": "Search Existing Invoice (CNL)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 800, 1808 ], "credentials": { "quickBooksOAuth2Api": { "id": "BPkRunJXtL1mqASg", "name": "CNL QUICKBOOKS" } }, "continueOnFail": true }, { "parameters": { "jsCode": "const ctx = $('QB Context').item.json;\nconst response = $json;\n\nif (response.error) {\n const err = response.error;\n const statusCode = err?.statusCode ?? err?.status ?? err?.httpStatusCode ?? err?.response?.statusCode;\n\n const rawBody = err?.response?.body ?? err?.response?.data ?? err?.body;\n const bodyText = typeof rawBody === 'string' ? rawBody : (rawBody ? JSON.stringify(rawBody) : '');\n\n const primary = err?.message || err?.Message || err?.description || err?.error;\n const fallback = typeof err === 'string' ? err : JSON.stringify(err);\n\n const parts = [];\n if (statusCode) parts.push(`status=${statusCode}`);\n if (primary) parts.push(String(primary));\n if (bodyText) parts.push(bodyText);\n\n const details = (parts.length ? parts.join(' | ') : fallback);\n const safeDetails = String(details).length > 2000 ? String(details).slice(0, 2000) + '…' : String(details);\n\n return [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `QuickBooks lookup failed: ${safeDetails}`,\n http_status: statusCode || 502\n }\n }];\n}\n\nconst invoices = response.QueryResponse?.Invoice ?? [];\nconst needle = `order_number:${ctx.order_number}`;\n\nconst normalizeText = (value) => String(value ?? '').trim().replace(/\\s+/g, ' ').toLowerCase();\nconst normalizeNumber = (value, decimals = 4) => {\n const num = Number(value);\n if (!Number.isFinite(num)) return null;\n return num.toFixed(decimals);\n};\n\nconst signatureFromLines = (lines) => {\n const normalized = lines\n .map((line) => ({\n desc: normalizeText(line.desc),\n qty: normalizeNumber(line.qty, 4),\n unitPrice: normalizeNumber(line.unitPrice, 4)\n }))\n .filter((line) => line.qty !== null && line.unitPrice !== null)\n .sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));\n\n return JSON.stringify(normalized);\n};\n\nconst incomingSignature = signatureFromLines(\n (Array.isArray(ctx.items) ? ctx.items : []).map((item) => ({\n desc: item?.name,\n qty: item?.qty,\n unitPrice: item?.price\n }))\n);\n\nconst getInvoiceSignature = (invoice) => signatureFromLines(\n (Array.isArray(invoice?.Line) ? invoice.Line : [])\n .filter((line) => line?.DetailType === 'SalesItemLineDetail')\n .map((line) => ({\n desc: line?.Description,\n qty: line?.SalesItemLineDetail?.Qty,\n unitPrice: line?.SalesItemLineDetail?.UnitPrice\n }))\n);\n\nif (Array.isArray(invoices) && invoices.length > 0) {\n const matchingOrderInvoices = invoices.filter((inv) => {\n const note = String(inv?.PrivateNote ?? '').trim();\n return note === needle || note.startsWith(needle);\n });\n\n if (matchingOrderInvoices.length > 0) {\n const exactDuplicate = matchingOrderInvoices.find((inv) => getInvoiceSignature(inv) === incomingSignature);\n\n if (exactDuplicate) {\n const invoiceId = exactDuplicate.Id ? String(exactDuplicate.Id) : '';\n const invoiceNumber = exactDuplicate.DocNumber ? String(exactDuplicate.DocNumber) : '';\n const invoiceLink = invoiceId ? `https://app.qbo.intuit.com/app/invoice?txnId=${invoiceId}` : '';\n\n console.log(JSON.stringify({\n event: 'wfdash.invoice.idempotent-hit',\n order_number: ctx.order_number,\n billing_company: ctx.billing_company,\n invoice_id: invoiceId,\n match_type: 'exact-items'\n }));\n\n return [{\n json: {\n ...ctx,\n qb_action: 'existing',\n status: 'success',\n invoice_number: invoiceNumber,\n invoice_id: invoiceId,\n invoice_link: invoiceLink\n }\n }];\n }\n\n console.log(JSON.stringify({\n event: 'wfdash.invoice.partial-create',\n order_number: ctx.order_number,\n billing_company: ctx.billing_company,\n existing_order_invoice_count: matchingOrderInvoices.length,\n reason: 'items-differ'\n }));\n }\n}\n\nconst lineItems = ctx.items.map(item => ({\n Amount: Number(item.qty) * Number(item.price),\n Description: String(item.name ?? ''),\n DetailType: 'SalesItemLineDetail',\n SalesItemLineDetail: {\n Qty: Number(item.qty),\n UnitPrice: Number(item.price),\n ItemRef: {value: String(ctx.qb_item_ref)},\n TaxCodeRef: { value: '5' } \n }\n}));\n\nconst payload = {\n Line: lineItems,\n CustomerRef: {\n value: String(ctx.customer_id || ctx.qb_customer_ref)\n },\n // Set Billing Email\n BillEmail: ctx.customer_email ? { Address: String(ctx.customer_email) } : undefined,\n \n // Keep order number in both internal note and PO/order field.\n PrivateNote: `order_number:${ctx.order_number}`,\n PONumber: String(ctx.order_number),\n CustomerMemo: {\n value: `Order: ${ctx.order_number}`\n },\n CustomField: [\n {\n DefinitionId: \"3\",\n Type: \"StringType\",\n StringValue: String(ctx.order_number)\n }\n ]\n};\n\nreturn [{\n json: {\n ...ctx,\n qb_action: 'create',\n qb_invoice_payload: payload\n }\n}];\n" }, "id": "1fdb8f8c-89c5-4038-978c-3b893f9e9a5d", "name": "Decide Invoice Action", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1024, 1904 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "action-error-check", "leftValue": "={{ $json.qb_action }}", "rightValue": "error", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "35cf989c-0b4d-4fcd-bb2a-98e3f0f8dc9f", "name": "Action Is Error?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1248, 1904 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "action-existing-check", "leftValue": "={{ $json.qb_action }}", "rightValue": "existing", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "541202ca-bdd7-427f-a269-ad6e6a4dc176", "name": "Action Is Existing?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1472, 1744 ] }, { "parameters": { "method": "POST", "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/invoice?minorversion=65' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ {\n ...$json.qb_invoice_payload,\n DocNumber: $json.current_doc_number || $json.generated_invoice_number\n} }}", "options": {} }, "id": "2739e1c7-154f-4cfd-b413-3d1faf9790a0", "name": "Create Invoice (CNL)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 2368, 1664 ], "credentials": { "quickBooksOAuth2Api": { "id": "BPkRunJXtL1mqASg", "name": "CNL QUICKBOOKS" } }, "continueOnFail": true }, { "parameters": { "jsCode": "const ctx = $('QB Context').item.json;\nconst sourceItem = $input.first();\nconst sourceBinary = sourceItem?.binary ?? {};\n\n// 1. Get the invoice data safely from the creation branch\nlet createResponse = null;\ntry { createResponse = $('Create Invoice (CNL)').item.json; } catch (e) {}\nif (!createResponse) {\n try { createResponse = $('Create Invoice (ISHERWOOD)').item.json; } catch (e) {}\n}\n\nconst invoice = createResponse?.Invoice ?? {};\nconst invoiceId = invoice.Id ? String(invoice.Id) : '';\nconst invoiceNumber = invoice.DocNumber ? String(invoice.DocNumber) : '';\nconst invoiceLink = invoiceId ? `https://app.qbo.intuit.com/app/invoice?txnId=${invoiceId}` : '';\nconst invoiceDate = invoice.TxnDate ? String(invoice.TxnDate) : '';\nconst invoiceCompany = String(ctx.invoice_company ?? ctx.company ?? '').trim();\n\n// Keep the base64 copy for compatibility/debugging and preserve the binary PDF for PocketBase upload.\nconst pdfBase64 = $json.pdf_base64 || null;\n\nconsole.log(JSON.stringify({\n event: 'wfdash.invoice.created',\n order_number: ctx.order_number,\n invoice_id: invoiceId,\n has_pdf: !!pdfBase64,\n has_binary_pdf: Object.keys(sourceBinary).length > 0\n}));\n\nreturn [{\n json: {\n status: 'success',\n invoice_number: invoiceNumber,\n invoice_id: invoiceId,\n invoice_link: invoiceLink,\n qb_invoice_date: invoiceDate,\n invoice_company: invoiceCompany,\n company: invoiceCompany,\n order_number: ctx.order_number,\n billing_company: ctx.billing_company,\n order_item_ids: Array.isArray(ctx.order_item_ids) ? ctx.order_item_ids : [],\n sent_by_id: String(ctx.sent_by_id ?? ''),\n sent_by_name: String(ctx.sent_by_name ?? ''),\n line_count: ctx.items.length,\n pdf_base64: pdfBase64\n },\n binary: sourceBinary\n}];" }, "id": "057ddc76-d75a-4a37-b1fe-f85ab4e56ffa", "name": "Build Created Response", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3504, 1552 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "existing-status", "name": "status", "value": "success", "type": "string" }, { "id": "existing-number", "name": "invoice_number", "value": "={{ $json.invoice_number }}", "type": "string" }, { "id": "existing-id", "name": "invoice_id", "value": "={{ $json.invoice_id }}", "type": "string" }, { "id": "existing-link", "name": "invoice_link", "value": "={{ $json.invoice_link }}", "type": "string" }, { "id": "existing-order", "name": "order_number", "value": "={{ $json.order_number }}", "type": "string" }, { "id": "existing-billing", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "existing-lines", "name": "line_count", "value": "={{ $json.items.length }}", "type": "number" } ] }, "options": {} }, "id": "1aa8923c-70fd-4fcb-8ed1-c3846eed9b02", "name": "Build Existing Response", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 5344, 1216 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "qb-error-status", "name": "status", "value": "error", "type": "string" }, { "id": "qb-error-message", "name": "message", "value": "={{ $json.message }}", "type": "string" }, { "id": "qb-error-order", "name": "order_number", "value": "={{ $json.order_number }}", "type": "string" }, { "id": "qb-error-billing", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "qb-error-http", "name": "http_status", "value": "={{ $json.http_status ?? 500 }}", "type": "number" } ] }, "options": {} }, "id": "d67e450d-2c9a-43ae-9f39-96bb6272560c", "name": "Build QB Error Response", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 5648, 1808 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "created-success-check", "leftValue": "={{ $json.status }}", "rightValue": "success", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "dcba4298-3020-490c-a2bc-e9b3e78fce58", "name": "Created Is Success?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 3712, 1552 ] }, { "parameters": { "respondWith": "json", "responseBody": "={{ $json }}", "options": { "responseCode": 200 } }, "id": "602d92ff-2722-4c08-acd6-9283343847b8", "name": "Respond Success", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.1, "position": [ 5712, 1216 ] }, { "parameters": { "respondWith": "json", "responseBody": "={{ { status: 'error', message: $json.message, order_number: $json.order_number, billing_company: $json.billing_company } }}", "options": { "responseCode": "={{ $json.http_status ?? 500 }}" } }, "id": "4a67fb06-ccb6-4f3c-867a-2e8f9b72ce7e", "name": "Respond Error", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.1, "position": [ 5936, 2096 ] }, { "parameters": { "operation": "getAll", "returnAll": true, "filters": {} }, "type": "n8n-nodes-base.quickbooks", "typeVersion": 1, "position": [ 128, 240 ], "id": "20d3b836-8196-4d33-b474-e3bb2dd4b9a6", "name": "GET ISHERWOOD CUSTOMERS1", "credentials": { "quickBooksOAuth2Api": { "id": "qIOWSWNJQneDXGmH", "name": "ISHERWOODMINING" } } }, { "parameters": { "operation": "getAll", "returnAll": true, "filters": {} }, "type": "n8n-nodes-base.quickbooks", "typeVersion": 1, "position": [ 128, 432 ], "id": "45f9c524-f622-47e3-b390-055b01ea5512", "name": "GET CNL CUSTOMERS1", "credentials": { "quickBooksOAuth2Api": { "id": "BPkRunJXtL1mqASg", "name": "CNL QUICKBOOKS" } } }, { "parameters": { "httpMethod": "POST", "path": "wfdash-get-customers", "responseMode": "responseNode", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ -1216, 528 ], "id": "9f5c1d31-b22a-489d-b275-57e9fe65d5b0", "name": "GET CUSTOMERS WEBHOOK", "webhookId": "a6b0fde0-592a-49bb-a345-84d7d690feb1" }, { "parameters": { "respondWith": "json", "responseBody": "={{ $json }}", "options": { "responseCode": "={{ $json.http_status ?? 200 }}" } }, "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.5, "position": [ 576, 704 ], "id": "4d385f77-dfb6-4e69-a014-dcec05caa242", "name": "Respond to Webhook" }, { "parameters": { "jsCode": "const body = $json.body ?? $json;\n\n// Public webhook mode: do not require X-Webhook-Token.\nconst billingCompany = (body.billing_company ?? '').toString().trim().toUpperCase();\nconst query = (body.customer_query ?? body.company ?? body.customer_name ?? '').toString().trim();\n\nreturn [{\n json: {\n billing_company: billingCompany,\n customer_query: query,\n limit: Number(body.limit ?? 15),\n auth_ok: true\n }\n}];" }, "id": "873fd9b3-11c5-4d2f-be98-511c5b0eb421", "name": "Normalize Customer Search Request", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -992, 528 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "customer-auth-ok", "leftValue": "={{ $json.auth_ok }}", "rightValue": true, "operator": { "type": "boolean", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "f8638fe6-e91a-4d69-9166-5f2fc16dff30", "name": "Is Customer Authorized?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ -768, 528 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "customer-unauth-status", "name": "status", "value": "error", "type": "string" }, { "id": "customer-unauth-message", "name": "message", "value": "Unauthorized: invalid or missing X-Webhook-Token", "type": "string" }, { "id": "customer-unauth-billing", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "customer-unauth-http", "name": "http_status", "value": 401, "type": "number" } ] }, "options": {} }, "id": "716d6a36-aaaf-4499-87e8-7ef7f2b1b8ad", "name": "Build Customer Unauthorized", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 352, 800 ] }, { "parameters": { "jsCode": "const errors = [];\nconst allowedCompanies = ['CNL', 'ISHERWOOD'];\n\nif (!allowedCompanies.includes($json.billing_company)) {\n errors.push('billing_company must be one of CNL, ISHERWOOD');\n}\n\nif (!$json.customer_query || typeof $json.customer_query !== 'string' || $json.customer_query.trim() === '') {\n errors.push('customer_query (or company/customer_name) is required');\n}\n\nif (errors.length > 0) {\n return [{\n json: {\n ...$json,\n valid: false,\n status: 'error',\n message: `Validation failed: ${errors.join('; ')}`,\n http_status: 400\n }\n }];\n}\n\nreturn [{\n json: {\n ...$json,\n valid: true\n }\n}];" }, "id": "abd6fe3d-a4cf-4936-8f67-7ab5de922472", "name": "Validate Customer Search", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -544, 432 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "customer-validate-ok", "leftValue": "={{ $json.valid }}", "rightValue": true, "operator": { "type": "boolean", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "3ca85ad8-1136-481d-a92c-9dd6ec34b2c4", "name": "Is Customer Search Valid?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ -320, 432 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "customer-validation-status", "name": "status", "value": "={{ $json.status }}", "type": "string" }, { "id": "customer-validation-message", "name": "message", "value": "={{ $json.message }}", "type": "string" }, { "id": "customer-validation-billing", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "customer-validation-http", "name": "http_status", "value": "={{ $json.http_status ?? 400 }}", "type": "number" } ] }, "options": {} }, "id": "685b9251-a292-42b6-9cd5-4daebf4b850a", "name": "Build Customer Validation Error", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 352, 608 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "customer-mapping-status", "name": "status", "value": "error", "type": "string" }, { "id": "customer-mapping-message", "name": "message", "value": "Unsupported billing_company mapping", "type": "string" }, { "id": "customer-mapping-billing", "name": "billing_company", "value": "={{ $json.billing_company }}", "type": "string" }, { "id": "customer-mapping-http", "name": "http_status", "value": 400, "type": "number" } ] }, "options": {} }, "id": "d23dfabc-9351-48e2-99f5-5e14418bbc95", "name": "Build Customer Mapping Error", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 352, 992 ] }, { "parameters": { "jsCode": "const source = $input.all().map((item) => item.json);\nconst ctx = $('If1').item.json;\nconst queryRaw = String(ctx.customer_query || '').toLowerCase().trim();\nconst queryTokens = queryRaw.split(/[^a-z0-9]+/).filter(Boolean);\nconst limit = Math.max(1, Math.min(Number(ctx.limit || 15), 50));\n\nfunction scoreMatch(name) {\n const candidate = String(name || '').toLowerCase().trim();\n if (!candidate) return 0;\n if (candidate === queryRaw) return 1;\n\n let score = 0;\n if (candidate.includes(queryRaw)) score += 0.6;\n\n const candidateTokens = candidate.split(/[^a-z0-9]+/).filter(Boolean);\n if (queryTokens.length > 0) {\n const overlap = queryTokens.filter((t) => candidateTokens.includes(t)).length;\n score += 0.4 * (overlap / queryTokens.length);\n }\n\n return Math.min(score, 0.99);\n}\n\nconst mapped = source\n .map((customer) => {\n const displayName = customer.DisplayName || customer.CompanyName || customer.FullyQualifiedName || '';\n const companyName = customer.CompanyName || '';\n const finalScore = Math.max(scoreMatch(displayName), scoreMatch(companyName));\n return {\n id: String(customer.Id || ''),\n display_name: String(displayName),\n company_name: String(companyName),\n fully_qualified_name: String(customer.FullyQualifiedName || ''),\n active: customer.Active !== false,\n score: Number(finalScore.toFixed(4))\n };\n })\n .filter((c) => c.id && c.display_name && c.score > 0)\n .sort((a, b) => b.score - a.score)\n .slice(0, limit);\n\nreturn [{\n json: {\n status: 'success',\n billing_company: ctx.billing_company,\n query: ctx.customer_query,\n customers: mapped,\n count: mapped.length\n }\n}];" }, "id": "455bcaa9-2ed4-4089-8228-91c9f79905f6", "name": "Fuzzy Match Customers", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 352, 336 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "d493ef7f-18b8-4bd4-9f49-bc5c117b077f", "leftValue": "={{ $json.billing_company }}", "rightValue": "ISHERWOOD", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ -96, 336 ], "id": "d649e677-2e54-4f02-a146-5e7d7ae8391f", "name": "If1" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "d493ef7f-18b8-4bd4-9f49-bc5c117b077f", "leftValue": "={{ $json.billing_company }}", "rightValue": "CNL", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ -96, 1904 ], "id": "11cfd0ba-9bd1-4f52-937c-ac04909df056", "name": "If2" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "route-search-cnl", "leftValue": "={{ $json.letterhead }}", "rightValue": "CNL", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "a8c8d601-8544-4acb-a1c0-5c5208a53e38", "name": "Route Search Company", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 576, 1904 ] }, { "parameters": { "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/query?query=' + encodeURIComponent(\"select * from Invoice order by MetaData.CreateTime desc maxresults 200\") + '&minorversion=65' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "options": {} }, "id": "4b9fd9f3-28bf-4310-b59c-1f50379bd3fe", "name": "Search Existing Invoice (ISHERWOOD)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 800, 2304 ], "credentials": { "quickBooksOAuth2Api": { "id": "qIOWSWNJQneDXGmH", "name": "ISHERWOODMINING" } }, "continueOnFail": true }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "route-create-cnl", "leftValue": "={{ $json.billing_company }}", "rightValue": "CNL", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "e5979cb3-d589-46fd-a07b-b3980cfd4e8a", "name": "Route Create Company", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1696, 1840 ] }, { "parameters": { "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/query?query=' + encodeURIComponent(\"select * from Invoice order by MetaData.CreateTime desc maxresults 200\") + '&minorversion=65' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "options": {} }, "id": "2a9a9ca3-aecf-48d9-813d-0064f3f518ee", "name": "Get Last Invoices (CNL)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1920, 1664 ], "credentials": { "quickBooksOAuth2Api": { "id": "BPkRunJXtL1mqASg", "name": "CNL QUICKBOOKS" } } }, { "parameters": { "jsCode": "const ctx = $('Decide Invoice Action').item.json;\nconst response = $json;\n\nif (response?.error) {\n throw new Error(`Failed to fetch last invoices: ${response.error.message ?? 'unknown error'}`);\n}\n\nconst invoices = response?.QueryResponse?.Invoice ?? [];\n\n// Required pattern: INV#### (example: INV9243)\nconst prefix = 'INV';\nlet maxNumeric = null;\n\nfor (const inv of invoices) {\n const doc = String(inv?.DocNumber ?? '').trim();\n const match = doc.match(/^INV(\\d+)$/i);\n if (!match) continue;\n\n const n = Number.parseInt(match[1], 10);\n if (!Number.isFinite(n)) continue;\n if (maxNumeric === null || n > maxNumeric) maxNumeric = n;\n}\n\nif (maxNumeric === null) {\n throw new Error('No INV#### invoice DocNumber found in the last 200 invoices. Increase maxresults or confirm QuickBooks invoice numbering uses INV + digits.');\n}\n\nconst nextDoc = `${prefix}${maxNumeric + 1}`;\n\nreturn [{\n json: {\n ...ctx,\n qb_invoice_payload: {\n ...(ctx.qb_invoice_payload ?? {}),\n DocNumber: nextDoc\n },\n generated_invoice_number: nextDoc\n }\n}];" }, "id": "4dcfa5fc-ba52-4aaa-96ae-a55e4e5679e2", "name": "Set Next DocNumber (CNL)", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2144, 1664 ] }, { "parameters": { "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/query?query=' + encodeURIComponent(\"select * from Invoice order by MetaData.CreateTime desc maxresults 200\") + '&minorversion=65' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "options": {} }, "id": "9ca3b673-9e12-48e2-93ec-76640e0651a7", "name": "Get Last Invoices (ISHERWOOD)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1920, 2176 ], "credentials": { "quickBooksOAuth2Api": { "id": "qIOWSWNJQneDXGmH", "name": "ISHERWOODMINING" } } }, { "parameters": { "jsCode": "const ctx = $('Decide Invoice Action').item.json;\nconst response = $json;\n\nif (response?.error) {\n throw new Error(`Failed to fetch last invoices: ${response.error.message ?? 'unknown error'}`);\n}\n\nconst invoices = response?.QueryResponse?.Invoice ?? [];\n\n// Required pattern: INV#### (example: INV9243)\nconst prefix = 'INV';\nlet maxNumeric = null;\n\nfor (const inv of invoices) {\n const doc = String(inv?.DocNumber ?? '').trim();\n const match = doc.match(/^INV(\\d+)$/i);\n if (!match) continue;\n\n const n = Number.parseInt(match[1], 10);\n if (!Number.isFinite(n)) continue;\n if (maxNumeric === null || n > maxNumeric) maxNumeric = n;\n}\n\nif (maxNumeric === null) {\n throw new Error('No INV#### invoice DocNumber found in the last 200 invoices. Increase maxresults or confirm QuickBooks invoice numbering uses INV + digits.');\n}\n\nconst nextDoc = `${prefix}${maxNumeric + 1}`;\n\nreturn [{\n json: {\n ...ctx,\n qb_invoice_payload: {\n ...(ctx.qb_invoice_payload ?? {}),\n DocNumber: nextDoc\n },\n generated_invoice_number: nextDoc\n }\n}];" }, "id": "667292c7-bcb3-4baf-af6c-5d547a37e677", "name": "Set Next DocNumber (ISHERWOOD)", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2144, 2176 ] }, { "parameters": { "method": "POST", "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/invoice?minorversion=65' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ {\n ...$json.qb_invoice_payload,\n DocNumber: $json.current_doc_number || $json.generated_invoice_number\n} }}", "options": {} }, "id": "d4bc218a-f116-440f-833c-2edfeadae603", "name": "Create Invoice (ISHERWOOD)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 2368, 2176 ], "credentials": { "quickBooksOAuth2Api": { "id": "qIOWSWNJQneDXGmH", "name": "ISHERWOODMINING" } }, "continueOnFail": true }, { "parameters": { "operation": "binaryToPropery", "destinationKey": "pdf_base64", "options": { "encoding": "base64", "keepSource": "both" } }, "type": "n8n-nodes-base.extractFromFile", "typeVersion": 1.1, "position": [ 3264, 2336 ], "id": "5ed1ba9d-4f40-4e3c-b334-0dcee506de9e", "name": "Extract from File" }, { "parameters": { "operation": "binaryToPropery", "destinationKey": "pdf_base64", "options": { "encoding": "base64", "keepSource": "both" } }, "type": "n8n-nodes-base.extractFromFile", "typeVersion": 1.1, "position": [ 3264, 1552 ], "id": "fa5a97e4-58b3-457a-ab7a-782bff8ebf80", "name": "Extract from File1" }, { "parameters": { "jsCode": "const MAX_RETRIES = 10;\nconst ctx = $('Set Next DocNumber (ISHERWOOD)').item.json;\nconst createResponse = $input.first().json;\n\n// --- Case 1: Success ---\nif (!createResponse.error && createResponse.Invoice?.Id) {\n const invoiceId = String(createResponse.Invoice.Id);\n const docNumber = String(createResponse.Invoice.DocNumber || '');\n\n return [{\n json: {\n ...ctx,\n qb_action: 'created',\n status: 'success',\n created_invoice_id: invoiceId,\n generated_invoice_number: docNumber,\n current_doc_number: docNumber,\n http_status: 200\n }\n }];\n}\n\n// --- Case 2: Duplicate Document Number ---\nconst rawBody = createResponse?.error?.response?.body\n || createResponse?.error?.body\n || createResponse?.error?.description \n || createResponse?.error?.message\n || '';\nconst bodyText = typeof rawBody === 'string' ? rawBody : JSON.stringify(rawBody);\n\nif (bodyText.includes('Duplicate Document Number Error') || bodyText.includes('code\":\"6140')) {\n \n // 1. Extract the exact DocNumber QuickBooks complained about\n const match = bodyText.match(/DocNumber=([A-Z0-9]+)/i);\n const conflictingDoc = match ? match[1] : null;\n\n if (!conflictingDoc) {\n return [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `Duplicate but could not parse DocNumber from error.`,\n http_status: 409\n }\n }];\n }\n\n // 2. Parse the prefix and the numeric part\n const docMatch = conflictingDoc.match(/^([A-Za-z]*)(\\d+)$/);\n if (!docMatch) {\n return [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `Duplicate but could not parse prefix/number: ${conflictingDoc}`,\n http_status: 409\n }\n }];\n }\n\n const [, prefix, numStr] = docMatch;\n \n // 3. Calculate retry count statelessly using math\n const startDocMatch = (ctx.generated_invoice_number || '').match(/^([A-Za-z]*)(\\d+)$/);\n let retryCount = 0;\n if (startDocMatch) {\n retryCount = parseInt(numStr, 10) - parseInt(startDocMatch[2], 10);\n }\n\n // 4. Check limit\n if (retryCount >= MAX_RETRIES) {\n return [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `Failed after ${retryCount} attempts. Last conflict: ${conflictingDoc}`,\n http_status: 409\n }\n }];\n }\n\n // 5. Generate NEXT doc number\n const nextNum = String(parseInt(numStr, 10) + 1).padStart(numStr.length, '0');\n const nextDoc = `${prefix}${nextNum}`;\n\n // Return item back to the loop WITH the explicit retry flag\n return [{\n json: {\n ...ctx,\n qb_action: 'retry', // <--- This explicitly tells the router to loop\n current_doc_number: nextDoc,\n retry_count: retryCount + 1,\n last_error: `Duplicate: tried ${conflictingDoc}, now trying ${nextDoc}`\n }\n }];\n}\n\n// --- Case 3: Other error ---\nreturn [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `QB create failed: ${bodyText.slice(0, 500)}`,\n http_status: createResponse?.error?.statusCode || 500\n }\n}];" }, "id": "26827664-0b24-4942-8dc6-1ae0b1f657a3", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2592, 2176 ], "name": "Check Result (ISHERWOOD)" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "condition-1", "leftValue": "={{ $json.qb_action }}", "rightValue": "created", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "29c89970-db02-4106-ba33-75eea04f73e8", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 2816, 2176 ], "name": "Retry Router (ISHERWOOD)" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "condition-1", "leftValue": "={{ $json.qb_action }}", "rightValue": "created", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "f01992a8-17ea-4272-8f5a-d8f8e454c061", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 2816, 1600 ], "name": "Retry Router (CNL)" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "cond-ish-error", "leftValue": "={{ $json.qb_action }}", "rightValue": "error", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "455b65b6-6f65-458d-9c17-d404792d15e1", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 3024, 2144 ], "name": "Retry Router 2 (ISHERWOOD)" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "cond-cnl-error", "leftValue": "={{ $json.qb_action }}", "rightValue": "error", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "5d4d5849-d057-49ee-abf3-29e6b2e6cbf0", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 3040, 1856 ], "name": "Retry Router 2 (CNL)" }, { "parameters": { "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/invoice/' + $json.created_invoice_id + '/pdf' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/pdf" } ] }, "options": { "response": { "response": { "responseFormat": "file" } } } }, "id": "e2dfc064-b0e9-41c9-93b3-d81e2673779e", "name": "Download QBO Invoice", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3040, 2336 ], "credentials": { "quickBooksOAuth2Api": { "id": "qIOWSWNJQneDXGmH", "name": "ISHERWOODMINING" } } }, { "parameters": { "url": "={{ 'https://quickbooks.api.intuit.com/v3/company/' + $json.qb_realm_id + '/invoice/' + $json.created_invoice_id + '/pdf' }}", "authentication": "predefinedCredentialType", "nodeCredentialType": "quickBooksOAuth2Api", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/pdf" } ] }, "options": { "response": { "response": { "responseFormat": "file" } } } }, "id": "fb902055-e411-4f6e-ab85-7c80390962e0", "name": "Download QBO Invoice1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3040, 1552 ], "credentials": { "quickBooksOAuth2Api": { "id": "BPkRunJXtL1mqASg", "name": "CNL QUICKBOOKS" } } }, { "parameters": { "jsCode": "const MAX_RETRIES = 10;\nconst ctx = $('Set Next DocNumber (CNL)').item.json;\nconst createResponse = $input.first().json;\n\n// --- Case 1: Success ---\nif (!createResponse.error && createResponse.Invoice?.Id) {\n const invoiceId = String(createResponse.Invoice.Id);\n const docNumber = String(createResponse.Invoice.DocNumber || '');\n\n return [{\n json: {\n ...ctx,\n qb_action: 'created',\n status: 'success',\n created_invoice_id: invoiceId,\n generated_invoice_number: docNumber,\n current_doc_number: docNumber,\n http_status: 200\n }\n }];\n}\n\n// --- Case 2: Duplicate Document Number ---\nconst rawBody = createResponse?.error?.response?.body\n || createResponse?.error?.body\n || createResponse?.error?.description \n || createResponse?.error?.message\n || '';\nconst bodyText = typeof rawBody === 'string' ? rawBody : JSON.stringify(rawBody);\n\nif (bodyText.includes('Duplicate Document Number Error') || bodyText.includes('code\":\"6140')) {\n \n // 1. Extract the exact DocNumber QuickBooks complained about\n const match = bodyText.match(/DocNumber=([A-Z0-9]+)/i);\n const conflictingDoc = match ? match[1] : null;\n\n if (!conflictingDoc) {\n return [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `Duplicate but could not parse DocNumber from error.`,\n http_status: 409\n }\n }];\n }\n\n // 2. Parse the prefix and the numeric part\n const docMatch = conflictingDoc.match(/^([A-Za-z]*)(\\d+)$/);\n if (!docMatch) {\n return [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `Duplicate but could not parse prefix/number: ${conflictingDoc}`,\n http_status: 409\n }\n }];\n }\n\n const [, prefix, numStr] = docMatch;\n \n // 3. Calculate retry count statelessly using math\n const startDocMatch = (ctx.generated_invoice_number || '').match(/^([A-Za-z]*)(\\d+)$/);\n let retryCount = 0;\n if (startDocMatch) {\n retryCount = parseInt(numStr, 10) - parseInt(startDocMatch[2], 10);\n }\n\n // 4. Check limit\n if (retryCount >= MAX_RETRIES) {\n return [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `Failed after ${retryCount} attempts. Last conflict: ${conflictingDoc}`,\n http_status: 409\n }\n }];\n }\n\n // 5. Generate NEXT doc number\n const nextNum = String(parseInt(numStr, 10) + 1).padStart(numStr.length, '0');\n const nextDoc = `${prefix}${nextNum}`;\n\n // Return item back to the loop WITH the explicit retry flag\n return [{\n json: {\n ...ctx,\n qb_action: 'retry', // <--- This explicitly tells the router to loop\n current_doc_number: nextDoc,\n retry_count: retryCount + 1,\n last_error: `Duplicate: tried ${conflictingDoc}, now trying ${nextDoc}`\n }\n }];\n}\n\n// --- Case 3: Other error ---\nreturn [{\n json: {\n ...ctx,\n qb_action: 'error',\n status: 'error',\n message: `QB create failed: ${bodyText.slice(0, 500)}`,\n http_status: createResponse?.error?.statusCode || 500\n }\n}];" }, "id": "90806acb-f9fd-4d68-a2fc-ee2a5cd85860", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2592, 1600 ], "name": "Check Result (CNL)" }, { "parameters": { "jsCode": "const now = new Date().toISOString();\nconst sourceItem = $input.first();\nconst ctx = sourceItem?.json ?? {};\nconst sourceBinary = sourceItem?.binary ?? {};\nconst invoiceNumber = String(ctx.invoice_number ?? '').trim();\nconst invoiceId = String(ctx.invoice_id ?? '').trim();\nconst invoiceLink = String(ctx.invoice_link ?? '').trim();\nconst billingCompany = String(ctx.billing_company ?? '').trim();\nconst invoiceCompany = String(ctx.invoice_company ?? ctx.company ?? '').trim();\nconst sentById = String(ctx.sent_by_id ?? '').trim();\nconst sentByName = String(ctx.sent_by_name ?? '').trim();\nconst orderItemIds = Array.isArray(ctx.order_item_ids)\n ? ctx.order_item_ids.map((value) => String(value ?? '').trim()).filter(Boolean)\n : [];\nconst invoiceDate = String(ctx.qb_invoice_date ?? '').trim() || now.slice(0, 10);\n\nconst binaryKeys = Object.keys(sourceBinary);\nconst rawBinary = sourceBinary.qb_invoice_pdf ?? sourceBinary.data ?? (binaryKeys.length > 0 ? sourceBinary[binaryKeys[0]] : null);\n\nif (!invoiceNumber || orderItemIds.length === 0) {\n return [{\n json: {\n ...ctx,\n status: 'error',\n message: 'Missing invoice write-back fields',\n http_status: 500\n }\n }];\n}\n\nif (!rawBinary?.data) {\n return [{\n json: {\n ...ctx,\n status: 'error',\n message: 'Missing invoice PDF binary for PocketBase upload',\n http_status: 500\n }\n }];\n}\n\nconst uploadBinary = {\n ...rawBinary,\n mimeType: rawBinary.mimeType || 'application/pdf',\n fileName: `invoice_${invoiceNumber || 'invoice'}.pdf`\n};\n\nreturn orderItemIds.map((orderItemId) => {\n const pbPatch = {\n item_status: 'invoiced',\n order_item_details: {\n invoice: {\n number: invoiceNumber,\n date: invoiceDate,\n setAt: now,\n setBy: sentById,\n setByName: sentByName,\n billingCompany,\n invoiceCompany,\n qbInvoiceId: invoiceId,\n qbInvoiceLink: invoiceLink\n }\n }\n };\n\n return {\n json: {\n ...ctx,\n order_item_id: orderItemId,\n pb_patch: pbPatch\n },\n binary: {\n qb_invoice_pdf: uploadBinary\n }\n };\n});" }, "id": "b719bf09-d9b4-41ab-aeba-bd997e3008d8", "name": "Build PocketBase Invoice Update", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4144, 1472 ] }, { "parameters": { "method": "PATCH", "url": "=https://pocketbase-gnqc88suy8fqk6wyryjjdpvl.169.239.180.130.sslip.io/api/collections/order_items/records/{{ $json.order_item_id }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Content-Type", "value": "application/json" }, { "name": "Authorization", "value": "={{ $env.PB_ADMIN_TOKEN }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ $json.pb_patch }}", "options": { "timeout": 15000 } }, "id": "5f1c45fe-4ba3-4ec3-a88a-b716e22fd16f", "name": "Update Order Item In PocketBase", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 5104, 1408 ], "continueOnFail": true }, { "parameters": { "jsCode": "const inputs = $input.all();\nconst sourceItems = $('Build PocketBase Invoice Update').all();\nconst firstSource = sourceItems[0]?.json ?? {};\n\nif (sourceItems.length === 1 && firstSource.status === 'error' && !firstSource.order_item_id && !firstSource.pb_patch) {\n return [{ json: firstSource }];\n}\n\nif (inputs.length === 0) {\n return [{\n json: {\n ...firstSource,\n status: 'error',\n message: 'PocketBase write-back returned no items',\n http_status: 500\n }\n }];\n}\n\nconst failures = [];\nfor (let index = 0; index < inputs.length; index += 1) {\n const payload = inputs[index]?.json ?? {};\n const source = sourceItems[index]?.json ?? firstSource;\n if (payload.error) {\n const details = payload.error?.message || payload.error?.description || payload.error?.error || JSON.stringify(payload.error);\n failures.push(`${source.order_item_id || 'unknown'}: ${String(details).slice(0, 250)}`);\n }\n}\n\nif (failures.length > 0) {\n return [{\n json: {\n ...firstSource,\n status: 'error',\n message: `PocketBase write-back failed for ${failures.length} item(s): ${failures.join('; ')}`,\n http_status: 500\n }\n }];\n}\n\nreturn [{\n json: {\n status: 'success',\n invoice_number: String(firstSource.invoice_number ?? ''),\n invoice_id: String(firstSource.invoice_id ?? ''),\n invoice_link: String(firstSource.invoice_link ?? ''),\n qb_invoice_date: String(firstSource.qb_invoice_date ?? ''),\n invoice_company: String(firstSource.invoice_company ?? firstSource.company ?? ''),\n company: String(firstSource.invoice_company ?? firstSource.company ?? ''),\n order_number: String(firstSource.order_number ?? ''),\n billing_company: String(firstSource.billing_company ?? ''),\n order_item_ids: Array.isArray(firstSource.order_item_ids) ? firstSource.order_item_ids : [],\n sent_by_id: String(firstSource.sent_by_id ?? ''),\n sent_by_name: String(firstSource.sent_by_name ?? ''),\n line_count: Number(firstSource.line_count ?? 0),\n pdf_base64: firstSource.pdf_base64 ?? null,\n pocketbase_updated_count: inputs.length\n }\n}];" }, "id": "cc0ca05b-422e-4827-883f-67eefd21b1fe", "name": "Finalize PocketBase Invoice Update", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5296, 1408 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "pb-writeback-success-check", "leftValue": "={{ $json.status }}", "rightValue": "success", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "563038e9-3cd7-4cb3-9167-f47d4ea25e15", "name": "PocketBase Write-Back Is Success?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 5488, 1408 ] }, { "parameters": { "method": "PATCH", "url": "=https://pocketbase-gnqc88suy8fqk6wyryjjdpvl.169.239.180.130.sslip.io/api/collections/order_items/records/{{ $('Build PocketBase Invoice Update').item.json.order_item_ids[0] }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Authorization", "value": "=Bearer {{ $('Merge').item.json.token }}" } ] }, "sendBody": true, "contentType": "multipart-form-data", "bodyParameters": { "parameters": [ { "parameterType": "formBinaryData", "name": "qb_invoice_pdf", "inputDataFieldName": "qb_invoice_pdf" } ] }, "options": { "response": { "response": { "responseFormat": "file", "outputPropertyName": "qb_invoice_pdf" } }, "timeout": 15000 } }, "id": "f88e4f4e-9418-475f-9a27-1f7cfd84e3ed", "name": "Upload Invoice PDF To PocketBase", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 4368, 1472 ], "continueOnFail": true }, { "parameters": { "jsCode": "const inputs = $input.all();\nconst sourceItems = $('Build PocketBase Invoice Update').all();\nconst firstSource = sourceItems[0]?.json ?? {};\n\nif (sourceItems.length === 1 && firstSource.status === 'error' && !firstSource.order_item_id && !firstSource.pb_patch) {\n return [{ json: firstSource }];\n}\n\nif (inputs.length === 0) {\n return [{\n json: {\n ...firstSource,\n status: 'error',\n message: 'PocketBase invoice PDF upload returned no items',\n http_status: 500\n }\n }];\n}\n\nconst failures = [];\nfor (let index = 0; index < inputs.length; index += 1) {\n const payload = inputs[index]?.json ?? {};\n const source = sourceItems[index]?.json ?? firstSource;\n if (payload.error) {\n const details = payload.error?.message || payload.error?.description || payload.error?.error || JSON.stringify(payload.error);\n failures.push(`${source.order_item_id || 'unknown'}: ${String(details).slice(0, 250)}`);\n }\n}\n\nif (failures.length > 0) {\n return [{\n json: {\n ...firstSource,\n status: 'error',\n message: `PocketBase invoice PDF upload failed for ${failures.length} item(s): ${failures.join('; ')}`,\n http_status: 500\n }\n }];\n}\n\nreturn sourceItems.map((item) => ({\n json: item.json\n}));" }, "id": "2107a950-858f-4f63-86a4-b45a4deac86f", "name": "Finalize Invoice PDF Upload", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4592, 1472 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 1 }, "conditions": [ { "id": "invoice-upload-success-check", "leftValue": "={{ $json.status }}", "rightValue": "success", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "7ef154a6-bc39-45d2-87df-f58a41d83e45", "name": "Invoice PDF Upload Is Success?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 4816, 1472 ] }, { "parameters": { "jsCode": "const pb = await this.helpers.httpRequest({\n method: 'POST',\n url: `https://pocketbase-gnqc88suy8fqk6wyryjjdpvl.169.239.180.130.sslip.io/api/collections/_superusers/auth-with-password`,\n headers: { 'Content-Type': 'application/json' },\n body: { identity: 'david.els1@outlook.com', password: '1234567890' },\n json: true,\n});\nreturn [{ json: { token: pb.token, _pb: pb } }];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -1440, 2352 ], "id": "e50f43e2-36bf-48e5-ad29-5cb8459cfe7b", "name": "GET PB TOKEN" }, { "parameters": { "mode": "combine", "combineBy": "combineAll", "options": {} }, "type": "n8n-nodes-base.merge", "typeVersion": 3.2, "position": [ -1232, 2080 ], "id": "41609940-5d26-41e3-a06d-096a9c89582b", "name": "Merge" } ], "pinData": { "Webhook Trigger": [ { "json": { "headers": { "host": "n8nmac.apphub.co.za", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5.2 Safari/605.1.15", "content-length": "332", "accept": "*/*", "accept-encoding": "gzip, deflate, br, zstd", "accept-language": "en-US,en;q=0.9", "content-type": "application/json", "origin": "http://localhost:4000", "priority": "u=3, i", "referer": "http://localhost:4000/", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "cross-site", "x-forwarded-for": "196.39.29.2", "x-forwarded-host": "n8nmac.apphub.co.za", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-forwarded-server": "aa6e8c40473e", "x-real-ip": "196.39.29.2" }, "params": {}, "query": {}, "body": { "order_number": "TEST COLLECION POOL", "billing_company": "CNL", "invoice_company": "Adal Engineering", "customer_id": "236", "customer_name": "Adal Engineering", "items": [ { "name": "Welding rod 3.2mm E6013 5kg pack mild steel", "qty": 1, "price": 0 } ], "order_item_ids": [ "m74xvviv2hpzz2d" ], "sent_by_id": "k045yfeze92ckx9", "sent_by_name": "David Els" }, "webhookUrl": "https://n8nmac.apphub.co.za/webhook/wfdash-quickbooks-invoice-creator", "executionMode": "production" } } ] }, "connections": { "Webhook Trigger": { "main": [ [ { "node": "GET PB TOKEN", "type": "main", "index": 0 }, { "node": "Merge", "type": "main", "index": 0 } ] ] }, "Normalize Request": { "main": [ [ { "node": "Is Authorized?", "type": "main", "index": 0 } ] ] }, "Is Authorized?": { "main": [ [ { "node": "Validate Payload", "type": "main", "index": 0 } ], [ { "node": "Unauthorized Response", "type": "main", "index": 0 } ] ] }, "Unauthorized Response": { "main": [ [ { "node": "Respond Error", "type": "main", "index": 0 } ] ] }, "Validate Payload": { "main": [ [ { "node": "Is Payload Valid?", "type": "main", "index": 0 } ] ] }, "Is Payload Valid?": { "main": [ [ { "node": "If2", "type": "main", "index": 0 } ], [ { "node": "Validation Error Response", "type": "main", "index": 0 } ] ] }, "Validation Error Response": { "main": [ [ { "node": "Respond Error", "type": "main", "index": 0 } ] ] }, "Mapping Error Response": { "main": [ [ { "node": "Respond Error", "type": "main", "index": 0 } ] ] }, "Set CNL Context": { "main": [ [ { "node": "QB Context", "type": "main", "index": 0 } ] ] }, "Set ISHERWOOD Context": { "main": [ [ { "node": "QB Context", "type": "main", "index": 0 } ] ] }, "QB Context": { "main": [ [ { "node": "Route Search Company", "type": "main", "index": 0 } ] ] }, "Decide Invoice Action": { "main": [ [ { "node": "Action Is Error?", "type": "main", "index": 0 } ] ] }, "Action Is Error?": { "main": [ [ { "node": "Build QB Error Response", "type": "main", "index": 0 } ], [ { "node": "Action Is Existing?", "type": "main", "index": 0 } ] ] }, "Action Is Existing?": { "main": [ [ { "node": "Build Existing Response", "type": "main", "index": 0 } ], [ { "node": "Route Create Company", "type": "main", "index": 0 } ] ] }, "Build Existing Response": { "main": [ [ { "node": "Respond Success", "type": "main", "index": 0 } ] ] }, "Build Created Response": { "main": [ [ { "node": "Created Is Success?", "type": "main", "index": 0 } ] ] }, "Created Is Success?": { "main": [ [ { "node": "Build PocketBase Invoice Update", "type": "main", "index": 0 } ], [ { "node": "Respond Error", "type": "main", "index": 0 } ] ] }, "Build QB Error Response": { "main": [ [ { "node": "Respond Error", "type": "main", "index": 0 } ] ] }, "GET ISHERWOOD CUSTOMERS1": { "main": [ [ { "node": "Fuzzy Match Customers", "type": "main", "index": 0 } ] ] }, "GET CNL CUSTOMERS1": { "main": [ [ { "node": "Fuzzy Match Customers", "type": "main", "index": 0 } ] ] }, "GET CUSTOMERS WEBHOOK": { "main": [ [ { "node": "Normalize Customer Search Request", "type": "main", "index": 0 } ] ] }, "Normalize Customer Search Request": { "main": [ [ { "node": "Is Customer Authorized?", "type": "main", "index": 0 } ] ] }, "Is Customer Authorized?": { "main": [ [ { "node": "Validate Customer Search", "type": "main", "index": 0 } ], [ { "node": "Build Customer Unauthorized", "type": "main", "index": 0 } ] ] }, "Build Customer Unauthorized": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] }, "Validate Customer Search": { "main": [ [ { "node": "Is Customer Search Valid?", "type": "main", "index": 0 } ] ] }, "Is Customer Search Valid?": { "main": [ [ { "node": "If1", "type": "main", "index": 0 } ], [ { "node": "Build Customer Validation Error", "type": "main", "index": 0 } ] ] }, "Build Customer Validation Error": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] }, "Build Customer Mapping Error": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] }, "Fuzzy Match Customers": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] }, "If1": { "main": [ [ { "node": "GET ISHERWOOD CUSTOMERS1", "type": "main", "index": 0 } ], [ { "node": "GET CNL CUSTOMERS1", "type": "main", "index": 0 } ] ] }, "If2": { "main": [ [ { "node": "Set CNL Context", "type": "main", "index": 0 } ], [ { "node": "Set ISHERWOOD Context", "type": "main", "index": 0 } ] ] }, "Route Search Company": { "main": [ [ { "node": "Search Existing Invoice (CNL)", "type": "main", "index": 0 } ], [ { "node": "Search Existing Invoice (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Search Existing Invoice (CNL)": { "main": [ [ { "node": "Decide Invoice Action", "type": "main", "index": 0 } ] ] }, "Search Existing Invoice (ISHERWOOD)": { "main": [ [ { "node": "Decide Invoice Action", "type": "main", "index": 0 } ] ] }, "Route Create Company": { "main": [ [ { "node": "Get Last Invoices (CNL)", "type": "main", "index": 0 } ], [ { "node": "Get Last Invoices (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Get Last Invoices (CNL)": { "main": [ [ { "node": "Set Next DocNumber (CNL)", "type": "main", "index": 0 } ] ] }, "Get Last Invoices (ISHERWOOD)": { "main": [ [ { "node": "Set Next DocNumber (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Extract from File": { "main": [ [ { "node": "Build Created Response", "type": "main", "index": 0 } ] ] }, "Extract from File1": { "main": [ [ { "node": "Build Created Response", "type": "main", "index": 0 } ] ] }, "Set Next DocNumber (ISHERWOOD)": { "main": [ [ { "node": "Create Invoice (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Create Invoice (ISHERWOOD)": { "main": [ [ { "node": "Check Result (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Check Result (ISHERWOOD)": { "main": [ [ { "node": "Retry Router (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Retry Router (ISHERWOOD)": { "main": [ [ { "node": "Download QBO Invoice", "type": "main", "index": 0 } ], [ { "node": "Retry Router 2 (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Set Next DocNumber (CNL)": { "main": [ [ { "node": "Create Invoice (CNL)", "type": "main", "index": 0 } ] ] }, "Create Invoice (CNL)": { "main": [ [ { "node": "Check Result (CNL)", "type": "main", "index": 0 } ] ] }, "Retry Router (CNL)": { "main": [ [ { "node": "Download QBO Invoice1", "type": "main", "index": 0 } ], [ { "node": "Retry Router 2 (CNL)", "type": "main", "index": 0 } ] ] }, "Retry Router 2 (ISHERWOOD)": { "main": [ [ { "node": "Respond Error", "type": "main", "index": 0 } ], [ { "node": "Create Invoice (ISHERWOOD)", "type": "main", "index": 0 } ] ] }, "Retry Router 2 (CNL)": { "main": [ [ { "node": "Respond Error", "type": "main", "index": 0 } ], [ { "node": "Create Invoice (CNL)", "type": "main", "index": 0 } ] ] }, "Download QBO Invoice": { "main": [ [ { "node": "Extract from File", "type": "main", "index": 0 } ] ] }, "Download QBO Invoice1": { "main": [ [ { "node": "Extract from File1", "type": "main", "index": 0 } ] ] }, "Check Result (CNL)": { "main": [ [ { "node": "Retry Router (CNL)", "type": "main", "index": 0 } ] ] }, "Build PocketBase Invoice Update": { "main": [ [ { "node": "Upload Invoice PDF To PocketBase", "type": "main", "index": 0 } ] ] }, "Upload Invoice PDF To PocketBase": { "main": [ [ { "node": "Finalize Invoice PDF Upload", "type": "main", "index": 0 } ] ] }, "Finalize Invoice PDF Upload": { "main": [ [ { "node": "Invoice PDF Upload Is Success?", "type": "main", "index": 0 } ] ] }, "Invoice PDF Upload Is Success?": { "main": [ [ { "node": "Update Order Item In PocketBase", "type": "main", "index": 0 } ], [ { "node": "Build QB Error Response", "type": "main", "index": 0 } ] ] }, "Update Order Item In PocketBase": { "main": [ [ { "node": "Finalize PocketBase Invoice Update", "type": "main", "index": 0 } ] ] }, "Finalize PocketBase Invoice Update": { "main": [ [ { "node": "PocketBase Write-Back Is Success?", "type": "main", "index": 0 } ] ] }, "PocketBase Write-Back Is Success?": { "main": [ [ { "node": "Respond Success", "type": "main", "index": 0 } ], [ { "node": "Build QB Error Response", "type": "main", "index": 0 } ] ] }, "GET PB TOKEN": { "main": [ [ { "node": "Merge", "type": "main", "index": 1 } ] ] }, "Merge": { "main": [ [ { "node": "Normalize Request", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1", "binaryMode": "separate" }, "versionId": "36e66bc6-6af7-4d47-a9f1-3094b58d420e", "meta": { "templateCredsSetupCompleted": true, "instanceId": "375b0a7073a999c2b9437a1ec848664e8305503237ae3684ba9dca3ce53ea61b" }, "nodeGroups": [], "id": "QH2Kk8fPHp6wKkjz", "tags": [] }