sheet.saveUpdatedCells() doesn't seem to save any data #549
-
I've been importing data from Google Sheets to our database and writing the newly generated record IDs back to the spreadsheet. If I use I'm using the service account auth process and note the saveUpdatedCells call is in two different places in the example (this is just for the example) as I've tried it outside of the Here's my code example: const pushDataToDb = async (productData) => {
Promise.allSettled(productData.map(async (product, index) => {
const endpoint = product.id
? `${apiDomain}/product/${product.id.trim()}`
: `${apiDomain}/product`
await fetch(
endpoint,
{
method: product.id ? 'PUT' : 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(product)
}
).then(response => {
return response.json()
})
.then(async (data) => {
if (product.id) {
rows[index].id = data.id
await rows[index].save()
}
console.log(`
id: ${data.id},
productName: ${data.productName}
`)
})
})).then(async (results) => {
console.log('cool: ', results)
sheet.saveUpdatedCells()
})
await sheet.saveUpdatedCells()
} Any help would be appreciated! Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The row-based and cell-based APIs are totally separate... If you want to deal with rows (which keeps this simple but is limited) then you load rows, update them (while being blissfully unaware of the concept of cells), and call save on them. Otherwise if you want to deal with cells directly (more flexible but more complex), then you load a range of cells, update the data in specific cells, and then can save all the updates. This was set up this way to try to mirror Google's row-based interactions that they used to have in a previous version of their API. It's definitely much more limited, but probably handles 90% of use cases and keeps things much simpler. |
Beta Was this translation helpful? Give feedback.
The row-based and cell-based APIs are totally separate...
If you want to deal with rows (which keeps this simple but is limited) then you load rows, update them (while being blissfully unaware of the concept of cells), and call save on them.
Otherwise if you want to deal with cells directly (more flexible but more complex), then you load a range of cells, update the data in specific cells, and then can save all the updates.
This was set up this way to try to mirror Google's row-based interactions that they used to have in a previous version of their API. It's definitely much more limited, but probably handles 90% of use cases and keeps things much simpler.