Skip to main content

Create Session (v1)

Method + Path

POST /v1/workspace/:workspaceId/sessions

Actual backend path: /v1/workspace/:workspaceId/sessions

Description

Create a new session (appointment) in a workspace. Sessions can be assigned multiple services, and the duration will be automatically calculated from the sum of selected services' durations (unless manually overridden).

Authentication

Required - JWT token in Authorization header

Required Permissions:

  • sessions.create

Headers

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

Path Parameters

ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier

Request Body

{
"name": "Consultation Session",
"clientId": "507f1f77bcf86cd799439012",
"serviceIds": ["507f1f77bcf86cd799439013", "507f1f77bcf86cd799439014"],
"staffId": "507f1f77bcf86cd799439015",
"date": "2024-01-20T10:00:00Z",
"startTime": "10:00",
"durationMinutes": 90,
"status": "scheduled",
"fieldValues": [
{
"fieldKey": "session-type",
"value": "consultation",
"phase": "pre"
}
]
}

Body Parameters

ParameterTypeRequiredDescription
namestringYesSession name (minimum 1 character)
clientIdstringYesClient ID for the session
serviceIdsarray[string]YesArray of service IDs (minimum 1 service required). All services must have scope: "sessions"
staffIdstringNoResponsible staff member ID (optional)
datestringYesSession date in ISO 8601 datetime format
startTimestringYesSession start time in HH:mm format (24-hour)
durationMinutesnumberNoSession duration in minutes. If not provided, will be calculated automatically from selected services' durations
statusstringNoSession status. Valid values: scheduled, in-progress, completed, cancelled (default: scheduled)
fieldValuesarrayNoArray of custom field values (for pre-session phase)

Duration Calculation:

  • If durationMinutes is not provided, the system automatically calculates it as the sum of all selected services' durationMinutes
  • If a service doesn't have a durationMinutes value, it contributes 0 to the calculation
  • If the calculated duration is 0 or less, it defaults to 60 minutes
  • You can manually override the calculated duration by providing durationMinutes in the request

Response (201)

{
"session": {
"id": "507f1f77bcf86cd799439011",
"workspaceId": "507f191e810c19729de860ea",
"clientId": "507f1f77bcf86cd799439012",
"clientName": "John Doe",
"serviceIds": ["507f1f77bcf86cd799439013", "507f1f77bcf86cd799439014"],
"serviceNames": ["استشارة طبية", "فحص عام"],
"staffId": "507f1f77bcf86cd799439015",
"staffName": "Dr. Smith",
"name": "Consultation Session",
"date": "2024-01-20T00:00:00.000Z",
"startTime": "10:00",
"endTime": "11:30",
"durationMinutes": 90,
"status": "scheduled",
"fieldValues": [],
"attachments": [],
"notes": [],
"invoice": null,
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-01-15T10:00:00.000Z"
}
}

Common Errors

  • 400 Bad Request: Invalid request body or validation errors (e.g., at least one service is required, invalid date/time format)
  • 401 Unauthorized: Missing or invalid authentication token
  • 403 Forbidden: Insufficient permissions (requires sessions.create)
  • 404 Not Found: Workspace, client, or service(s) not found
  • 422 Unprocessable Entity: Validation errors
  • 500 Internal Server Error: Server error