Skip to main content
The ByDoctor API uses API keys for authentication. Every request must include a valid key in the Authorization header using the Bearer token scheme. Without a valid key, the API returns 401 Unauthorized and ignores the request entirely.

API Keys Overview

An API key is a long-lived credential tied to a specific ByDoctor clinic account. Each key carries a set of scopes that determine which operations it can perform. You can issue multiple keys — for example, one key per integration or service — and revoke any key independently without affecting the others.
API keys are issued at the clinic level. A key has access only to the data belonging to the clinic under which it was created, enforcing ByDoctor’s multi-tenant isolation model.

How to Get Your API Key

1

Log in to your ByDoctor dashboard

Navigate to app.bydoctor.com.br and sign in with an account that has the Admin role. Only Admins can manage API keys.
2

Open the API settings page

In the left navigation, click Settings, then select the API tab. This page lists all active keys for your clinic.
3

Create a new API key

Click New API Key, enter a descriptive name (for example, scheduling-sync-prod), and select the scopes your integration needs. Click Create.
4

Copy and store your key securely

The full key is displayed only once at creation time. Copy it immediately and store it in a secrets manager or environment variable. ByDoctor does not show the raw key again after you close the dialog.

Passing Your API Key in Requests

Include your API key as a Bearer token in the Authorization header of every request. The header format is:
Replace YOUR_API_KEY with the key you copied from the dashboard. Never hardcode the key directly in source files — use an environment variable like BYDOCTOR_API_KEY and inject it at runtime.

Key Scopes

Scopes limit what an API key can do. Assign the minimum set of scopes required for your integration to follow the principle of least privilege.
Most read-heavy integrations — such as dashboard widgets or reporting tools — only need the read scope. Reserve admin-scoped keys for internal back-end services.

Rotating Your API Key

Rotate your key whenever you suspect it has been exposed, or as part of a regular credential rotation schedule. Rotation is immediate — the old key stops working the moment you revoke it.
1

Create the replacement key first

Follow the steps in How to Get Your API Key to issue a new key with the same scopes. Update all services that use the old key to reference the new one.
2

Verify the new key is working

Make a test request using the new key and confirm you receive a 200 OK response before proceeding.
3

Revoke the old key

Return to Settings → API in the dashboard, locate the old key by name, and click Revoke. Confirm the action. The key is immediately invalidated.

Authentication Error Responses

When authentication fails, the API returns a structured JSON error body alongside the appropriate HTTP status code.

401 Unauthorized

Returned when no API key is provided, the key is malformed, or the key has been revoked.

403 Forbidden

Returned when the API key is valid but lacks the scope required for the requested operation — for example, using a read-only key to create an appointment.

Security Best Practices

Never commit API keys to source control. A key accidentally pushed to a public repository should be considered compromised immediately. Revoke it and issue a replacement before doing anything else.
Follow these practices to keep your API keys secure:
  • Use environment variables — Store keys in environment variables (e.g., BYDOCTOR_API_KEY) and load them at runtime. Use a secrets manager such as AWS Secrets Manager, HashiCorp Vault, or Doppler in production environments.
  • Issue one key per integration — Separate keys per service make it easy to revoke a single compromised key without affecting other integrations.
  • Apply minimal scopes — Only grant the scopes an integration actually needs. A webhook consumer needs only read; a booking engine needs write.
  • Rotate keys regularly — Establish a rotation schedule (for example, every 90 days) and automate it where possible.
  • Monitor for unexpected usage — Review the audit log in Settings → Audit Trail to detect unusual patterns such as high request volumes from unexpected IP addresses.