- Home
- Skills
- APIs & Backend
- apps script sheets
apps script sheets
Turn Google Sheets into a serverless backend API with concurrency locking and data integrity for internal tools.
Free
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
- Paste this code into your Apps Script editor and save.
- Run an initial test execution to authorize
SpreadsheetApppermissions. - Deploy as a "Web App", set access to "Anyone", and use the provided URL for your form
fetchcalls.
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
LockServicelogic to prevent data loss or overwriting when multiple users submit data simultaneously. - API development builds
doGetanddoPostendpoints 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
PropertiesServiceand prevents formula injection attacks by neutralizing malicious input.
How it works
- Initialize infrastructure run an installation routine to set up required sheet headers and script properties.
- Define endpoints configure the web app to handle incoming HTTP requests and route them to specific sheet operations.
- Apply batch operations read and write data in blocks using
getValuesandsetValuesto respect Google execution limits. - 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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
What's inside
Frequently Asked Questions
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.