Sonatina.ca
← Help centre

Webhooks for Zapier, Make and your own tools

Send a signed message to another tool when a student is added, an invoice is paid, a lesson is cancelled and more, and how to check the signature.

A webhook is a message Sonatina.ca sends to a web address you choose, the moment (within about an hour) something happens in your school. Zapier, Make and most other tools can listen at such an address. Open Settings > Webhooks to set it up. Nothing is sent until you save an address, and you can switch it off again at any time. Sonatina.ca does not have a ready-made Zapier or Make app: you use their generic webhook step, as described here.

Set up: 1. In Zapier choose the trigger "Webhooks by Zapier > Catch Hook" (in Make, the module "Webhooks > Custom webhook") and copy the address it gives you. It starts with https://. 2. In Sonatina.ca open Settings > Webhooks, paste the address, tick the events you want and press Save. 3. Copy the signing secret that is shown (it is shown once). 4. Press "Send a test event" and check that your tool received it.

The events: student.created (a student is added), family.created (a family is added), lesson.booked (a one-off lesson is booked, or a student gets a weekly slot), lesson.cancelled (a lesson is cancelled by the school or a family), invoice.created (an invoice is issued; drafts are not announced), invoice.paid (an invoice is paid), payment.failed (an automatic or bank payment fails) and trial.booked (a free trial lesson is booked).

More events: class.enrolled (a student joins a group class), refund.created (money from an invoice payment is given back), merch.order.created (a shop order is placed), merch.order.paid, merch.order.cancelled and merch.order.refunded. A shop event carries the order number, status, totals in cents and the items, and never the buyer's name, email, phone or address.

Personal details: by default a student event has no birthdate and a family event has no email or phone number. Under "Personal details in the events" you can tick either one if the tool you connect needs it; many students are children, so only tick them if you are happy for that tool to hold the details. Nothing is sent for a demo school.

Several web addresses and faster delivery: you can add up to 3 web addresses, each with its own name, events, personal-detail boxes and signing secret; an event goes to every address that asked for it, and one address failing never stops the others. Right after a change made in your school's pages, Sonatina.ca also tries once, for at most 2 seconds and without slowing the page, to send the event to your tool; if that does not work nothing is lost, because the hourly job (the guaranteed path) sends it later. The quick try depends on the web host, so always plan for delivery within about an hour.

What you receive: a small JSON message with an id, a type, the time it was created and the thing itself, for example {"id":"evt_...","type":"student.created","created":"2026-11-12T10:00:00Z","data":{"object":{...}}}. The thing has the same fields our API already shows for it. There are never card or bank details in a message.

Delivery: events are looked for, and sent, by the hourly job, so a message arrives within about an hour. Answer with any 2xx status to say you got it. If you answer with anything else, or do not answer within 10 seconds, we try again after 1 hour, 2 hours, 6 hours, 12 hours and 24 hours, then give up on that event (you can press "Send again" in the log). If ten events in a row are given up, webhooks switch themselves off so a broken tool does not keep being called. Redirects are not followed. Your address must be https on the public internet: addresses on a private network are refused.

Check the signature: every message has the header X-Sonatina-Signature: t=1789210000,v1=<64 letters and numbers>. It proves the message came from Sonatina.ca and was not changed. 1. Take the number after t= and the exact text of the body, exactly as received (do not parse and re-write it first). 2. Join them with a dot: "<t>.<body>". 3. Work out the HMAC-SHA256 of that text, using your signing secret as the key, written as lower-case hex. 4. Compare it with the v1 value using a constant-time comparison. 5. Refuse the message if t is more than 5 minutes away from your own clock. The headers X-Sonatina-Event, X-Sonatina-Delivery (the event id; use it to ignore a message you already handled) and X-Sonatina-Timestamp are also sent. Examples in three languages follow.

Changing the secret: press "Make a new signing secret" and put the new one in your tool. If "Keep the old secret working for 24 hours" is ticked, every message for the next 24 hours carries two signatures (t=...,v1=<new>,v1=<old>); your tool is correct if ANY v1 matches, so nothing is lost while you switch. Untick it to stop the old secret at once. To stop everything, press "Switch webhooks off".

PHP

<?php
$secret = 'whsec_...';                      // from Settings > Webhooks
$body   = file_get_contents('php://input');   // the exact text, before any parsing
$header = $_SERVER['HTTP_X_SONATINA_SIGNATURE'] ?? '';
if (!preg_match('/^t=(\d+),((?:v1=[a-f0-9]{64},?)+)$/', $header, $m) || abs(time() - (int)$m[1]) > 300) { http_response_code(400); exit; }
$expected = hash_hmac('sha256', $m[1] . '.' . $body, $secret);
$ok = false;
foreach (explode(',', $m[2]) as $part) { $ok = hash_equals($expected, substr($part, 3)) || $ok; }   // any v1 may match (two while a secret is being replaced)
if (!$ok) { http_response_code(400); exit; }
// safe to use json_decode($body, true) now

Node.js

const crypto = require('crypto');
function verify(secret, header, rawBody) {      // rawBody: the exact bytes received
  const m = /^t=(\d+),((?:v1=[a-f0-9]{64},?)+)$/.exec(header || '');
  if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return false;
  const expected = crypto.createHmac('sha256', secret).update(m[1] + '.' + rawBody).digest('hex');
  return m[2].split(',').some(p => crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(p.slice(3))));   // any v1 may match
}

Python

import hmac, hashlib, re, time
def verify(secret, header, raw_body):          # raw_body: the exact bytes received
    m = re.fullmatch(r't=(\d+),((?:v1=[a-f0-9]{64},?)+)', header or '')
    if not m or abs(time.time() - int(m.group(1))) > 300:
        return False
    expected = hmac.new(secret.encode(), m.group(1).encode() + b'.' + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(expected, p[3:]) for p in m.group(2).split(','))   # any v1 may match

An example event

POST https://hooks.example.com/sonatina
Content-Type: application/json
X-Sonatina-Event: student.created
X-Sonatina-Delivery: evt_5f0c1d2e3a4b5c6d7e8f9a0b
X-Sonatina-Timestamp: 1789210000
X-Sonatina-Signature: t=1789210000,v1=3b1f...64 hex letters...

{"id":"evt_5f0c1d2e3a4b5c6d7e8f9a0b","type":"student.created","created":"2026-11-12T10:00:00Z",
 "data":{"object":{"object":"student","id":412,"family_id":97,"name":"Ana Lopez","status":"active"}}}

A shop order event (no buyer name, email, phone or address)

{"id":"evt_...","type":"merch.order.paid","created":"2026-11-15T18:30:00Z",
 "data":{"object":{"object":"merch_order","id":31,"number":"M-0031","status":"paid","pay_method":"card","family_id":97,
  "subtotal_cents":4400,"shipping_cents":0,"tax_cents":572,"total_cents":4972,"refunded_cents":0,
  "items":[{"name":"Studio T-shirt","label":"M / Black","qty":2,"unit_cents":2200}]}}}

A complete receiver you can copy

Put it on your own web server, then paste its https address into Settings > Webhooks and press "Send a test event". It answers 200 only when the signature is right, and it ignores a delivery it has already handled.

PHP

<?php
// receive.php - put this on your own web server (it must be reachable at an https address),
// then paste that address into Settings > Webhooks in Sonatina.ca and press "Send a test event".
$secret = 'whsec_...';                        // your signing secret (shown once when you make it)
$body   = file_get_contents('php://input');   // the exact text received
$header = $_SERVER['HTTP_X_SONATINA_SIGNATURE'] ?? '';

// 1. Check the signature and the time (see the snippet above)
if (!preg_match('/^t=(\d+),((?:v1=[a-f0-9]{64},?)+)$/', $header, $m) || abs(time() - (int)$m[1]) > 300) { http_response_code(400); exit('bad signature'); }
$expected = hash_hmac('sha256', $m[1] . '.' . $body, $secret);
$ok = false;
foreach (explode(',', $m[2]) as $part) { $ok = hash_equals($expected, substr($part, 3)) || $ok; }
if (!$ok) { http_response_code(400); exit('bad signature'); }

// 2. Ignore a delivery you already handled (the same event id comes again if you were slow to answer)
$id = preg_replace('/[^a-z0-9_]/i', '', $_SERVER['HTTP_X_SONATINA_DELIVERY'] ?? '');
if ($id === '' || file_exists(__DIR__ . "/seen_$id")) { http_response_code(200); exit('already handled'); }
touch(__DIR__ . "/seen_$id");

// 3. Do something with it: here, add one line to a text file
$event = json_decode($body, true);
file_put_contents(__DIR__ . '/events.txt', date('c') . ' ' . $event['type'] . ' ' . json_encode($event['data']['object']) . "\n", FILE_APPEND);

http_response_code(200);   // any 2xx tells Sonatina.ca you got it
echo 'ok';

Node.js

// receive.js - run with:  node receive.js   (put it behind https, e.g. with your host's proxy or a tunnel)
const http = require('http'), crypto = require('crypto');
const SECRET = 'whsec_...';                    // your signing secret
const seen = new Set();                        // use a database in real life: this forgets when the program restarts
function verify(header, raw) {
  const m = /^t=(\d+),((?:v1=[a-f0-9]{64},?)+)$/.exec(header || '');
  if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return false;
  const expected = crypto.createHmac('sha256', SECRET).update(m[1] + '.' + raw).digest('hex');
  return m[2].split(',').some(p => crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(p.slice(3))));
}
http.createServer((req, res) => {
  const chunks = [];
  req.on('data', c => chunks.push(c));
  req.on('end', () => {
    const raw = Buffer.concat(chunks).toString('utf8');            // the exact text received
    if (!verify(req.headers['x-sonatina-signature'], raw)) { res.statusCode = 400; return res.end('bad signature'); }
    const id = req.headers['x-sonatina-delivery'];
    if (!seen.has(id)) {                                            // ignore a delivery you already handled
      seen.add(id);
      const event = JSON.parse(raw);
      console.log(event.type, JSON.stringify(event.data.object));  // do something with it here
    }
    res.statusCode = 200; res.end('ok');                            // any 2xx tells Sonatina.ca you got it
  });
}).listen(8080);

Python

# receive.py - run with:  python3 receive.py   (put it behind https, e.g. with your host's proxy or a tunnel)
import hmac, hashlib, json, re, time
from http.server import BaseHTTPRequestHandler, HTTPServer
SECRET = b'whsec_...'                          # your signing secret
seen = set()                                   # use a database in real life: this forgets when the program restarts
def verify(header, raw):
    m = re.fullmatch(r't=(\d+),((?:v1=[a-f0-9]{64},?)+)', header or '')
    if not m or abs(time.time() - int(m.group(1))) > 300:
        return False
    expected = hmac.new(SECRET, m.group(1).encode() + b'.' + raw, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(expected, p[3:]) for p in m.group(2).split(','))
class Hook(BaseHTTPRequestHandler):
    def do_POST(self):
        raw = self.rfile.read(int(self.headers.get('Content-Length', 0)))      # the exact bytes received
        if not verify(self.headers.get('X-Sonatina-Signature'), raw):
            self.send_response(400); self.end_headers(); return
        delivery = self.headers.get('X-Sonatina-Delivery')
        if delivery not in seen:                                                # ignore a delivery you already handled
            seen.add(delivery)
            event = json.loads(raw)
            print(event['type'], json.dumps(event['data']['object']))          # do something with it here
        self.send_response(200); self.end_headers(); self.wfile.write(b'ok')    # any 2xx tells Sonatina.ca you got it
HTTPServer(('', 8080), Hook).serve_forever()

Still stuck? Write to us, or use "Send feedback" inside Sonatina. More help