Turn your Google Sheet into an API in 2 minutes using Google Apps Script. Create a simple script to fetch sheet data, publish it as a web app, and access it via a URL. Ideal for dashboards, apps, or integrations.
- Step 1: Click on the
Copy
button to copy the code snippet. - Step 2: Paste the copied code into your project’s script editor.
Apps Scripts Blog
Apps Scripts Code
function doGet(req) { var doc = SpreadsheetApp.getActiveSpreadsheet(); var sheet = doc.getSheetByName('sheet1'); var values = sheet.getDataRange().getValues(); var output = []; for (var i = 0; i < values.length; i++) { if (i == 0) { continue; } var row = {}; // Create a new row object for each row for (var j = 0; j < 100; j++) { if (!values[i][j]) { break; } row[values[0][j]] = values[i][j]; } output.push(row); // Push the row object to the output array delete row; } return ContentService.createTextOutput(JSON.stringify({ data: output })).setMimeType(ContentService.MimeType.JSON); }