(+91)7275894867 [email protected]
OutRightCRM Login
📅 Published on August 30, 2024 ✏️ Updated on April 22, 2025

Convert Your – Google Sheet into API in 2 Minutes

Author Avatar
Author
Editorial Team

Convert Your – Google Sheet into API in 2 Minutes

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.
  1. Step 1: Click on the Copy button to copy the code snippet.
  2. Step 2: Paste the copied code into your project’s script editor.

Apps Scripts Blog

Read 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);
}

Scroll to Top