July
Julyβ€’7mo ago

July - Hey, the google sheet add row doesnt see...

Hey, the google sheet add row doesnt seem to do anything, also i dont see it in the docs πŸ‘€
Solution:
Hi @July, The Google Sheet Add Row node is working perfectly.
No description
No description
Jump to solution
7 Replies
Solution
Gaurav Chadha
Gaurav Chadhaβ€’7mo ago
Hi @July, The Google Sheet Add Row node is working perfectly.
No description
No description
July
Julyβ€’7mo ago
oo okay i will try again
Gaurav Chadha
Gaurav Chadhaβ€’7mo ago
Could you please confirm the field values, if they are correct? You can refer to the info tooltip.
No description
July
Julyβ€’7mo ago
The node runs fine but nothing happens in the doc, maybe some mistake on my part.
Gaurav Chadha
Gaurav Chadhaβ€’7mo ago
To debug you can check the response, if the sheets id, range, and other things matches with the google sheet,
July
Julyβ€’7mo ago
Oh yeah it works, bad syntax on my part. Thanks! I wasnt using a template literal in which case nothing happened I made a quick update so it adds a new row instead of replacing the existing range function getTotalSubarrays(data, sheetName) { const values = data.values; if (Array.isArray(values)) { // const numberOfSubarrays = values.filter(row => row.length > 0).length; const numberOfSubarrays = values.length; return ${sheetName}!A${numberOfSubarrays+1}; } // Handle the case where "values" is not an array return ${sheetName}!A1; // Adjust to your specific default range or handle accordingly } async function batchAppendGoogleSheet({ spreadsheetId, dataArray, sheetName }, { auth }) { const { access_token } = await auth.getToken(); // Fetch the current values from the Google Sheet const getSheet = await fetch(https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${sheetName}, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': Bearer ${access_token} } }); const result = await getSheet.json(); // Calculate the next available row by counting existing rows const nextRow = result.values ? result.values.length + 1 : 1; const rangeNotation = ${sheetName}!A${nextRow}; // Prepare the data to be appended const data = { range: rangeNotation, majorDimension: "ROWS", values: [dataArray] // Wrap the dataArray in an array to match the expected format }; // Make the API request to append the data const url = https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${sheetName}!A:A:append?valueInputOption=RAW; const response = await fetch(url, { method: 'POST', body: JSON.stringify(data), headers: { 'Content-Type': 'application/json', Authorization: Bearer ${access_token} } }); const updates = await response.json(); return updates; } now updates with a single row ["1","2"..] also doesnt require cell number
Gaurav Chadha
Gaurav Chadhaβ€’7mo ago
cool, thanks for sharing.