createSession( )
Creates a session.
Description
The createSession()
function returns a Promise that resolves when a session is created.
A session is one of the following:
"EVENT"
: Reserved period of time on any schedule. For example, an appointment, class, or course. Events are visible in the Dashboard in the Bookings app's Booking Calendar page. Settype
to"EVENT"
when creating sessions that reserve time on a service's schedule, or when creating a blocked time for a resource."WORKING_HOURS"
: Placeholder for available time on a resource’s schedule. Settype
to"WORKING_HOURS"
when creating sessions for resource availability.
Sessions belong to a schedule. Schedules are owned by a resource or a service.
A session may be an individual session or a recurring session.
An individual session has a discrete start and end date, while a recurring session defines a series of repeating sessions. An instance of a recurring session is a specific session in a series of repeating sessions, generated according to the recurrence rule.
The start
and end
properties set the time and duration of the session. For non-recurring sessions, you can use either the timestamp
or localDateTime
properties.
For recurring sessions, use the localDateTime
property only. For recurring sessions, the start
property sets the date and time of the first recurring session, subject to the recurrence rule. For example, if you set the start
to Saturday, May 1 and your recurrence rule says every second Monday, then the first session will only be on Monday, May 10.
The year
, monthOfYear
and dayOfMonth
properties in the end
property are used with the hourOfDay
and minutesOfHour
properties to set the duration of each session relative to the start
.
The UNTIL
keyword in the recurrence
property sets the date for the last recurring session.
You can create a session that blocks hours on the resource's calendar, making the resource unavailable.
Create a non-recurring session of type "EVENT"
, and add "Blocked"
to the tags
array.
Notes:
- For properties where there is no explicit timezone information, the timezone used is the business’s timezone.
- Only users with Bookings Admin permissions can create a session. You can override the permissions by setting the
suppressAuth
option totrue
.
Syntax
function createSession(sessionInfo: SessionInfo, [options: Options]): Promise<Session>
createSession Parameters
NAME
TYPE
DESCRIPTION
Information to use when creating a session..
An object representing the available options for creating a session.
Returns
Fulfilled - Session.
Return Type:
NAME
TYPE
DESCRIPTION
Session ID.
ID of the schedule that the session belongs to.
ID of the resource or service that the session's schedule belongs to.
Tags for the session. The value is inherited from the schedule and can be overridden unless the session is a recurring session.
Additional information about the session. Notes are not supported for recurring sessions.
Session status.
One of:
"CONFIRMED"
Default value."CANCELLED"
The session was deleted.
ID of the recurring session if this session is an instance of a recurrence. Use this ID to update the recurrence and all of the instances.
Session type.
One of:
"EVENT"
Reserved period of time on the schedule. For example, an appointment, class, course, or blocked time. Events are visible in the Dashboard in the Bookings app's Booking Calendar page."WORKING_HOURS"
Placeholder for available time on a resource’s schedule.
String representing a recurrence rule (RRULE) for a recurring session, as defined in iCalendar RFC 5545.
If the session is an instance of a recurrence pattern, the instanceOfRecurrence
property will contain the recurrence rule and this property will be empty.
The RRULE defines a rule for repeating a session.
Supported parameters are:
Keyword | Description | Supported values |
---|---|---|
FREQ | The frequency at which the session is recurs. Required. | WEEKLY |
INTERVAL | How often, in terms of FREQ , the session recurs. Default is 1. Optional. | |
UNTIL | The UTC end date and time of the recurrence. Optional. | |
BYDAY | Day of the week when the event should recur. Required. | One of: MO , TU , WE , TH , FR , SA , SU |
For example, a session that repeats every second week on a Monday until January 7, 2022 at 8 AM:
"FREQ=WEEKLY;INTERVAL=2;BYDAY=MO;UNTIL=20220107T080000Z"
String representing a recurrence rule (RRULE) if the session is an instance of a recurrence pattern.
Empty when the session is not an instance of a recurrence rule, or if the session defines a recurrence pattern, and recurrence
is not empty.
An object specifying the start date and time of the session. If the session is a recurring session, start
must contain a localDateTime
.
An object specifying the end date and time of the session. If the session is a recurring session, end
must contain a localDateTime
.
Was this helpful?
1import { Permissions, webMethod } from "wix-web-module";2import { sessions } from "wix-bookings-backend";34export const createNonRecurringSessions = webMethod(Permissions.Anyone, (scheduleId) => {5 const sessionInfo = {6 scheduleId,7 start: {8 timestamp: new Date("2021-02-15T12:00:00.000-07:00"),9 },10 end: {11 timestamp: new Date("2021-02-15T13:00:00.000-07:00"),12 },13 type: "WORKING_HOURS",14 };1516 const options = { suppressAuth: true };1718 return sessions19 .createSession(sessionInfo, options)20 .then((session) => {21 return session;22 })23 .catch((error) => {24 console.error("Failed to create session:", error);25 });26});2728/* Returns a Promise that resolves to a session object:29 * {30 * "_id": "2mmoW0vwKcSFyxtOfCdMhHQCHOQ1j8BjlhonXsthFhhClxedYCD7W67Dzj8Gcsw0EBU60ml88FFboL9qt39lLftLn3tcMtFZoPu9",31 * "notes": "",32 * "scheduleId": "aec380c0-ca2c-43c2-98f4-9aebbd3276f3",33 * "scheduleOwnerId": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae",34 * "start": {35 * "timestamp": "2021-02-15T19:00:00.000Z"36 * },37 * "end": {38 * "timestamp": "2021-02-15T20:00:00.000Z"39 * },40 * "status": "CONFIRMED",41 * "tags": [],42 * "type": "WORKING_HOURS"43 * }44 */
12import { Permissions, webMethod } from "wix-web-module";3import { sessions } from "wix-bookings-backend";45export const createRecurringSessions = webMethod(Permissions.Anyone, (scheduleId) => {6 const recurringSession = {7 scheduleId,8 start: {9 localDateTime: {10 year: 2021,11 monthOfYear: 3,12 dayOfMonth: 1,13 hourOfDay: 9,14 minutesOfHour: 0,15 },16 },17 end: {18 localDateTime: {19 year: 2021,20 monthOfYear: 3,21 dayOfMonth: 1,22 hourOfDay: 17,23 minutesOfHour: 0,24 },25 },26 type: "WORKING_HOURS",27 recurrence: "FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z",28 };29 const options = { suppressAuth: true };3031 return sessions32 .createSession(recurringSession, options)33 .then((session) => {34 return session;35 })36 .catch((error) => {37 console.error("Failed to create session:", error);38 });39});4041/* Returns a Promise that resolves to a session object:42 * {43 * "_id": "aec380c0ca2c43c298f49aebbd3276f3-10c6d84adc9247e7b9cd17e12b01addc",44 * "notes": "",45 * "recurrence": "FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z",46 * "scheduleId": "aec380c0-ca2c-43c2-98f4-9aebbd3276f3",47 * "scheduleOwnerId": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae",48 * "start": {49 * "localDateTime": {50 * "year": 2021,51 * "monthOfYear": 3,52 * "dayOfMonth": 1,53 * "hourOfDay": 9,54 * "minutesOfHour": 055 * }56 * },57 * "end": {58 * "localDateTime": {59 * "year": 2021,60 * "monthOfYear": 3,61 * "dayOfMonth": 1,62 * "hourOfDay": 17,63 * "minutesOfHour": 064 * }65 * },66 * "status": "CONFIRMED",67 * "tags": [],68 * "type": "WORKING_HOURS"69 * }70 */71