Skip to main content
Patient records are the foundation of every clinical workflow. Whether you are migrating an existing patient database into ByDoctor, pushing new patients from a CRM, or keeping a downstream EHR up to date, the Patients API gives you the tools to create, search, update, and bulk-import records programmatically.
Patient records in ByDoctor include the CPF (Cadastro de Pessoa Física — Brazilian individual tax ID) and protected health information. Under the LGPD (Lei Geral de Proteção de Dados), this data must be processed lawfully, stored only in Brazil, and never shared with unauthorised third parties. Ensure your integration stores and transmits patient data over HTTPS, applies access controls, and has a documented legal basis for processing.

Creating a patient

Use POST /patients to add a new patient to a clinic. The name and phone fields are required; all other fields are optional but strongly recommended for a complete clinical record.
Response — 201 Created:
Always send phone numbers in E.164 format — a leading +, the country code, area code, and number with no spaces or punctuation (e.g., +5511999999999). ByDoctor uses this number to send WhatsApp notifications; an incorrectly formatted number silently prevents delivery.

Searching for patients

Before creating a patient, search for an existing record to avoid duplicates. GET /patients?search= matches against name, phone, and CPF simultaneously.
For deduplication, prefer searching by CPF or phone rather than name — these are unique identifiers, while names can have spelling variations. Use ?search=123.456.789-00 or ?search=+5511999999999 for precise lookups.

Updating a patient

Use PATCH /patients/{id} to apply a partial update. Send only the fields you want to change — all other fields remain untouched.
Response — 200 OK returns the full updated patient object.

Deduplication strategy

When syncing from an external system, determine whether a patient already exists in ByDoctor before deciding to create or update:
  1. Search by CPF — CPF is a national unique identifier; if a match is found, it is the same person.
  2. Search by phone — Use as a secondary fallback if CPF is unavailable.
  3. If no match is found — Call POST /patients to create the record.
  4. If a match is found — Compare fields and call PATCH /patients/{id} only if data has changed.

Bulk import from CSV

1

Parse the CSV file

Read the file row by row and normalise the data — strip formatting from CPF (remove . and -), convert phone numbers to E.164, and standardise date formats to YYYY-MM-DD.
2

Check each patient by CPF or phone

Query ByDoctor for each patient before writing to avoid duplicates.
3

Create if missing, update if changed

Upsert each patient based on the lookup result.

Webhook-based sync

Subscribe to patient.created and patient.updated events to push changes from ByDoctor into your external system in real time — for example, to update a CRM or populate a data warehouse.
Handle each event in your listener: