Get values from any public spreadsheet created with Google Sheets as JSON. This program is designed for Google Cloud Functions and requires very minimal set-up. But it can also be run from the command line as a stand-alone server for testing.
Open the API & Services Credentials page on Google Cloud and generate a new API key with the "Create Credentials" button. Copy the generated key.
You need to have a Google Cloud account with Cloud Functions and the Google Sheets API enabled to use this program. All you have to do is click "Enable" and wait a few minutes.
-
Create a new Cloud Function
Open the Cloud Functions dashboard and create a new function with the "Create Function" button. But before you click next.. -
Add runtime variables
This is where you add your app settings. You need to add 3 runtime variables with the "Add Variable" button at the bottom of the page.Name Value API_KEY
The API key generated at the start of this guide SHEET_ID
ID of the spreadsheet.
Here's how to find itSHEET_RANGE
A1 notation of the cells to export with this API -
Upload source code
Download a Cloud Functions compatible ZIP of this program from the releases page. Select "ZIP Upload" under the "Source code" dropdown in the function creator -
Deploy
Click "Deploy" and wait for the Cloud Function to start up. You should see the URL it created for your function under the function details page. The spreadsheet cells should now show up as JSON.
You can also run this program locally as a stand-alone server. There are currently no pre-built binaries of this program, but you can download the Go compiler and run it from the CLI.
-
Clone this repo
git clone https://github.com/VictorWesterlund/gcf-sheets-api.git
-
Download Go
Follow the instructions on go.dev. Or download it from a package managersudo apt-get install golang-go
-
Environment variables
Copy the hidden.env.example
file to.env
and set the following values. Save and close when you're doneName Value API_KEY
The API key generated at the start of this guide SHEET_ID
ID of the spreadsheet.
Here's how to find itSHEET_RANGE
A1 notation of the cells to export with this API -
Start the server
Start the web server with Go rungo run .
Note: The server will listen for HTTP (not HTTPS) connections on localhost:8090