Fetch Data From Google Sheet

let offset = 'A2';
let limit = 'Z999';
const sheetid = "<sheetid>"; 

const apikey = "<api key>"; 

const sheetname = "Sheet1";
const url = `https://sheets.googleapis.com/v4/spreadsheets/${sheetid}/values/${sheetname}!${offset}:${limit}?key=${apikey}`;

var sheet_data = [];

fetch(url).then(data => data.json()).then(data => { 
	sheet_data = data.values;
	console.table(sheet_data);
});

Sample Google Sheet Data

To get sheet id
Click on share then copy link

Create API Key

Final Output in HTML

One Reply to “Fetch Data From Google Sheet”

  1. Hi, I’m not the most familiar with backend and I have the following question.

    Assuming this code is run on a server (Node.js server), does it mean the code will be run everytime a change is made to the sheets file? Can an implementation be made so that a button in Sheets can be pressed to run the code?

    Thank you
    Truman

Leave a Reply

Your email address will not be published. Required fields are marked *