apps script sheets

    by Miguel Elias Gutierrez Garcia

    1

    Turn Google Sheets into a serverless backend API with concurrency locking and data integrity for internal tools.

    Free

    Security scanned

    Works with the AI Agents you already use

    apps script sheets

    Example session with this skill installed

    Create a Google Apps Script POST handler to save lead data from a web form to a sheet named "Leads", ensuring no duplicates and safe concurrent writes.

    • Read your context and instructions
    • Compiled the apps script sheets

    I have generated a robust Apps Script backend for your lead collection. It includes header-based mapping, concurrency locking, and idempotency checks to prevent duplicate entries.

    Google Apps Script Lead Backend

    /**
     * POST Handler for Lead Collection
     * Deploy as Web App with 'Anyone' or 'Anyone with Google Account' access.
     */
    function doPost(e) {
      const LOCK_TIMEOUT_MS = 10000;
      const lock = LockService.getScriptLock();
      
      try {
        if (!lock.tryLock(LOCK_TIMEOUT_MS)) {
          return createJsonResponse(false, 'Server busy, try again later');
        }
    
        const payload = JSON.parse(e.postData.contents);
        const ss = SpreadsheetApp.getActiveSpreadsheet();
        const sheet = ss.getSheetByName('Leads') || ss.insertSheet('Leads');
        
        // 1. Ensure columns exist (Idempotent)
        const headers = ['timestamp', 'id_ref', 'name', 'email', 'status'];
        ensureColumns_(sheet, headers);
        
        // 2. Check for duplicate reference
        if (isDuplicate_(sheet, payload.ref)) {
          return createJsonResponse(true, 'Already processed');
        }
    
        // 3. Map data to headers and write
        const rowData = headers.map(h => {
          if (h === 'timestamp') return new Date();
          if (h === 'id_ref') return payload.ref;
          let val = payload[h] || '';
          return (typeof val === 'string' && /^[=+\-@]/.test(val)) ? "'" + val : val;
        });
    
        sheet.appendRow(rowData);
        SpreadsheetApp.flush();
        
        return createJsonResponse(true, { message: 'Lead saved' });
    
      } catch (err) {
        return createJsonResponse(false, err.toString());
      } finally {
        lock.releaseLock();
      }
    }
    
    function createJsonResponse(ok, data) {
      const output = ok ? { ok: true, data: data } : { ok: false, error: data };
      return ContentService.createTextOutput(JSON.stringify(output))
        .setMimeType(ContentService.MimeType.JSON);
    }
    
    function ensureColumns_(sheet, headers) {
      const existing = sheet.getRange(1, 1, 1, sheet.getLastColumn() || 1).getValues()[0];
      headers.forEach(h => {
        if (existing.indexOf(h) === -1) {
          sheet.getRange(1, sheet.getLastColumn() + 1).setValue(h);
        }
      });
    }
    
    function isDuplicate_(sheet, ref) {
      if (!ref) return false;
      const data = sheet.getDataRange().getValues();
      const refIdx = data[0].indexOf('id_ref');
      return data.some(row => row[refIdx] === ref);
    }
    

    Next steps

    1. Paste this code into your Apps Script editor and save.
    2. Run an initial test execution to authorize SpreadsheetApp permissions.
    3. Deploy as a "Web App", set access to "Anyone", and use the provided URL for your form fetch calls.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Build lightweight backends, field apps, and internal tools without server costs or infrastructure management. This skill turns Google Sheets into a functional database using Google Apps Script (GAS). It focuses on creating robust web apps and APIs that remain stable even when spreadsheets are manually edited or reorganized.

    What it does

    • Database abstraction treat Google Sheets as a database by reading columns via header names rather than fragile fixed positions.
    • Concurrency control implements LockService logic to prevent data loss or overwriting when multiple users submit data simultaneously.
    • API development builds doGet and doPost endpoints that serve uniform JSON responses for web and mobile clients.
    • Idempotency management tracks unique references to ensure re-tried requests from offline apps do not create duplicate records.
    • Security hardening manages secrets via PropertiesService and prevents formula injection attacks by neutralizing malicious input.

    How it works

    1. Initialize infrastructure run an installation routine to set up required sheet headers and script properties.
    2. Define endpoints configure the web app to handle incoming HTTP requests and route them to specific sheet operations.
    3. Apply batch operations read and write data in blocks using getValues and setValues to respect Google execution limits.
    4. Deploy and version manage script deployments to ensure URL stability while updating business logic.

    Frameworks & tools

    Google Apps Script (GAS), Google Sheets API, clasp (Command Line Apps Script Projects), and PropertiesService for configuration management.

    Why this beats prompting it yourself

    Generic prompts often produce code that breaks when a user moves a column or triggers a race condition. This skill enforces production-grade patterns like row locking, header-based mapping, and idempotency that are critical for data integrity.

    Use cases

    • Build a custom field data collection app that works with an existing spreadsheet.
    • Create a REST API for a static site using Google Sheets as a CMS.
    • Automate report generation and notification workflows based on sheet updates.
    • Develop internal tools that non-technical staff can manage via a spreadsheet interface.

    Known limitations

    Not suitable for high-traffic applications exceeding 30 simultaneous executions or complex transactional systems. Scripts are subject to a ~6-minute execution timeout.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 14 days ago

    • Free with an Agensi account

    Permissions

    Read Files
    Network Access
    Listed14 days ago

    What's inside

    Frequently Asked Questions

    This skill converts Google Sheets into a production-ready API by adding critical layers like concurrency locking, idempotency to prevent duplicate entries, and header-based data mapping that survives manual sheet changes.

    The skill is designed for any AI agent or platform capable of making HTTP requests (GET/POST), such as ChatGPT Actions, Custom GPTs, Zapier, or custom web/mobile applications.

    Setup involves running an automated initialization routine within your Google Apps Script editor to establish the necessary headers, script properties, and security settings.

    While highly scalable for internal tools, it is limited by Google's quotas, typically supporting up to 30 concurrent executions and a 6-minute maximum script runtime per request.

    You receive the full script architecture, deployment configurations, and documentation on how to define endpoints and manage security via the Google PropertiesService.

    Yes, the skill is specifically engineered to use header-based mapping, meaning your API logic won't break if a user adds, removes, or reorders columns in the spreadsheet.

    New in APIs & Backend

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    Free