FirestoreGoogleAppsScript
A Google Apps Script library for accessing Google Cloud Firestore.
AI Summary
Firestore for Google Apps Scripts
A library that enables Google Apps Script to authenticate to Google Cloud Firestore and perform CRUD and query operations.
Target Users
Intermediate GAS developers building internal tools or add-ons who want to use Firestore easily and securely.
Problems Solved
Accessing Firestore from GAS normally requires manual REST calls and OAuth/JWT handling, which is burdensome.
Tags
Main Features
Simplified Service-Account Authentication
Get a Firestore instance by supplying email, private key and project ID, eliminating manual JWT creation and token refresh.
Intuitive CRUD Methods
One-line document operations via methods like createDocument, getDocument, updateDocument and deleteDocument.
Advanced Query API
Chainable Where, OrderBy, Limit etc. followed by .Execute() enables filtered, ordered and paginated queries.
Usage Examples
Connect to Firestore and add a document
/**
* Sample that reads service-account credentials from Script Properties,
* connects to Firestore and adds one document into a collection.
*/
function addSampleDocument() {
// Read credentials stored in Script Properties
const props = PropertiesService.getScriptProperties();
const email = props.getProperty('client_email');
const key = props.getProperty('private_key');
const projectId = props.getProperty('project_id');
// Obtain Firestore instance
const firestore = FirestoreApp.getFirestore(email, key, projectId);
// Data to be inserted
const data = {
name: 'Written from GAS', // any field you like
createdAt: new Date().toISOString()
};
// Add document into FirstCollection with auto-generated ID
const doc = firestore.createDocument('FirstCollection', data);
// Log generated path
console.log('Created path: ' + doc.path);
}
Copy & paste, set client_email
, private_key
, project_id
in Script Properties and it will run immediately.