{"openapi":"3.1.0","info":{"title":"Doc365.lk API","version":"1.0.0","summary":"Token booking and live queues for clinics in Sri Lanka.","description":"Public endpoints need no key. Use them to find a clinic, list its doctors and sessions for the next 14 days,\nbook a token for a patient, and follow the live queue.\n\nRules for agents booking on behalf of a person: only book when the person has asked for it and given their own\nname and Sri Lankan mobile number; the clinic sends the confirmation SMS to that number. Do not book several\ntokens to hold places. Times are local (Asia/Colombo) and ETAs are estimates, not appointments.\n\nErrors are `{ \"error\": { \"code\", \"message\", \"details?\" } }` and `message` is written to be shown to a person.\nRate limits: 300 requests a minute per IP overall; booking and cancelling are limited further.","contact":{"name":"Doc365.lk","email":"hello@doc365.lk","url":"https://doc365.lk"}},"servers":[{"url":"https://backend.doc365.lk/api/v1"}],"externalDocs":{"description":"Product overview for assistants","url":"https://doc365.lk/llms.txt"},"tags":[{"name":"Clinics","description":"Find clinics and see their doctors and sessions"},{"name":"Bookings","description":"Book, track and cancel a token"},{"name":"Queue","description":"Live queue boards"},{"name":"Plans","description":"Doc365 subscription plans"},{"name":"Auth","description":"Sign-in for clinic staff"},{"name":"Staff","description":"Clinic staff endpoints (bearer token)"}],"paths":{"/public/clinics":{"get":{"tags":["Clinics"],"operationId":"searchClinics","summary":"Search clinics that take online bookings","description":"Matches the clinic name, town, district or page slug. Without `q`, lists every listed clinic.","parameters":[{"name":"q","in":"query","required":false,"description":"Name, town or district","schema":{"type":"string","maxLength":60,"example":"Kurunegala"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","required":["clinics"],"properties":{"clinics":{"type":"array","items":{"$ref":"#/components/schemas/ClinicListItem"}}}}}}}}}},"/public/clinics/{slug}":{"get":{"tags":["Clinics"],"operationId":"getClinic","summary":"A clinic, its doctors and its sessions for the next 14 days","parameters":[{"name":"slug","in":"path","required":true,"description":"The clinic’s page name, as in doc365.lk/c/{slug}","schema":{"type":"string","example":"sahana-medical-centre"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClinicDetail"}}}},"404":{"$ref":"#/components/responses/E404"}}}},"/public/clinics/{slug}/bookings":{"post":{"tags":["Bookings"],"operationId":"bookToken","summary":"Book a token in a session","description":"Only for sessions with `bookable: true`. The patient gets an SMS with the token number and reference. Keep the reference: it is how the booking is tracked and cancelled.","parameters":[{"name":"slug","in":"path","required":true,"description":"Clinic page name","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["sessionId","name","phone"],"properties":{"sessionId":{"type":"string","description":"From `sessions[].id` of getClinic"},"name":{"type":"string","minLength":2,"maxLength":120,"description":"Patient’s name"},"phone":{"type":"string","minLength":9,"maxLength":20,"description":"Sri Lankan mobile number, e.g. 0771234567","example":"0771234567"},"email":{"type":"string","format":"email"}}}}}},"responses":{"201":{"description":"Booked","content":{"application/json":{"schema":{"type":"object","properties":{"booking":{"type":"object","properties":{"reference":{"type":"string","example":"MC7K2P"},"tokenNumber":{"type":"integer","example":12},"status":{"type":"string","example":"BOOKED"},"eta":{"type":"string","pattern":"^\\d{2}:\\d{2}$","description":"Approximate time the token is seen","example":"17:30"}}}}}}}},"403":{"$ref":"#/components/responses/E403"},"404":{"$ref":"#/components/responses/E404"},"409":{"$ref":"#/components/responses/E409"},"422":{"$ref":"#/components/responses/E422"},"429":{"$ref":"#/components/responses/E429"}}}},"/public/bookings/{reference}":{"get":{"tags":["Bookings"],"operationId":"trackBooking","summary":"Live status of a booking","description":"Patients ahead, the token now with the doctor and an updated ETA. Poll at most every 20 seconds.","parameters":[{"name":"reference","in":"path","required":true,"description":"Booking reference from the SMS","schema":{"type":"string","example":"MC7K2P"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"booking":{"$ref":"#/components/schemas/BookingStatus"}}}}}},"404":{"$ref":"#/components/responses/E404"}}}},"/public/bookings/{reference}/cancel":{"post":{"tags":["Bookings"],"operationId":"cancelBooking","summary":"Cancel a booking","description":"The phone number must match the one the booking was made with. Only bookings not yet called can be cancelled.","parameters":[{"name":"reference","in":"path","required":true,"description":"Booking reference","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["phone"],"properties":{"phone":{"type":"string"}}}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"403":{"$ref":"#/components/responses/E403"},"404":{"$ref":"#/components/responses/E404"},"409":{"$ref":"#/components/responses/E409"},"429":{"$ref":"#/components/responses/E429"}}}},"/public/bookings/{reference}/pay":{"post":{"tags":["Bookings"],"operationId":"payBookingFee","summary":"Pay the channelling fee online","description":"For clinics that take online payment. Returns PayHere checkout fields to post to `action`. A token held for payment is released if not paid within 20 minutes.","parameters":[{"name":"reference","in":"path","required":true,"description":"Booking reference","schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"checkout":{"type":"object","properties":{"action":{"type":"string"},"fields":{"type":"object","additionalProperties":{"type":"string"}}}}}}}}},"404":{"$ref":"#/components/responses/E404"},"409":{"$ref":"#/components/responses/E409"},"429":{"$ref":"#/components/responses/E429"}}}},"/public/arrive/{slug}/{code}":{"post":{"tags":["Queue"],"operationId":"checkInAtDoor","summary":"Check in on arrival (door QR code)","description":"Marks the bookings for today made with this phone number as arrived. The code comes from the poster the clinic prints.","parameters":[{"name":"slug","in":"path","required":true,"description":"Clinic slug","schema":{"type":"string"}},{"name":"code","in":"path","required":true,"description":"Code printed on the poster","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["phone"],"properties":{"phone":{"type":"string"}}}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"checkedIn":{"type":"array","items":{"type":"object"}}}}}}},"404":{"$ref":"#/components/responses/E404"},"422":{"$ref":"#/components/responses/E422"},"429":{"$ref":"#/components/responses/E429"}}}},"/public/status":{"get":{"tags":["Clinics"],"operationId":"serviceStatus","summary":"Whether bookings, screens, SMS, WhatsApp and payments are working","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"checkedAt":{"type":"string","format":"date-time"},"components":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"state":{"type":"string","enum":["ok","degraded","down","off"]}}}}}}}}}}}},"/public/sessions/{sessionId}/queue":{"get":{"tags":["Queue"],"operationId":"sessionQueue","summary":"Queue board for one session","parameters":[{"name":"sessionId","in":"path","required":true,"description":"Session id","schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"queue":{"$ref":"#/components/schemas/QueueSnapshot"}}}}}},"404":{"$ref":"#/components/responses/E404"}}}},"/plans":{"get":{"tags":["Plans"],"operationId":"listPlans","summary":"Subscription plans and monthly prices in LKR","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"plans":{"type":"array","items":{"$ref":"#/components/schemas/Plan"}}}}}}}}}},"/auth/login":{"post":{"tags":["Auth"],"operationId":"login","summary":"Staff sign-in with email and password","description":"Returns a 15-minute access token. Browsers also get an httpOnly refresh cookie; apps keep `refreshToken`.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["email","password"],"properties":{"email":{"type":"string","format":"email"},"password":{"type":"string"}}}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Session"}}}},"401":{"$ref":"#/components/responses/E401"},"429":{"$ref":"#/components/responses/E429"}}}},"/auth/refresh":{"post":{"tags":["Auth"],"operationId":"refresh","summary":"Swap a refresh token for a new access token","description":"Refresh tokens rotate: store the new one each time.","requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"object","properties":{"refreshToken":{"type":"string"}}}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Session"}}}},"401":{"$ref":"#/components/responses/E401"}}}},"/auth/me":{"get":{"tags":["Auth"],"operationId":"me","summary":"The signed-in user and their clinics and roles","security":[{"bearer":[]}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/E401"}}}},"/clinics/{clinicId}/dashboard":{"get":{"tags":["Staff"],"operationId":"dayDashboard","summary":"A day at the clinic: totals and every session with who is in the room and who is next","description":"Fees are zero and `revenueHidden: true` for reception and pharmacists.","security":[{"bearer":[]}],"parameters":[{"name":"clinicId","in":"path","required":true,"description":"Clinic id from /auth/me","schema":{"type":"string"}},{"name":"date","in":"query","required":false,"schema":{"type":"string","format":"date","example":"2026-11-11"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/E401"},"403":{"$ref":"#/components/responses/E403"}}}},"/clinics/{clinicId}/sessions/{sessionId}/queue":{"post":{"tags":["Staff"],"operationId":"queueAction","summary":"Run the queue","description":"Doctors, reception, admins and owners. `next` finishes the patient in the room and calls the next token.","security":[{"bearer":[]}],"parameters":[{"name":"clinicId","in":"path","required":true,"description":"Clinic id","schema":{"type":"string"}},{"name":"sessionId","in":"path","required":true,"description":"Session id","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["action"],"properties":{"action":{"type":"string","enum":["open","pause","resume","close","next","call","complete","skip","noshow","checkin","recall"]},"bookingId":{"type":"string","description":"For call, checkin, noshow and recall"}}}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/E401"},"402":{"$ref":"#/components/responses/E402"},"403":{"$ref":"#/components/responses/E403"},"409":{"$ref":"#/components/responses/E409"}}}}},"components":{"securitySchemes":{"bearer":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"responses":{"E400":{"description":"The request was not valid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"E401":{"description":"Sign in first","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"E402":{"description":"The clinic’s plan has ended; the queue is read-only","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"E403":{"description":"Not allowed, for example online booking is off for this clinic","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"E404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"E409":{"description":"Conflict, for example the session is full or has ended","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"E422":{"description":"Some fields need fixing; see error.details","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"E429":{"description":"Too many requests; wait and try again","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"object","required":["code","message"],"properties":{"code":{"type":"string"},"message":{"type":"string"},"details":{}}}}},"Ok":{"type":"object","properties":{"ok":{"type":"boolean","const":true}}},"ClinicType":{"type":"string","enum":["DISPENSARY","CLINIC","CHANNELLING_CENTRE","MEDICAL_CENTRE"]},"ClinicListItem":{"type":"object","properties":{"slug":{"type":"string"},"name":{"type":"string"},"type":{"$ref":"#/components/schemas/ClinicType"},"city":{"type":["string","null"]},"district":{"type":["string","null"]},"addressLine":{"type":["string","null"]},"doctors":{"type":"integer","description":"Doctors listed"},"updatedAt":{"type":"string","format":"date-time"}}},"Doctor":{"type":"object","properties":{"id":{"type":"string"},"title":{"type":"string","example":"Dr."},"name":{"type":"string"},"specialty":{"type":["string","null"]},"consultationFee":{"type":"string","description":"LKR, decimal string","example":"1500.00"},"photoUrl":{"type":["string","null"]},"bio":{"type":["string","null"]}}},"Session":{"type":"object","properties":{"accessToken":{"type":"string"},"refreshToken":{"type":"string"},"user":{"type":"object"}}},"ClinicSession":{"type":"object","properties":{"id":{"type":"string"},"doctorId":{"type":"string"},"date":{"type":"string","format":"date","example":"2026-11-11"},"startTime":{"type":"string","pattern":"^\\d{2}:\\d{2}$","description":"24-hour local time, Asia/Colombo","example":"17:30"},"endTime":{"type":"string","pattern":"^\\d{2}:\\d{2}$","description":"24-hour local time, Asia/Colombo","example":"17:30"},"delayMinutes":{"type":"integer","description":"Doctor running late by this many minutes (0 = on time); already included in every estimate"},"expectedStart":{"type":"string","pattern":"^\\d{2}:\\d{2}$","description":"Start time to expect now: startTime plus delayMinutes","example":"17:30"},"status":{"type":"string","enum":["SCHEDULED","OPEN","PAUSED"]},"room":{"type":["string","null"]},"tokensLeft":{"type":"integer"},"nextToken":{"type":"integer","description":"The token number a new booking would get"},"nextTokenEta":{"type":"string","pattern":"^\\d{2}:\\d{2}$","description":"Approximate time that token is seen","example":"17:30"},"bookable":{"type":"boolean"},"reason":{"type":["string","null"],"description":"Why it cannot be booked online, to show the person"}}},"ClinicDetail":{"type":"object","properties":{"clinic":{"type":"object","properties":{"slug":{"type":"string"},"name":{"type":"string"},"type":{"$ref":"#/components/schemas/ClinicType"},"phone":{"type":["string","null"]},"email":{"type":["string","null"]},"addressLine":{"type":["string","null"]},"city":{"type":["string","null"]},"district":{"type":["string","null"]},"latitude":{"type":["string","null"]},"longitude":{"type":["string","null"]},"publicBooking":{"type":"boolean","description":"False when the clinic only books by phone or at the counter"}}},"doctors":{"type":"array","items":{"$ref":"#/components/schemas/Doctor"}},"sessions":{"type":"array","items":{"$ref":"#/components/schemas/ClinicSession"}}}},"BookingStatus":{"type":"object","properties":{"reference":{"type":"string"},"tokenNumber":{"type":"integer"},"status":{"type":"string","enum":["BOOKED","CHECKED_IN","IN_CONSULTATION","COMPLETED","CANCELLED","NO_SHOW","SKIPPED"]},"patientName":{"type":"string","description":"Shortened for privacy"},"eta":{"type":["string","null"],"pattern":"^\\d{2}:\\d{2}$","description":"24-hour local time, Asia/Colombo","example":"17:30"},"nowServing":{"type":["integer","null"]},"patientsAhead":{"type":"integer"},"session":{"type":"object"},"doctor":{"type":"object"},"clinic":{"type":"object"}}},"QueueSnapshot":{"type":"object","properties":{"sessionId":{"type":"string"},"status":{"type":"string"},"currentToken":{"type":"integer"},"nowServing":{"type":["object","null"],"properties":{"token":{"type":"integer"},"name":{"type":"string"}}},"upNext":{"type":"array","items":{"type":"object","properties":{"token":{"type":"integer"},"name":{"type":"string"},"arrived":{"type":"boolean"}}}},"waitingCount":{"type":"integer"},"seenCount":{"type":"integer"},"avgMinutes":{"type":"integer"}}},"Plan":{"type":"object","properties":{"code":{"type":"string"},"name":{"type":"string"},"priceMonthly":{"type":"string","description":"LKR"},"currency":{"type":"string","example":"LKR"},"maxDoctors":{"type":"integer"},"maxStaff":{"type":"integer"},"smsPerMonth":{"type":"integer"},"features":{}}}}}}