A volunteer keeps planning matches in Google Sheets; an Apps Script menu publishes them to Sanity, where coaches add scores.

How I let a volunteer keep working in his spreadsheet while the club website reads structured match data from Sanity — with Apps Script, the HTTP API and a clear rule about who owns which field.

The problem: the schedule lives in a spreadsheet, and it should stay there

FC Versoud is an amateur football club near Grenoble, France: about twenty teams, from under-6s to seniors, and everything runs on volunteers. I'm one of them, and I'm rebuilding the club's website on Astro + Sanity + Cloudflare.

Every week, one volunteer prepares the weekend schedule: which team plays, when, against whom, on which pitch, with which referee. For years this was an Excel file with one block per weekend, shared as a screenshot on WhatsApp and retyped on the old WordPress site — when someone had the time.

The obvious "modern" answer would be: enter the matches in the CMS. I didn't want that, for three reasons:

  1. The spreadsheet is the volunteer's tool, not just a data source. He uses it to plan pitches and referees, columns the website will never show. Asking him to type everything twice would kill the project.
  2. A spreadsheet is the right UI for this job. Twenty rows per weekend, copy-paste from the federation's emails, drag-to-fill. No form beats that.
  3. The website still needs structured data. Each team page lists its next matches and results, and the home page shows the weekend. That's a GROQ query, not an embedded sheet.

So the goal became: the spreadsheet stays the source of truth for the schedule, Sanity becomes the source of truth for everything that happens after the match.

The architecture

Google Sheet (one tab per weekend) │ menu "FC Versoud > Publish this weekend" (Apps Script) ▼ Sanity HTTP API: query + mutate (match documents) │ coaches add scores and match reports in the Studio ▼ Astro site on Cloudflare Workers (team pages, weekend page) 

No server, no queue, no third-party sync tool. Apps Script runs inside the spreadsheet, under the club's Google account, and talks directly to Sanity's HTTP API with an Editor token.

Rule #1: split ownership field by field

The whole design rests on one decision: each field has exactly one owner.

Owned by the spreadsheet Owned by Sanity
team, date and time, opponent (or clubs at a youth tournament), home/away, venue, competition score, "played" status, match report, photos

The publish script only ever writes the spreadsheet's fields. It never touches a score. In the Studio, the spreadsheet's fields are locked on documents that came from the sheet, so nobody "fixes" a kick-off time in the wrong place and sees it overwritten the next night:

// studio/schemaTypes/documents/match.ts (simplified) const SHEET_FIELDS = new Set([ 'team', 'teamNumber', 'type', 'competition', 'dateTime', 'timeText', 'home', 'opponent', 'tournamentClubs', 'venue', 'place', ]) const comesFromSheet = ({document}: {document?: {sheet?: {rowId?: string}}}) => !!document?.sheet?.rowId const lockSheetFields = <T extends {name: string}>(fields: T[]) => fields.map((f) => (SHEET_FIELDS.has(f.name) ? {...f, readOnly: comesFromSheet} : f)) export const match = defineType({ name: 'match', type: 'document', fields: lockSheetFields([ defineField({ name: 'sheet', title: 'Comes from the schedule spreadsheet', description: 'Date, time, opponent and venue are edited in the Google Sheet, then "Publish this weekend".', type: 'object', readOnly: true, hidden: ({value}) => !value, fields: [ defineField({name: 'rowId', type: 'string'}), defineField({name: 'weekend', type: 'date'}), // the Saturday of the weekend ], }), // ...team, dateTime, opponent, venue, score, report... ]), }) 

Matches created by hand in the Studio (a friendly, a cup game nobody put in the sheet) have no sheet object, so all their fields stay editable. The description is the documentation: it tells the coach exactly where to go.

Rule #2: a stable ID per row, not per match

Rows move, get copied, get re-sorted. Matching a row to a document by "team + date" breaks the first time a game is rescheduled. So every row gets a hidden ID column, filled with a short UUID when the weekend tab is created (or when the script meets a row without one):

if (!row.id && (row.homeTeam || row.awayTeams)) { row.id = Utilities.getUuid().slice(0, 12) sheet.getRange(firstRow + i, columns.id + 1).setValue(row.id) } 

The Sanity document ID is derived from it — sheet-<rowId> — so the sync is idempotent. Publishing the same weekend ten times produces the same documents, never duplicates. One row can produce several documents: "U6 and U7" on the same pitch becomes sheet-<rowId>-u6 and sheet-<rowId>-u7, one per team page.

The mutations: create if missing, patch only what you own, delete what disappeared

For each weekend tab, the script:

  1. reads the rows and turns them into documents;
  2. asks Sanity which sheet-born matches already exist for that weekend (published and drafts);
  3. sends one transaction.
// What already exists for this weekend? (perspective=raw so drafts are included) const EXISTING = `{ "ids": *[_type == "match" && sheet.weekend == $weekend && !(_id in path("drafts.**"))]._id, "drafts": *[_type == "match" && sheet.weekend == $weekend && _id in path("drafts.**")]._id }` function mutationsForWeekend(docs, teams, existing) { const mutations = [] const kept = {} docs.forEach((doc) => { kept[doc._id] = true const set = {}, unset = [] SHEET_FIELDS.forEach((field) => { const value = field === 'team' ? {_type: 'reference', _ref: teams[doc.teamSlug]} : doc[field] if (value == null) unset.push(field) else set[field] = value }) // 1. Create the document the first time only (status "scheduled") mutations.push({createIfNotExists: {_id: doc._id, _type: 'match', status: 'scheduled', team: set.team, dateTime: set.dateTime}}) // 2. Patch only the spreadsheet's fields — on the published doc AND on an open draft const ids = [doc._id].concat(existing.drafts.includes('drafts.' + doc._id) ? ['drafts.' + doc._id] : []) ids.forEach((id) => mutations.push({patch: {id, set, ...(unset.length ? {unset} : {})}})) }) // 3. A row deleted from the tab removes its match from the site (sheet-born matches only) existing.ids.filter((id) => !kept[id]).forEach((id) => mutations.push({delete: {id}})) existing.drafts.filter((id) => !kept[id.replace(/^drafts\./, '')]).forEach((id) => mutations.push({delete: {id}})) return mutations } 

Three details that took me a few iterations:

  • createIfNotExists + patch, never createOrReplace. createOrReplace would wipe the score a coach entered on Saturday evening.
  • Patch the draft too. If a coach has the match open in the Studio (a draft exists), patching only the published document means the draft silently brings back the old kick-off time when he publishes his report. Patching both keeps them in step.
  • unset empty cells. If the volunteer clears the venue, the site must stop showing the old one. Skipping null values would leave stale data behind.

The call itself is plain UrlFetchApp:

function send(mutations) { const res = UrlFetchApp.fetch( `https://${PROJECT_ID}.api.sanity.io/v2026-11-01/data/mutate/${DATASET}?visibility=sync`, { method: 'post', contentType: 'application/json', headers: {Authorization: 'Bearer ' + PropertiesService.getScriptProperties().getProperty('SANITY_TOKEN')}, payload: JSON.stringify({mutations}), muteHttpExceptions: true, }, ) if (res.getResponseCode() !== 200) throw new Error('Sanity refused the mutation: ' + res.getContentText().slice(0, 300)) } 

The token lives in Script Properties, set through a "Settings…" menu item, never in a cell. Anyone the sheet is shared with can read the cells, but not the script properties.

The part nobody warns you about: time zones

The sheet says "Saturday 28/11/2026" and "14h 30". Sanity wants an ISO datetime in UTC. Apps Script runs in the script's time zone, the spreadsheet has its own, and the Studio displays in the editor's browser zone. The first version put every November match one hour early.

I stopped relying on the runtime and computed the Paris offset explicitly (+2 between the last Sunday of March and the last Sunday of October, +1 otherwise):

function parisOffset(year, month, day, hour) { const lastSunday = (m) => { const d = new Date(Date.UTC(year, m + 1, 0)); return d.getUTCDate() - d.getUTCDay() } const summerStart = Date.UTC(year, 2, lastSunday(2), 1) // last Sunday of March, 01:00 UTC const summerEnd = Date.UTC(year, 9, lastSunday(9), 1) // last Sunday of October, 01:00 UTC const t = Date.UTC(year, month, day, hour) - 3600 * 1000 return t >= summerStart && t < summerEnd ? 2 : 1 } 

When the time cell says "to be confirmed" instead of a time, the match is stored at noon and the original text goes into a timeText field that the site displays instead of the hour. Messy input is the norm in a volunteer's sheet, so the parser warns instead of failing: after each publish, a dialog lists "row 14: team 'U13 3' is not published in Sanity, match skipped". The volunteer fixes the cell and publishes again.

Making it feel native for the volunteer

The script adds a FC Versoud menu to the spreadsheet:

  • New weekend…: asks for the Saturday's date, duplicates a template tab, fills the dates and the usual categories, and generates the row IDs.
  • Publish this weekend on the site: syncs the active tab, then shows how many matches were sent and the rows to check.
  • Publish all upcoming weekends, and an optional nightly publish (a time-driven trigger at 2 a.m., Paris time) for when he forgets.
  • Settings…: the Sanity token and an optional deploy hook.

Referee, assistant and observer columns exist in the sheet but are simply not in the column map, so they can never reach the website. A "Page on the site" column is pre-filled from the category and lets him route an unusual row (a cup, a tournament) or mark it "Do not publish".

The rules that read a row (Rules.js) are plain ES5 functions with a module.exports guard at the bottom. The same file runs in Apps Script and in Node: I used it from a Sanity CLI script to import the existing Excel file once, and to test the parsing on real rows without clicking through Google's UI.

if (typeof module !== 'undefined') { module.exports = {readRow, mutationsForWeekend, saturdayOfWeekend, COLUMNS} } 

What I'd tell someone building the same thing

  • Decide field ownership first. Everything else (read-only fields, patch instead of replace, what to delete) follows from that table.
  • Derive document IDs from the source, never from content. That makes the sync idempotent and safe to run every night.
  • Remember drafts. Anything that writes to published documents while editors work in the Studio has to decide what happens to drafts.<id>.
  • Let the spreadsheet stay a spreadsheet. Sanity doesn't need to replace the tool people already use. It can sit behind it and add what the sheet can't: structure, references to teams and venues, and fields that belong to other people.

The club is switching from Excel to the Google Sheet for the 2026-2027 season. The matches from late November to mid-December are already in Sanity, and the coaches will add scores in the Studio.

Jérémy Luye — Jecero Studio, a one-person web & SEO studio near Grenoble, France. I build content sites on Astro + Sanity + Cloudflare. jecero.fr