Your Web App URL is already saved. Run this script once in Google Apps Script — it auto-creates your Sheet and you are live.
1
Go to script.google.com → New Project → paste the code below into Code.gs
// KRT Private Circle — Google Apps Script Backend v2
// ─────────────────────────────────────────────────
// THIS VERSION AUTO-CREATES ITS OWN GOOGLE SHEET.
// No need to open from a Sheet first.
//
// HOW TO DEPLOY:
// 1. Go to script.google.com → New Project
// 2. Paste ALL of this code into Code.gs (replace everything)
// 3. Click Deploy → New Deployment
// 4. Type: Web App
// 5. Execute as: Me
// 6. Who has access: Anyone
// 7. Click Deploy → Authorise → Copy the Web App URL
// ─────────────────────────────────────────────────
const SHEET_NAME = 'KRT Referrals';
const PROP_KEY = 'KRT_SHEET_ID';
// Gets or creates the spreadsheet — works as standalone script
function _getSheet() {
const props = PropertiesService.getScriptProperties();
let sheetId = props.getProperty(PROP_KEY);
let ss;
if (sheetId) {
try { ss = SpreadsheetApp.openById(sheetId); }
catch(e) { sheetId = null; }
}
if (!sheetId) {
ss = SpreadsheetApp.create('KRT Private Circle — Referrals');
props.setProperty(PROP_KEY, ss.getId());
// Share with your Google account so you can view it
ss.addEditor(Session.getActiveUser().getEmail());
}
let sh = ss.getSheetByName(SHEET_NAME);
if (!sh) {
sh = ss.getSheets()[0];
sh.setName(SHEET_NAME);
sh.appendRow(['refId','clientName','brand','whatsapp',
'referredName','referredBrand','referredContact',
'submittedAt','tier','status','notes']);
sh.setFrozenRows(1);
sh.getRange(1,1,1,11).setFontWeight('bold')
.setBackground('#2C2510').setFontColor('#dab34c');
}
return sh;
}
function doGet(e) {
const sh = _getSheet();
if (sh.getLastRow() < 2) return _out([]);
const [headers, ...rows] = sh.getDataRange().getValues();
return _out(rows.map(r => Object.fromEntries(headers.map((h,i)=>[h,r[i]||'']))));
}
function doPost(e) {
const sh = _getSheet();
const b = JSON.parse(e.postData.contents);
if (b.action === 'new') {
sh.appendRow([
b.refId, b.clientName, b.brand, b.whatsapp,
b.referredName||'', b.referredBrand||'', b.referredContact||'',
b.submittedAt, 'Unassigned', 'New', ''
]);
} else if (b.action === 'update') {
const vals = sh.getDataRange().getValues();
const H = vals[0];
for (let i = 1; i < vals.length; i++) {
if (vals[i][0] === b.refId) {
if (b.tier !== undefined) sh.getRange(i+1, H.indexOf('tier')+1).setValue(b.tier);
if (b.status !== undefined) sh.getRange(i+1, H.indexOf('status')+1).setValue(b.status);
if (b.notes !== undefined) sh.getRange(i+1, H.indexOf('notes')+1).setValue(b.notes);
break;
}
}
}
return _out({ok: true});
}
function _out(data) {
return ContentService
.createTextOutput(JSON.stringify(data))
.setMimeType(ContentService.MimeType.JSON);
}
// Run this once manually after deploying to verify the Sheet was created
function testSetup() {
const sh = _getSheet();
Logger.log('Sheet URL: ' + sh.getParent().getUrl());
Logger.log('Sheet name: ' + sh.getName());
Logger.log('Setup complete.');
}
2
Click Deploy → New Deployment → Type: Web App → Execute as: Me → Who has access: Anyone → Deploy → Copy the Web App URL
3
After deploying, run the testSetup() function once from the script editor to verify the Sheet was created. Your Web App URL is already configured in both files.