From 9a6cc78332e487ff01ff5f459eda149e17c6e252 Mon Sep 17 00:00:00 2001 From: Adam Gough <77861281+aadamgough@users.noreply.github.com> Date: Wed, 10 Sep 2025 17:55:35 -0700 Subject: [PATCH] fix(sheets): fixed google sheets update (#1311) Google sheets append was sending an invalid shape to the google sheets api. This PR fixes this by having similar logic to what is in append.ts --- apps/sim/tools/google_sheets/append.ts | 2 -- apps/sim/tools/google_sheets/update.ts | 21 ++++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/apps/sim/tools/google_sheets/append.ts b/apps/sim/tools/google_sheets/append.ts index ef214a4350..e17b76f1f3 100644 --- a/apps/sim/tools/google_sheets/append.ts +++ b/apps/sim/tools/google_sheets/append.ts @@ -107,8 +107,6 @@ export const appendTool: ToolConfig { let processedValues: any = params.values || [] - // Handle array of objects + // Minimal shape enforcement: Google requires a 2D array + if (!Array.isArray(processedValues)) { + processedValues = [[processedValues]] + } else if (!processedValues.every((item: any) => Array.isArray(item))) { + processedValues = (processedValues as any[]).map((row: any) => + Array.isArray(row) ? row : [row] + ) + } + + // Handle array of objects (existing behavior) if ( Array.isArray(processedValues) && processedValues.length > 0 && typeof processedValues[0] === 'object' && !Array.isArray(processedValues[0]) ) { - // It's an array of objects - - // First, extract all unique keys from all objects to create headers const allKeys = new Set() processedValues.forEach((obj: any) => { if (obj && typeof obj === 'object') { @@ -100,15 +106,12 @@ export const updateTool: ToolConfig { if (!obj || typeof obj !== 'object') { - // Handle non-object items by creating an array with empty values return Array(headers.length).fill('') } return headers.map((key) => { const value = obj[key] - // Handle nested objects/arrays by converting to JSON string if (value !== null && typeof value === 'object') { return JSON.stringify(value) } @@ -116,7 +119,6 @@ export const updateTool: ToolConfig