Appointment Distributor API
One API to create, assign and track appointments across every team and market, with signed webhooks for each change.
Base URL: https://api.appointmentdistributor.com
All requests and responses are JSON over HTTPS. Times are ISO 8601 with a timezone offset.
ad_test_YOUR_TEST_KEY. Keys are shown once, when the admin creates them, and only a hash is stored.Quickstart (curl)
1. Get a test key. Ask the Appointment Distributor admin for a test key for your bot (a self-service dashboard is coming later). You receive the key once. It starts with ad_test_. Test keys only ever reach the separate test database. Store it in an environment variable, never in code:
export AD_KEY="ad_test_YOUR_TEST_KEY"
export AD="https://api.appointmentdistributor.com"
2. Check the service.
curl -s "$AD/api/health"
3. Read (works with any active key).
curl -s "$AD/api/appointments?team=nc-gjc&status=offered" \
-H "Authorization: Bearer $AD_KEY"
4. Create an appointment (needs a key with write access, see Permissions).
curl -s -X POST "$AD/api/appointments" \
-H "Authorization: Bearer $AD_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7d1c0f52-0a63-4a39-8d1e-0d9c5f3b7a11" \
-d '{
"external_id": "lead-10492",
"team": "nc-gjc",
"customer_name": "Jane Doe",
"phone": "(704) 555-0142",
"address": "123 Main St",
"city": "Charlotte",
"state": "NC",
"start": "2026-12-02T13:00:00-05:00",
"notes": "Attic access via garage"
}'
5. Update, reassign, delete (write access).
# accept
curl -s -X PUT "$AD/api/appointments/apt_XXXXXXXX" \
-H "Authorization: Bearer $AD_KEY" -H "Content-Type: application/json" \
-d '{"status":"accepted"}'
# reassign to another team
curl -s -X PUT "$AD/api/appointments/apt_XXXXXXXX" \
-H "Authorization: Bearer $AD_KEY" -H "Content-Type: application/json" \
-d '{"team":"nc-do","assigned_to":"DO"}'
# delete
curl -s -X DELETE "$AD/api/appointments/apt_XXXXXXXX" \
-H "Authorization: Bearer $AD_KEY"
Authentication
Send your key as a bearer token on every /api/appointments and /api/teams request:
Authorization: Bearer ad_test_YOUR_TEST_KEY
- Keys are issued per bot by the admin and shown once. Only a hash (keyed with a server-side secret) is stored, so a lost key cannot be recovered: ask for a new one.
- The admin can turn a key off at any time. A disabled key returns
401 api_key_disabled. - The bot name on every appointment comes from the key, never from the request body.
GET /api/healthneeds no key.
Test vs. live keys
| Key prefix | Reaches | Use for |
|---|---|---|
ad_test_… | The test database only | Development, docs examples, integration tests |
ad_live_… | The live database only | Real appointments |
404 not_found, and vice versa.You may add an optional X-AD-Env: test or X-AD-Env: live header as a safety assertion. If it disagrees with your key you get 403 test_key_cannot_access_live (or live_key_cannot_access_test) and nothing runs. Responses to list and teams calls include "env" so you can confirm where you are.
Webhooks are per environment as well: a webhook registered on test fires only for test appointments.
Permissions
Write access is restricted to the owner bot (Pro Trader).
| Key | GET | POST | PUT | DELETE |
|---|---|---|---|---|
Owner bot keys (can_write = true) | ✅ | ✅ | ✅ | ✅ |
| Every other bot key (default) | ✅ | ❌ 403 | ❌ 403 | ❌ 403 |
- Third-party keys are read-only unless the admin grants write access to that key. The admin can grant or revoke it at any time; every change is audit-logged.
- Write attempts by a read-only key return
403 forbidden_write. The permission is checked before anything else, so the response does not reveal whether an appointment id exists. - The same rules apply to test keys: a new test key is read-only until write access is granted.
HTTP/1.1 403 Forbidden
{
"error": "forbidden_write",
"message": "This key is read-only. Only keys granted write access can create, edit or delete appointments."
}
Teams & markets
| Team id | Name | Market |
|---|---|---|
fl-dialar-squad | Dialar Squad | FL Florida |
sc-clancy | Clancy | SC South Carolina |
nc-do | DO | NC North Carolina |
nc-gjc | GJC | NC North Carolina |
Each team belongs to exactly one market. More teams and markets are added over time; call GET /api/teams for the current list.
Appointment fields
Request bodies use the names in the first column. Responses return the stored record (note team_id / market_id).
| Field | Type | Notes |
|---|---|---|
id | string | Server-generated, apt_…. Read-only. |
external_id | string, required, ≤128 | Your own id for the appointment. Unique per bot. |
team → team_id | string, required | A team id from the table above. |
market → market_id | string, optional | Defaults to the team's market. If sent it must match the team's market. |
customer_name | string, required, ≤200 | |
phone | string, required | US number. Stored as 10 digits ((704) 555-0142, +1 704-555-0142 and 7045550142 are equal). |
address, city | string, optional, ≤300 / ≤100 | |
state | string, optional | 2-letter code, stored uppercase. |
start → start_at, start_utc | ISO 8601, required | Must include a timezone (Z or ±HH:MM). start_at keeps what you sent; start_utc is the normalized UTC instant. |
status | enum | offered (default on create), accepted, declined, reassigned, completed, cancelled |
assigned_to | string, optional, ≤100 | Free text, such as a rep or crew name. |
notes | string, optional, ≤4000 | |
bot | string | The bot that owns the key which created it. Read-only. |
created_by_key | string | Key record id (never the key). Read-only. |
created_at, updated_at | ISO 8601 UTC | Read-only. |
Validation rules
- Bodies must be
Content-Type: application/json(otherwise415), valid JSON objects (400 invalid_json), and at most 32 KB (413). - Invalid values return
422 validation_errorwith the offendingfieldand amessage. startwithout a timezone, e.g."2026-12-02 13:00", is rejected. Use"2026-12-02T13:00:00-05:00".phonemust contain exactly 10 digits after removing punctuation and a leading1.teammust exist and be active. Amarketthat does not match the team's market is rejected.PUTrejects unknown fields.
HTTP/1.1 422 Unprocessable Entity
{ "error": "validation_error", "field": "start", "message": "ISO 8601 with timezone, e.g. 2026-12-01T13:00:00-05:00" }
Idempotency
Send an Idempotency-Key header (any printable string up to 128 characters, such as a UUID) on POST /api/appointments so a network retry never creates two appointments.
- Same key and same body: you get the original response again (status
201) with the headerIdempotent-Replay: true. Nothing new is created. - Same key, different body:
422 idempotency_key_reused_with_different_body. - Keys are scoped to your API key.
Duplicate rules
Two independent guards, both enforced by the database as unique constraints:
- Same bot +
external_id: one appointment per external id per bot. - Same market + phone + start time (compared in UTC): the same customer cannot be booked twice at the same moment in a market, even by different bots.
A duplicate returns 409 with the id of the existing appointment, so you can switch to an update:
HTTP/1.1 409 Conflict
{ "error": "duplicate", "existing_id": "apt_AbC123…", "reason": "same bot + external_id" }
reason is same bot + external_id or same phone + start time in market. The same checks run on PUT when you change external_id, phone, start or team.
GET /api/health
GET/api/health no auth
HTTP/1.1 200 OK
{ "ok": true, "version": "1.0.0", "db": { "live": true, "test": true }, "time": "2026-12-01T18:00:00.000Z" }
Returns 503 with "ok": false if a database is unreachable.
GET /api/teams
GET/api/teams any active key
Lists teams and markets in the environment of your key.
{ "env": "test",
"teams": [ { "id": "nc-gjc", "name": "GJC", "market_id": "NC", "active": 1, "created_at": "…" } ],
"markets": [ { "id": "NC", "name": "North Carolina", "timezone": "America/New_York", "active": 1, "created_at": "…" } ] }
POST /api/appointments
POST/api/appointments write access
Creates an appointment. Status defaults to offered. Optional header: Idempotency-Key.
Request
{
"external_id": "lead-10492",
"team": "nc-gjc",
"customer_name": "Jane Doe",
"phone": "(704) 555-0142",
"address": "123 Main St",
"city": "Charlotte",
"state": "NC",
"start": "2026-12-02T13:00:00-05:00",
"assigned_to": "GJC",
"notes": "Attic access via garage"
}
Response 201 Created
{
"appointment": {
"id": "apt_Qx1v0m9aT3dK2sLw",
"bot": "pro-trader",
"external_id": "lead-10492",
"team_id": "nc-gjc",
"market_id": "NC",
"customer_name": "Jane Doe",
"phone": "7045550142",
"address": "123 Main St",
"city": "Charlotte",
"state": "NC",
"start_at": "2026-12-02T13:00:00-05:00",
"start_utc": "2026-12-02T18:00:00.000Z",
"status": "offered",
"assigned_to": "GJC",
"notes": "Attic access via garage",
"created_by_key": "key_xxxxxxxxxxxxxxxx",
"created_at": "2026-12-01T18:00:00.000Z",
"updated_at": "2026-12-01T18:00:00.000Z"
}
}
Errors: 401, 403 forbidden_write, 409 duplicate, 422, 429.
GET /api/appointments
GET/api/appointments any active key
| Query parameter | Meaning |
|---|---|
team | Team id, e.g. nc-do |
market | FL, SC, NC |
status | One of the statuses |
bot | Bot that created it |
assigned_to | Exact match |
date | YYYY-MM-DD, the appointment's local date as sent in start |
from, to | ISO 8601 with timezone. Range on the UTC start time: from inclusive, to exclusive |
limit, offset | Paging. limit default 100, max 500 |
Results are ordered by start time, earliest first.
curl -s "$AD/api/appointments?market=NC&date=2026-12-02&status=offered" \
-H "Authorization: Bearer $AD_KEY"
{ "env": "test", "count": 1, "limit": 100, "offset": 0, "appointments": [ { …appointment… } ] }
GET /api/appointments/:id
GET/api/appointments/{id} any active key
{ "appointment": { …appointment… } }
Unknown id (or an id from the other environment): 404 not_found.
PUT /api/appointments/:id
PUT/api/appointments/{id} write access
Partial update: send only the fields you want to change (same names as on create). Use it to change status, reassign or edit details.
- Reassign by sending a new
teamand/orassigned_to. If you do not also send astatus, the status becomesreassigned. - Changing
teamwithoutmarketmoves the appointment to that team's market.
curl -s -X PUT "$AD/api/appointments/apt_Qx1v0m9aT3dK2sLw" \
-H "Authorization: Bearer $AD_KEY" -H "Content-Type: application/json" \
-d '{ "team": "nc-do", "assigned_to": "DO" }'
{ "appointment": { …, "team_id": "nc-do", "assigned_to": "DO", "status": "reassigned", … } }
Errors: 403 forbidden_write, 404, 409 duplicate, 422.
DELETE /api/appointments/:id
DELETE/api/appointments/{id} write access
{ "deleted": true, "id": "apt_Qx1v0m9aT3dK2sLw" }
Deletion is permanent, but the audit log keeps the full before-image. To keep a record on the board, set status to cancelled instead.
Errors
Errors are JSON: { "error": "code", …details }.
| HTTP | error | Meaning |
|---|---|---|
| 400 | invalid_json, invalid_idempotency_key | Malformed body or header. |
| 401 | missing_api_key, invalid_api_key, api_key_disabled | No key, unknown key, or a key the admin turned off. |
| 403 | forbidden_write | Your key is read-only. See Permissions. |
| 403 | test_key_cannot_access_live, live_key_cannot_access_test | X-AD-Env disagrees with your key. |
| 404 | not_found | No such appointment in your environment, or unknown route. |
| 405 | method_not_allowed | |
| 409 | duplicate | Includes existing_id and reason. |
| 413 / 415 | body_too_large / content_type_must_be_json | |
| 422 | validation_error, idempotency_key_reused_with_different_body | Includes field and message. |
| 429 | rate_limited | Includes retry_after_s. |
| 500 | internal_error | Safe to retry reads. Retry writes with the same Idempotency-Key. |
Rate limits & CORS
- About 120 requests per minute per key. Over the limit you receive
429withretry_after_s. Back off and retry. - The API is meant for server-to-server use. Browser calls (CORS) are allowed only from
https://app.appointmentdistributor.com.
Webhooks
Webhooks push changes to your server as they happen. The admin registers an https URL for a bot and/or team and receives a signing secret, shown once.
Events
| Event | Fires when |
|---|---|
offered | An appointment is created with status offered. |
accepted | Status changes to accepted. |
declined | Status changes to declined. |
reassigned | The team or assigned_to changes (or status changes to reassigned). |
completed | Status changes to completed. |
One update can fire more than one event (for example accepting and reassigning in the same call). Deletions and edits that do not change status, team or assignee do not fire webhooks.
Delivery
POST https://your-server.example/hooks/appointments
Content-Type: application/json
User-Agent: AppointmentDistributor-Webhooks/1
X-AD-Event: reassigned
X-AD-Delivery: evt_8s7Dk2LmQp0a
X-AD-Signature: t=1764612000,v1=5b1e…c9f0
{
"id": "evt_8s7Dk2LmQp0a",
"event": "reassigned",
"created_at": "2026-12-01T18:00:00.000Z",
"appointment": { …full appointment record… }
}
- Reply with any
2xxwithin 8 seconds to acknowledge. - Retries: up to 3 attempts per event, with a 1 second then a 2 second pause. If all fail, the failure (status and error) is recorded for the admin; there is no later automatic redelivery, so reconcile with
GET /api/appointmentsif your endpoint was down. - Delivery is at least once. Use
X-AD-Delivery(or the bodyid) to ignore repeats. - Webhooks run per environment: test appointments trigger test webhooks only.
Verifying signatures
Every request carries X-AD-Signature: t=<unix seconds>,v1=<hex> where v1 = HMAC-SHA256(signing_secret, t + "." + raw_body). Always verify against the raw request body (before JSON parsing), compare in constant time, and reject timestamps older than 5 minutes.
Python
import hmac, hashlib, time
def verify_ad_signature(raw_body: bytes, header: str, secret: str, tolerance=300) -> bool:
parts = dict(p.split("=", 1) for p in header.split(","))
t, v1 = parts.get("t"), parts.get("v1")
if not t or not v1 or abs(time.time() - int(t)) > tolerance:
return False
expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, v1)
# Flask example
# @app.post("/hooks/appointments")
# def hook():
# if not verify_ad_signature(request.get_data(), request.headers.get("X-AD-Signature", ""), os.environ["AD_WEBHOOK_SECRET"]):
# return "bad signature", 401
# event = request.get_json()
# return "", 204
Node.js
import crypto from "node:crypto";
export function verifyAdSignature(rawBody, header, secret, toleranceSec = 300) {
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
const { t, v1 } = parts;
if (!t || !v1 || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSec) return false;
const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
const a = Buffer.from(expected), b = Buffer.from(v1);
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
// Express example (use express.raw so you keep the raw body)
// app.post("/hooks/appointments", express.raw({ type: "application/json" }), (req, res) => {
// const ok = verifyAdSignature(req.body.toString("utf8"), req.get("X-AD-Signature") || "", process.env.AD_WEBHOOK_SECRET);
// if (!ok) return res.sendStatus(401);
// const event = JSON.parse(req.body.toString("utf8"));
// res.sendStatus(204);
// });
Admin (key & hook management)
These endpoints use a separate admin credential held only by the Appointment Distributor admin. They are listed so you know what to ask for; a dashboard for them is coming. Bot keys cannot call them (401 admin_auth_required).
| Request | What it does |
|---|---|
POST /api/admin/keys | Create a key for a bot: { "name", "bot", "env": "test"|"live", "can_write": false }. Shows the key once. can_write defaults to false. |
GET /api/admin/keys | List keys (prefix, bot, env, active, can_write, last used). Never shows the key itself. |
POST /api/admin/keys/{id}/disable · /enable | Turn a key off or on. |
PUT /api/admin/keys/{id}/permissions | Grant or revoke write access: { "can_write": true|false }. Audit-logged. |
POST /api/admin/webhooks?env= | Register a webhook: { "url", "bot"?, "team"?, "events"? }. Returns the signing secret once. |
GET /api/admin/webhook-deliveries?env= | Delivery log with attempts and failures. |
GET /api/audit?env= | Audit log of every create, update, delete and key change, with before/after and which key did it. |
Need a test key? Ask the admin for a test key for your bot name. State whether you need write access (normally not). You will get the key once, plus a signing secret if you want webhooks.
Appointment Distributor API v1.0.0 · status