Integrating your Google Spreadsheet with Firebase Functions

A spontaneous approach.

firebase cloud functions
Firebase Cloud Functions with Google Spreadsheet API

Part 1 — Set Up Your Firebase Project

mkdir my-firebase-function
cd my-firebase-function
npm init
npm install -g firebase-tools
firebase login
firebase init
├── node_modules/
├── firebase.json
├── functions/
├── index.js
├── node_modules/
├── package-lock.json
└── package.json
└── package.json

Part 2 — Set Up Your Google Spreadsheet API

cd my-firebase-function/functions/
npm install googleapis@39 --save

Part 3 — Integrate

Google Spreadsheet API Authentication

Click to view code snippet

Cloud Functions and Endpoints

mkdir functions/spreadsheet
cd functions/spreadsheet
touch createSpreadsheet.js createWorksheet.js updateWorksheet.js touch removeWorksheet.js

Below are code snippets for the Cloud Functions

Create Spreadsheet

Click to view code snippet

Create Worksheet

Click to view code snippet

Append / Update Worksheet

Click to view code snippet

Remove worksheet

Click to view code snippet
Click to view code snippet
Click to view code snippet

Part 3 — Deploying Cloud Functions

firebase deploy — only functions
firebase deploy --only functions:createSpreadsheet



Part 4 — Testing

Create new Spreadsheet

curl -d "title=Spreadsheet+Test” -X GET https://<app_url>/createSpreadSheetParameters
- title: Spreadsheet title

Create new Worksheet

curl -d "ssid=<SSID>&title=<sheet title>” -X GET https://<app_url>/createWorkSheetParameters
- ssid: Spread sheet identification
- title: Sheet title

Append / Update Worksheet

curl -d "ssid=<SSID>&sheetRange=<sheet name>&data=<array_of_data>” -X GET https://<app_url>/updateWorkSheetParameters
- ssid: spread sheet id
- sheetRange: sheet name
- data: array of data to be inserted / updated
example: [
['name', 'age', 'gender'],
['john doe', 24, 'male'],
['felicia', 28, 'female']

Remove Worksheet

curl -d "ssid=<SSID>&sheetRange=<sheet name>” -X GET https://<app_url>/removeWorkSheetParameters
- ssid: spread sheet id
- sheetId: work sheet id

Software engineer, runner, hiker, fitness enthusiast.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store