{"openapi":"3.0.0","info":{"title":"Biocanic API","version":"1.0.0"},"servers":[{"url":"/api/v1","description":"API v1"}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"Tracker":{"type":"object","description":"A tracker represents an individual metric being tracked for a user.","properties":{"_id":{"type":"string","description":"MongoDB ObjectId"},"name":{"type":"string"},"subtitle":{"type":"string"},"user":{"type":"string","description":"User ID reference"},"trackerType":{"type":"string","example":"standard"},"metricType":{"type":"string"},"startDate":{"type":"string","format":"date-time"},"endDate":{"type":"string","format":"date-time"},"active":{"type":"boolean"},"deleted":{"type":"boolean"},"data":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string","format":"date-time"},"value":{"type":"number"}}}},"wearablesId":{"type":"string","description":"Wearables reference when populated"},"updatedAt":{"type":"string","format":"date-time"},"createdAt":{"type":"string","format":"date-time"}}}}},"paths":{"/lab_results/attachment_url":{"get":{"summary":"Get pre-signed URL for a lab result file","description":"Returns a pre-signed S3 URL (fileUrl) for a single lab result attachment so the file can be viewed or downloaded. The client must supply the S3 path of the file (e.g. from the lab result's attachments). Requires JWT.","tags":["Lab Results"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"query","name":"s3_path","required":true,"schema":{"type":"string","description":"S3 object key/path of the lab result attachment (e.g. userId/lab_results/labResultId/attachments/fileName)"},"description":"The S3 path of the file to retrieve"}],"responses":{"200":{"description":"Pre-signed URL returned successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":true},"fileUrl":{"type":"string","description":"Pre-signed URL for viewing/downloading the file"}}}}}},"400":{"description":"Bad request (e.g. missing s3_path)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string","example":"No s3 path given."}}}}}}}}},"/lab_results":{"get":{"summary":"List lab results","description":"Returns a list of lab results for the authenticated user. Access is scoped by role—providers see their own and their clients' results; plain users see only their own and only results where isViewableToClient is not false. Only non-deleted results are returned. Supports filtering by lab, date range, and optional attachment population. Requires JWT.","tags":["Lab Results"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"query","name":"lab","schema":{"type":"string","description":"Lab ID to filter results"}},{"in":"query","name":"startDate","schema":{"type":"string","format":"date"},"description":"Start of date range for result date"},{"in":"query","name":"endDate","schema":{"type":"string","format":"date"},"description":"End of date range for result date"},{"in":"query","name":"limit","schema":{"type":"string","default":"100"},"description":"Max number of results (default 100)"},{"in":"query","name":"basic","schema":{"type":"boolean"},"description":"If set, minimal population (no user/lab details)"},{"in":"query","name":"showAttachments","schema":{"type":"boolean"},"description":"If set, include attachment details in response"},{"in":"query","name":"sortProperty","schema":{"type":"string","default":"name"}},{"in":"query","name":"sortAscending","schema":{"type":"string","example":"false"}}],"responses":{"200":{"description":"List of lab results (fields may vary by query; e.g. name, lab, date, attachments, results, status, user)","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"_id":{"type":"string"},"name":{"type":"string"},"lab":{"type":"object"},"date":{"type":"string","format":"date-time"},"attachments":{"type":"array","items":{"type":"object"}},"results":{"type":"array"},"status":{"type":"string"},"isViewableToClient":{"type":"boolean"},"user":{"type":"object"}}}}}}},"400":{"description":"Bad request (e.g. provider not in client list)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}}}}},"/notes/attachment_urls":{"get":{"summary":"Get pre-signed URLs for note attachments","description":"Returns attachment metadata with pre-signed S3 URLs (fileUrl) for a note so attachments can be viewed or downloaded. Requires JWT.","tags":["Notes"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"query","name":"note_id","required":true,"schema":{"type":"string","description":"Note ID (MongoDB ObjectId)"},"description":"The note whose attachment URLs to retrieve"}],"responses":{"200":{"description":"Pre-signed attachment URLs returned successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":true},"attachments":{"type":"array","items":{"type":"object","properties":{"_id":{"type":"string","description":"Attachment ID"},"name":{"type":"string","description":"Attachment file name"},"src":{"type":"string","description":"S3 object key/path"},"fileUrl":{"type":"string","description":"Pre-signed URL for viewing/downloading"}}}}}}}}},"400":{"description":"Bad request (e.g. missing note_id)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string","example":"No note id given."}}}}}}}}},"/notes":{"post":{"summary":"Create a new note","description":"Creates a new note for a client. Request must be multipart/form-data. Providers can create notes for any client; clients can create notes only for themselves. Optional file uploads are stored as attachments. Requires JWT.\n**Try it out:** (1) Use the Authorization parameter below and set it to \"Bearer YOUR_JWT\" so the token is sent with multipart. (2) Leave resources, attachments, and signature with their example values (valid JSON strings); empty values will cause 400.\n","tags":["Notes"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"header","name":"Authorization","required":false,"schema":{"type":"string","example":"Bearer YOUR_JWT_TOKEN"},"description":"Bearer JWT (required for Try it out; Swagger does not send Authorize token with multipart.)"}],"requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["client"],"properties":{"client":{"type":"string","description":"Client user ID (MongoDB ObjectId) the note belongs to","example":"5c18b6ddfee2ce57187a53be"},"name":{"type":"string","description":"Note title/name","example":"test title"},"notes":{"type":"string","description":"Note message body (can be HTML)","example":"<p>test body</p>"},"visableToClient":{"type":"string","enum":["true","false"],"description":"Whether the client can see this note","example":"true"},"visibleToPractitioner":{"type":"string","enum":["true","false"],"description":"Whether practitioners can see this note","example":"true"},"resources":{"type":"string","description":"Must be a valid JSON string (e.g. []). Empty string causes 400.","example":"[]"},"attachments":{"type":"string","description":"Must be a valid JSON string (e.g. []). Empty string causes 400.","example":"[]"},"signature":{"type":"string","description":"Must be a valid JSON object string (e.g. enabled flag).","example":"{\"enabled\":false}"},"isDraft":{"type":"string","enum":["true","false"],"description":"If true, note is saved as draft","example":"false"},"file":{"type":"string","format":"binary","description":"Optional attachment file(s). Omit this part when not uploading files; do not send an empty file part."}}}}}},"responses":{"200":{"description":"Note created successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":true},"result":{"type":"object","description":"The created note document"}}}}}},"400":{"description":"Bad request (empty body, no client, client not in list, etc.)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}},"403":{"description":"Access restricted (e.g. client creating note for another user)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}}}},"get":{"summary":"List notes (view notes and messages)","description":"Returns a list of notes for the authenticated user. Notes include message content, attachments (with pre-signed fileUrl), resources (with fileUrl for file type), responses, and populated user/lastResponder/signature. Access is scoped by role (provider or client). Requires JWT.","tags":["Notes"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"query","name":"user","schema":{"type":"string","description":"User/client ID to filter notes (used by providers, ignored for clients)"}},{"in":"query","name":"limit","schema":{"type":"string","default":"100"},"description":"Max number of notes to return (optional)"},{"in":"query","name":"sortProperty","schema":{"type":"string","default":"createdAt"}},{"in":"query","name":"sortAscending","schema":{"type":"string","example":"false"}}],"responses":{"200":{"description":"List of notes with attachment and resource file URLs","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","description":"Note with attachments[].fileUrl and resources[].fileUrl for viewing files","properties":{"_id":{"type":"string"},"name":{"type":"string"},"notes":{"type":"string","description":"Note message body"},"attachments":{"type":"array","items":{"type":"object","properties":{"_id":{"type":"string"},"name":{"type":"string"},"src":{"type":"string"},"fileUrl":{"type":"string","description":"Pre-signed URL for viewing attachment"}}}},"resources":{"type":"array"},"responses":{"type":"array"},"user":{"type":"object"},"lastResponder":{"type":"object"},"signature":{"type":"object"}}}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}}}}},"/notes/{id}":{"get":{"summary":"Get a single note by ID (view note/message and resources)","description":"Returns one note by ID with populated resources, responses, and signature. File-type resources include pre-signed fileUrl. For attachment file URLs use GET /notes/attachment_urls?note_id={id}. Access is restricted by role (provider or client). Requires JWT.","tags":["Notes"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"},"description":"Note ID (MongoDB ObjectId)"},{"in":"query","name":"populate","schema":{"type":"string","enum":["user"]},"description":"Set to 'user' to populate note user"}],"responses":{"200":{"description":"Note found and returned","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":true},"result":{"type":"object","description":"Full note with resources[].fileUrl for file-type resources","properties":{"_id":{"type":"string"},"name":{"type":"string"},"notes":{"type":"string"},"attachments":{"type":"array","items":{"type":"object","properties":{"_id":{"type":"string"},"name":{"type":"string"},"src":{"type":"string"}}}},"resources":{"type":"array","items":{"type":"object","properties":{"url":{"type":"string"},"fileUrl":{"type":"string","description":"Pre-signed URL (for type file)"},"type":{"type":"string"}}}},"responses":{"type":"array"},"signature":{"type":"object"},"user":{"type":"object"},"client":{"type":"string"}}}}}}}},"400":{"description":"Bad request (e.g. no id, note not found)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}},"403":{"description":"Access restricted to practitioners only","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}}}}},"/notes/{id}/responses":{"post":{"summary":"Reply to an existing note","description":"Adds a new response (reply) to a note. Can be saved as draft (isDraft true) or published. Optionally updates note resources. May trigger emails and timeline events when published. Requires JWT.","tags":["Notes"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"},"description":"Note ID (MongoDB ObjectId) to reply to"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"responseBody":{"type":"string","description":"The reply message content"},"respondent":{"type":"string","description":"User ID of the respondent (defaults to authenticated user)"},"isDraft":{"type":"boolean","description":"If true, reply is saved as draft and no notifications sent"},"isAutoSave":{"type":"boolean","description":"If true, treated as autosave (no notifications)"},"resources":{"type":"array","description":"Optional array of resource references to attach to the note"}}}}}},"responses":{"200":{"description":"Reply created successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":true},"result":{"type":"object","description":"Updated note (with new response in responses array)"},"responseId":{"type":"string","description":"ID of the newly added response"}}}}}},"400":{"description":"Bad request (note not found, no added response id, etc.)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}}}}},"/trackers":{"get":{"summary":"List trackers","description":"Returns a list of trackers. Access is scoped by role—providers see their own and their clients' trackers; regular users see only their own. Non-deleted trackers are returned, sorted alphabetically by name. Optional filter by trackerType. When query.user is specified, full tracker details are returned (excluding reminder); otherwise list fields name, user, updatedAt, metricType, wearablesId with user (nameFirst, nameLast, gender) and wearablesId populated. Requires JWT.","tags":["Trackers"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"query","name":"user","schema":{"type":"string","description":"User ID to filter trackers (providers only)"}},{"in":"query","name":"trackerType","schema":{"type":"string","description":"Filter by tracker type (e.g. standard, session, oura, lab)"}},{"in":"query","name":"limit","schema":{"type":"string","default":"100"},"description":"Max number of results (default 100)"}],"responses":{"200":{"description":"List of trackers returned successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":true},"result":{"type":"array","items":{"$ref":"#/components/schemas/Tracker"}}}}}}},"400":{"description":"Bad request or failed to fetch trackers","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}}}},"post":{"summary":"Create a tracker","description":"Creates a new tracker for a user. Providers can create for themselves or their clients; regular users can create only for themselves (user is set from JWT). Request body should be a full tracker object. Supports standard, session, lab, and other tracker types. On success the created tracker is returned and linked to the user. Requires JWT.","tags":["Trackers"],"security":[{"bearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Display name of the tracker"},"user":{"type":"string","description":"User ID (required for provider; ignored for regular users)"},"trackerType":{"type":"string","default":"standard","description":"Type of tracker (e.g. standard, session, lab, oura)"},"metricType":{"type":"string","description":"Unit or metric being measured (e.g. lbs, inches)"},"startDate":{"type":"string","format":"date-time"},"endDate":{"type":"string","format":"date-time"},"minValue":{"type":"number"},"maxValue":{"type":"number"},"active":{"type":"boolean","default":false},"graphEntity":{"type":"string","description":"Reference ID for lab/entity (e.g. lab ID for lab trackers)"},"graphEntityType":{"type":"string","description":"Entity type (e.g. Lab)"}}}}}},"responses":{"200":{"description":"Tracker created successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":true},"result":{"$ref":"#/components/schemas/Tracker"}}}}}},"400":{"description":"Bad request (e.g. empty body or validation error)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}},"403":{"description":"Forbidden (e.g. provider creating for a user not in client list)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string"}}}}}},"500":{"description":"Audit or server error"}}}},"/trackers/{id}":{"get":{"summary":"Get a single tracker","description":"Returns one tracker by ID. Access is scoped by role—providers can view their own and their clients' trackers; regular users can view only their own. The tracker is returned with wearablesId populated. Requires JWT.","tags":["Trackers"],"security":[{"bearerAuth":[]}],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string","description":"Tracker ID (MongoDB ObjectId)"}}],"responses":{"200":{"description":"Tracker returned successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Tracker"}}}},"400":{"description":"Bad request (e.g. missing id or tracker not found)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"error":{"type":"string","example":"Tracker not found or does not exist."}}}}}}}}},"/users/authorize":{"post":{"summary":"Authenticate user with email and password","description":"Authenticates a user with their email and password credentials. Returns a JWT token and user information upon successful authentication.","tags":["Authentication"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["email","password"],"properties":{"email":{"type":"string","format":"email","description":"User's email address","example":"user@example.com"},"password":{"type":"string","format":"password","description":"User's password or magic link token","example":"password123"},"licenseCheck":{"type":"boolean","description":"Whether to perform license check for providers","example":false}}}}}},"responses":{"200":{"description":"Successful authentication","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"boolean","example":true},"token":{"type":"string","description":"JWT authentication token","example":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."},"phoneNumberVerified":{"type":"boolean","example":true},"country":{"type":"string","example":"US"},"requiresPasswordUpdate":{"type":"boolean","example":false},"isProvider":{"type":"boolean","example":false},"isAdmin":{"type":"boolean","example":false},"isTechSupportAdmin":{"type":"boolean","example":false},"isOrgAdmin":{"type":"boolean","example":false},"orgId":{"type":"string","example":"507f1f77bcf86cd799439011"},"subdomain":{"type":"string","nullable":true,"example":"example"},"practitionerTosAccepted":{"type":"boolean","example":true},"clientTosAccepted":{"type":"boolean","example":true},"clients":{"type":"array","items":{"type":"string"},"example":[]},"id":{"type":"string","description":"User ID","example":"507f1f77bcf86cd799439011"},"nameFirst":{"type":"string","example":"John"},"nameLast":{"type":"string","example":"Doe"},"fbId":{"type":"string","nullable":true,"example":null},"tosId":{"type":"string","example":"507f1f77bcf86cd799439011"},"isLicensed":{"type":"boolean","example":true},"isRegulated":{"type":"boolean","example":false},"doseSpotClinicId":{"type":"string","nullable":true,"example":null},"doseSpotClinicianId":{"type":"string","nullable":true,"example":null},"doseSpotClinicKey":{"type":"string","nullable":true,"example":null},"userType":{"type":"string","example":"client"},"isClinicAdmin":{"type":"boolean","example":false},"clinicAdmins":{"type":"array","items":{"type":"string"},"example":[]},"clinicIds":{"type":"array","items":{"type":"string"},"example":[]},"features":{"type":"array","items":{"type":"string"},"description":"User's feature list from subscription plans","example":[]}}}}}},"400":{"description":"Authentication failed","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"boolean","example":false},"success":{"type":"boolean","example":false},"message":{"type":"string","example":"Authentication failed. Please ensure you type in your email and password."}}},"examples":{"missingCredentials":{"value":{"status":false,"message":"Authentication failed. Please ensure you type in your email and password."}},"userNotFound":{"value":{"success":false,"message":"Authentication failed. User not found or wrong password."}},"wrongPassword":{"value":{"success":false,"message":"Authentication failed. Please ensure your email and password are correct."}},"userDisabled":{"value":{"success":false,"message":"User has been disabled. Please contact administration."}}}}}},"503":{"description":"Service unavailable (maintenance mode)","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","example":false},"message":{"type":"string","example":"Biocanic is currently down for maintenance."}}}}}}}}}},"tags":[]}