In 2023 I published the open source AppSheetApp library for Google Apps Script which made it easy to use the AppSheet API in your projects. @bienlim has enhanced the AppSheetApp library with a powerful new feature: fetchAll(). This now lets you run multiple AppSheet API calls at the same time, significantly boosting the performance of your Apps Script integrations. You can find the updated library in the GitHub code repository to start using this new feature today.
Here’s an example from the repo:
/**
* Executes multiple AppSheet API requests in parallel.
* This example shows how to perform Add, Delete, Edit, and Find operations simultaneously.
*/
function parallelRequest(){
// Replace with your actual App ID and Access Key
// If you are using the library in your script project use
// `const AppSheet = new AppSheetApp('YOUR_APP_ID', 'YOUR_ACCESS_KEY')`;
const AppSheet = AppSheetApp('YOUR_APP_ID', 'YOUR_ACCESS_KEY');
// Placeholder data for demonstration
const properties = { "Locale": "en-US" };
// Sample data for adding a new record. The key field is usually omitted if it's auto-generated.
const dataToAdd = [{"Name": "John Doe", "Age": 30}];
// Sample data for editing an existing record. The key field is required to identify the row.
const dataToEdit = [{"ID": "unique-id-123", "Age": 31}];
// Sample data for deleting an existing record. The key field is required.
const dataToDelete = [{"ID": "unique-id-456"}];
// The FetchAll method takes multiple API calls as arguments.
// The 'true' argument tells each method to return a parameter object instead of
// making an immediate API call. These parameter objects are then passed to fetchAll().
const responses = AppSheet.fetchAll(
AppSheet.Add('People', dataToAdd, properties, true),
AppSheet.Delete('People', dataToDelete, properties, true),
AppSheet.Edit('People', dataToEdit, properties, true),
AppSheet.Find('People', [], properties, true)
);
// The responses are returned in an array, in the same order as the requests.
const [ respFromAdd, respFromDelete, respFromEdit, respFromFind ] = responses;
// You can now handle each response individually
console.log('Add Response:', respFromAdd);
console.log('Delete Response:', respFromDelete);
console.log('Edit Response:', respFromEdit);
console.log('Find Response:', respFromFind);
}
As @bienlim highlights:
Key Changes
-
FetchAllWrapper: All parallel method calls are now wrapped within the newAppSheet.FetchAll()helper function. -
New Parameter: A fourth parameter,
isAysnc, has been added to the method calls. Setting this boolean totrueconverts the function into a URL request compatible withUrlFetchApp.fetchAll(). By default, this parameter isfalse, so all previous functions will continue to work without any changes.
To use this you can library. Add this Script ID on your App Script Project: 1aXPRqSO_ulCdptqlpKm12o81pdOHUlxnr9n6Gw3AIXk0K8Xc_cNCbx4B
A big thank you to Bien for his contribution! ![]()