From 28c3c7bd0a84a394e5b039b63f99b603fd0c1904 Mon Sep 17 00:00:00 2001 From: renee-png Date: Fri, 12 Jun 2026 18:58:13 -0400 Subject: [PATCH] Bills import: degrade gracefully when Buildium API key lacks Vendors permission GET /v1/vendors 403s on keys without the Vendors scope; import bills without vendor links instead of failing the pull, and surface it in results. Co-Authored-By: Claude Opus 4.8 --- supabase/functions/buildium-sync/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/supabase/functions/buildium-sync/index.ts b/supabase/functions/buildium-sync/index.ts index e2f88f7..ef49a6d 100644 --- a/supabase/functions/buildium-sync/index.ts +++ b/supabase/functions/buildium-sync/index.ts @@ -2096,8 +2096,17 @@ Deno.serve(async (req) => { if (syncType === "bills") { const { bIdToLocalId } = await getAssociationMaps(); - // 1) Sync vendors so bills can be linked - const buildiumVendors = await buildiumFetchAll("/v1/vendors", clientId, clientSecret); + // 1) Sync vendors so bills can be linked. The Buildium API key may lack + // the Vendors permission (403) — degrade gracefully: import bills without + // vendor links instead of failing the whole pull. + let buildiumVendors: any[] = []; + let vendorsAccessible = true; + try { + buildiumVendors = await buildiumFetchAll("/v1/vendors", clientId, clientSecret); + } catch (e) { + vendorsAccessible = false; + console.warn(`[bills] vendors fetch failed — continuing without vendor sync: ${e}`); + } // Paginated fetch so large vendor sets don't get truncated at 1000 rows const existingVendors: any[] = []; { @@ -2770,6 +2779,7 @@ Deno.serve(async (req) => { payments_held: paymentsHeld, checks_created: checksCreated, checks_held: checksHeld, + ...(vendorsAccessible ? {} : { vendors_unavailable: "Buildium API key lacks the Vendors permission — bills imported without vendor links" }), }; await supabase.from("company_settings").upsert(