const SHEET_NAME = "Appointments";
function doGet(e) {
const token = e.parameter.id;
if (!token) {
return jsonResponse({ error: "Missing appointment ID" });
}
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
const data = sheet.getDataRange().getValues();
const headers = data[0];
const rows = data.slice(1);
const tokenIndex = headers.indexOf("token");
for (const row of rows) {
if (row[tokenIndex] === token) {
const record = {};
headers.forEach((header, i) => {
record[header] = row[i];
});
return jsonResponse({
found: true,
appointment: {
token: record.token,
status: record.status,
customer_name: record.customer_name,
appointment_date: record.appointment_date,
arrival_window: record.arrival_window,
service_type: record.service_type,
minimum_fee: record.minimum_fee,
terms_url: record.terms_url
}
});
}
}
return jsonResponse({ found: false });
}
function jsonResponse(obj) {
return ContentService
.createTextOutput(JSON.stringify(obj))
.setMimeType(ContentService.MimeType.JSON);
}