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
| Header | Type | Required | Description |
|---|---|---|---|
Authorization | string | Yes | Bearer token: Bearer <token> |
Content-Type | string | Yes | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | Workspace 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
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Session name (minimum 1 character) |
clientId | string | Yes | Client ID for the session |
serviceIds | array[string] | Yes | Array of service IDs (minimum 1 service required). All services must have scope: "sessions" |
staffId | string | No | Responsible staff member ID (optional) |
date | string | Yes | Session date in ISO 8601 datetime format |
startTime | string | Yes | Session start time in HH:mm format (24-hour) |
durationMinutes | number | No | Session duration in minutes. If not provided, will be calculated automatically from selected services' durations |
status | string | No | Session status. Valid values: scheduled, in-progress, completed, cancelled (default: scheduled) |
fieldValues | array | No | Array of custom field values (for pre-session phase) |
Duration Calculation:
- If
durationMinutesis not provided, the system automatically calculates it as the sum of all selected services'durationMinutes - If a service doesn't have a
durationMinutesvalue, 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
durationMinutesin 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