Approaches to syncing
You have two strategies for keeping an external calendar or booking platform aligned with ByDoctor. Webhooks are the recommended approach for production integrations because they are real-time and reduce unnecessary API calls.- Polling (simple)
- Webhooks (recommended)
Periodically call Paginate through all results using the
GET /appointments with starts_after and starts_before filters and upsert the results into your system. This is straightforward to implement but introduces latency equal to your polling interval and increases API usage.page and per_page query parameters. Continue requesting the next page until the response’s meta.total_pages value equals the current page number. For each appointment returned, upsert it into your external system using the ByDoctor id field as your primary key.Webhook-based sync: step by step
1
Register your webhook endpoint
Call Save the
POST /webhooks with the URL of your listener and the list of events you want to subscribe to.secret you provide — ByDoctor uses it to sign every webhook payload with an X-ByDoctor-Signature header so you can verify authenticity.2
Handle appointment.created → create an external calendar event
When ByDoctor fires
appointment.created, create the corresponding event in your external calendar using the appointment’s id as the external event identifier.3
Handle appointment.confirmed → mark the external event as confirmed
When ByDoctor fires
appointment.confirmed, update the corresponding external calendar event to reflect the confirmed status. This is useful for signalling to staff that the patient has acknowledged the appointment.4
Handle appointment.updated → update the external event
For
appointment.updated, fetch the existing external event by the ByDoctor id stored in extendedProperties and patch only the fields that changed.5
Handle appointment.cancelled → remove or mark the event
Delete the external calendar event when a cancellation arrives, or mark it with a cancelled status depending on your audit requirements.
Checking availability before booking
Before creating an appointment, verify that the professional has an open slot using the availability endpoint.available is true before presenting options to the patient.
Creating an appointment
Once you have confirmed availability, create the appointment withPOST /appointments.
201 Created:
All timestamps in the API are in UTC. When displaying times to patients or staff in Brazil, convert to the
America/Sao_Paulo timezone (UTC−3, or UTC−2 during Daylight Saving Time). In JavaScript, use Intl.DateTimeFormat with timeZone: "America/Sao_Paulo", or a library like date-fns-tz: