Skip to main content
Keeping your external tools in sync with ByDoctor appointments prevents double-booking, ensures patients see accurate availability, and eliminates manual data entry across systems. This guide walks you through two integration approaches — polling and webhooks — and shows you how to check availability and create appointments programmatically.

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.
Periodically call 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.
Paginate through all results using the 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 POST /webhooks with the URL of your listener and the list of events you want to subscribe to.
Save the 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.
Example response:
Filter the response to slots where available is true before presenting options to the patient.

Creating an appointment

Once you have confirmed availability, create the appointment with POST /appointments.
Response — 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:
Use the ByDoctor appointment id (e.g., apt_f47ac10b) as your external calendar event’s unique identifier. Storing it as a custom property means you can always look up the external event from the ByDoctor ID and avoid creating duplicates when processing webhook retries.