Repository example for using Google Sheets as an API (JSON)
You can use Google Spreadsheets to do without a backend for your application if you need to store certain data and then use it for your API. All data can be conveniently changed in the Google table and they will be dynamically available in real-time.
Дане рішення підійде для веб сайтів чи застосунків яким потрібні динамічні дані, проте вони не мають можливості розгортати повноцінний бекенд з базою. Всі дані можна зручно змінювати в гугл таблиці і вони будуть динамічно доступні в реальному часі.
- Create a Google Spreadsheet. The spreadsheet itself does not have to be public when the web app is deployed to execute as its owner.
- Add a sheet named
API-exampleand create the six columns shown in the example spreadsheet. - Open Extensions → Apps Script.
- Copy the code from
api-example.gs. - Copy the ID from your spreadsheet URL and put it in
SPREADSHEET_ID. - If your sheet has a different tab name, update
SHEET_NAME. - Select
testApiin the Apps Script function menu and click Run. Do not runprepareGsDatawith an argument; the current version needs no arguments. - Approve the requested Google Sheets permission. A successful test logs a JSON object.
- Select Deploy → New deployment → Web app. Execute the app as yourself
and choose who may access the generated
/execURL.
Example deployment: https://script.google.com/macros/s/AKfycby0yU7sjcUrlIKFdsKIcuyOE3wABb6ysAWwB7XDyOWGQxEMOcCxg2fUFg2xrqjvO72f/exec
Anyone who can access the web app URL can read the JSON it returns. Do not put private or personal data in a sheet exposed by a public deployment.
The tests use built-in Node.js modules and do not require npm install:
node --check --input-type=commonjs < api-example.gs
node tests/api-example.test.mjsGoogle Apps scripts documentation - https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app
Google Sheets - https://docs.google.com/spreadsheets/d/e/2PACX-1vRuyjAsFpk4matTzw64SRQxsZb2FKx_dl-R4_OibJdkpgVyfaCH5aCPuGGAul1xRNUbvXx3sdhqd2ml/pubhtml
Google Apps Script: A Beginner’s Guide - https://www.benlcollins.com/apps-script/google-apps-script-beginner-guide/
Volodymyr Melnychuk
If you have suggestions for improvement, you can create an issue.