Skip to main content

Create Lab Visit (v1)

Method & Path

POST /api/v1/workspace/:workspaceId/labs/visits

Actual backend path: /v1/workspace/:workspaceId/labs/visits

Description

Create a new lab visit for a client and attach one or more lab tests.

Authentication

Required: JWT token in Authorization header

Persona Access:

  • Admin: Not applicable (workspace-scoped endpoint)
  • Workspace Owner: Allowed
  • Staff: Allowed (role-based)
  • Customer: Not allowed

Required Permissions:

  • labs.run

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token: Bearer <token>
Content-TypestringYesapplication/json

Path Parameters

ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier (MongoDB ObjectId)

Request Body

{
"clientId": "507f1f77bcf86cd799439013",
"referralId": "507f1f77bcf86cd799439099",
"labVisitType": "in-lab",
"labTestIds": [101, 205],
"labVisitDate": "2026-01-10T12:00:00.000Z",
"labVisitNotes": "Priority visit",
"labCouponCode": "WINTER10",
"labVisitSubtotal": null
}
FieldTypeRequiredDescription
clientIdstringYesClient identifier (MongoDB ObjectId)
referralIdstring | nullNoReferral identifier (MongoDB ObjectId). When provided, must belong to the same workspace
labVisitTypestringYesin-lab or at-home
labTestIdsnumber[]YesArray of test IDs (numeric)
labVisitDatestringYesISO datetime
labVisitNotesstringNoNotes (max 2000 chars)
labCouponCodestring | nullNoCoupon code to apply
labVisitSubtotalnumber | nullNoOptional subtotal. If omitted/null, backend calculates subtotal from test prices

Response 201 Created

{
"labVisit": {
"id": "507f1f77bcf86cd799439011",
"workspaceId": "507f1f77bcf86cd799439012",
"clientId": "507f1f77bcf86cd799439013",
"referralId": "507f1f77bcf86cd799439099",
"labVisitType": "in-lab",
"labVisitStatus": "pending",
"labTestIds": [101, 205],
"labTestSnapshots": [
{
"test": { "testId": 101, "testTitle": "CBC" },
"designTest": null
},
{
"test": { "testId": 205, "testTitle": "CRP" },
"designTest": null
}
],
"labTestResults": [],
"labVisitDate": "2026-01-10T12:00:00.000Z",
"labVisitNotes": "Priority visit",
"labVisitPricing": {
"labVisitSubtotal": 100,
"labCouponId": "507f1f77bcf86cd799439055",
"labCouponCode": "WINTER10",
"labVisitDiscountAmount": 10,
"labVisitTotal": 90
},
"deletedAt": null,
"createdAt": "2026-01-10T12:00:00.000Z",
"updatedAt": "2026-01-10T12:00:00.000Z"
}
}

Common Errors

400 Bad Request: Invalid request body or missing required fields

401 Unauthorized: Missing or invalid authentication token

403 Forbidden: Insufficient permissions (labs.run required)

404 Not Found: Workspace or client not found

422 Validation Error: Invalid IDs or validation errors (e.g., missing tests, invalid coupon)