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.

Never put a real key on a web page, in a repo or in a chat. Every example on this site uses placeholders such as 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

Test vs. live keys

Key prefixReachesUse for
ad_test_…The test database onlyDevelopment, docs examples, integration tests
ad_live_…The live database onlyReal appointments
A test key can never touch a real appointment. The two environments are separate databases. The key's prefix and its stored record must agree, and the server chooses the database from that and nothing else. A test key looking up a live appointment id simply gets 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).

KeyGETPOSTPUTDELETE
Owner bot keys (can_write = true)✅✅✅✅
Every other bot key (default)✅❌ 403❌ 403❌ 403
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 idNameMarket
fl-dialar-squadDialar SquadFL Florida
sc-clancyClancySC South Carolina
nc-doDONC North Carolina
nc-gjcGJCNC 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).

FieldTypeNotes
idstringServer-generated, apt_…. Read-only.
external_idstring, required, ≤128Your own id for the appointment. Unique per bot.
team → team_idstring, requiredA team id from the table above.
market → market_idstring, optionalDefaults to the team's market. If sent it must match the team's market.
customer_namestring, required, ≤200
phonestring, requiredUS number. Stored as 10 digits ((704) 555-0142, +1 704-555-0142 and 7045550142 are equal).
address, citystring, optional, ≤300 / ≤100
statestring, optional2-letter code, stored uppercase.
start → start_at, start_utcISO 8601, requiredMust include a timezone (Z or ±HH:MM). start_at keeps what you sent; start_utc is the normalized UTC instant.
statusenumoffered (default on create), accepted, declined, reassigned, completed, cancelled
assigned_tostring, optional, ≤100Free text, such as a rep or crew name.
notesstring, optional, ≤4000
botstringThe bot that owns the key which created it. Read-only.
created_by_keystringKey record id (never the key). Read-only.
created_at, updated_atISO 8601 UTCRead-only.

Validation rules

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.

Duplicate rules

Two independent guards, both enforced by the database as unique constraints:

  1. Same bot + external_id: one appointment per external id per bot.
  2. 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 parameterMeaning
teamTeam id, e.g. nc-do
marketFL, SC, NC
statusOne of the statuses
botBot that created it
assigned_toExact match
dateYYYY-MM-DD, the appointment's local date as sent in start
from, toISO 8601 with timezone. Range on the UTC start time: from inclusive, to exclusive
limit, offsetPaging. 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.

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 }.

HTTPerrorMeaning
400invalid_json, invalid_idempotency_keyMalformed body or header.
401missing_api_key, invalid_api_key, api_key_disabledNo key, unknown key, or a key the admin turned off.
403forbidden_writeYour key is read-only. See Permissions.
403test_key_cannot_access_live, live_key_cannot_access_testX-AD-Env disagrees with your key.
404not_foundNo such appointment in your environment, or unknown route.
405method_not_allowed
409duplicateIncludes existing_id and reason.
413 / 415body_too_large / content_type_must_be_json
422validation_error, idempotency_key_reused_with_different_bodyIncludes field and message.
429rate_limitedIncludes retry_after_s.
500internal_errorSafe to retry reads. Retry writes with the same Idempotency-Key.

Rate limits & CORS

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

EventFires when
offeredAn appointment is created with status offered.
acceptedStatus changes to accepted.
declinedStatus changes to declined.
reassignedThe team or assigned_to changes (or status changes to reassigned).
completedStatus 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… }
}

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).

RequestWhat it does
POST /api/admin/keysCreate 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/keysList keys (prefix, bot, env, active, can_write, last used). Never shows the key itself.
POST /api/admin/keys/{id}/disable · /enableTurn a key off or on.
PUT /api/admin/keys/{id}/permissionsGrant 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