From 2b3b50596cc64e96e7ff4572df3e7e2308c44d1b Mon Sep 17 00:00:00 2001 From: SJCoetz Date: Thu, 9 Jul 2026 23:25:05 +0200 Subject: [PATCH] feat(po): include additional_attachments in send-email webhook --- .../v1/purchase-orders/[id]/send-email/route.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/app/api/v1/purchase-orders/[id]/send-email/route.ts b/src/app/api/v1/purchase-orders/[id]/send-email/route.ts index bdb47e9..e115049 100644 --- a/src/app/api/v1/purchase-orders/[id]/send-email/route.ts +++ b/src/app/api/v1/purchase-orders/[id]/send-email/route.ts @@ -146,6 +146,17 @@ export async function POST( const supplierName = result.purchaseOrder.expand?.supplier?.suppliername || ""; + // Additional files (supplier quote, drawing, NDA) the operator + // wants to send with this PO. Sits alongside `documents` (the + // versioned PDF). The n8n workflow reads this array and attaches + // each token to the outbound SMTP message via the PB file proxy. + const additionalRaw = result.purchaseOrder.additional_attachments ?? []; + const additionalAttachments = Array.isArray(additionalRaw) + ? additionalRaw + : additionalRaw + ? [additionalRaw] + : []; + const webhookBody = { trigger: "manual_send", poId, @@ -186,6 +197,10 @@ export async function POST( }, ] : [], + // string[] of PB-stored tokens. The n8n workflow fetches each + // file via the PB file proxy and attaches it to the outbound + // SMTP message alongside `attachments` (the versioned PO PDF). + additional_attachments: additionalAttachments, // PB admin token + URL, used by the workflow's HTTP Request node // to fetch the PDF directly from PB (Bearer-equivalent). PB // accepts the admin token in either `Authorization: ` or