Syncing enrolments to Google Sheets
A live spreadsheet of every enrolment, updated the moment it happens, is one of the most requested automations there is. It needs no server and no paid tools: just a Google Sheet and a short script attached to it.
1. Set up the sheet
Create a Google Sheet with these headings in the first row:
Webhook ID | Date | Name | Email | Course
2. Add the script
In the sheet, open Extensions › Apps Script, delete what's
there and paste this in. Change SECRET to a long random string of
your own.
const SECRET = 'change-me-to-something-long-and-random';
function doPost(e) {
// Ignore anything without the secret in the address
if (e.parameter.key !== SECRET) return ok();
const event = JSON.parse(e.postData.contents);
if (event.type !== 'Enrollment.created') return ok();
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
// Skip duplicates: is this webhook ID already in column A?
const ids = sheet.getRange('A:A').getValues().flat();
if (ids.includes(event.id)) return ok();
const o = event.object || {};
sheet.appendRow([
event.id,
o.enrolled_at || event.created,
(o.user && o.user.name) || '',
(o.user && o.user.email) || '',
(o.course && o.course.name) || ''
]);
return ok();
}
function ok() {
return ContentService.createTextOutput('ok');
}
3. Publish it
- Click Deploy › New deployment and choose Web app.
- Set Execute as to yourself, and Who has access to Anyone. Teachable has no Google account, so it needs this.
- Deploy, approve the permissions, and copy the web app address.
4. Connect Teachable
- Add your secret to the end of the address:
...exec?key=your-secret - In Teachable, go to Settings › Webhooks › Add Webhook, choose
Enrollment.created, and paste the address in. - Enrol a test student and watch the row appear.
After any change, deploy a new version of the same deployment, so the address stays the same. A brand new deployment gets a new address, and Teachable would keep sending to the old one.
What this uses from the section
- A secret in the address keeps strangers out.
- The webhook ID column makes duplicates harmless.
- Every field is read defensively, so a missing name leaves a blank cell, not an error.
Next: the API
Webhooks tell you what just happened. The last section of the course covers the other half: asking Teachable for what you need, when you need it.
In short
- An Apps Script attached to a sheet can receive webhooks for free.
- Check a secret, skip duplicate IDs, and read every field defensively.
- Redeploy as a new version to keep the same address.