Search.../

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. Set type 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. Set type 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 to true.

Syntax

function createSession(sessionInfo: SessionInfo, [options: Options]): Promise<Session>

createSession Parameters

NAME
TYPE
DESCRIPTION
sessionInfo
SessionInfo

Information to use when creating a session..

options
Optional
Options

An object representing the available options for creating a session.

Returns

Fulfilled - Session.

Return Type:

Promise<Session>
NAME
TYPE
DESCRIPTION
_id
string

Session ID.

scheduleId
string

ID of the schedule that the session belongs to.

scheduleOwnerId
string

ID of the resource or service that the session's schedule belongs to.

tags
Array<string>

Tags for the session. The value is inherited from the schedule and can be overridden unless the session is a recurring session.

notes
string

Additional information about the session. Notes are not supported for recurring sessions.

status
string

Session status.

One of:

  • "CONFIRMED" Default value.
  • "CANCELLED" The session was deleted.
recurringSessionId
string

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.

type
string

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.
recurrence
string

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:

KeywordDescriptionSupported values
FREQThe frequency at which the session is recurs. Required.WEEKLY
INTERVALHow often, in terms of FREQ, the session recurs. Default is 1. Optional.
UNTILThe UTC end date and time of the recurrence. Optional.
BYDAYDay 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"

instanceOfRecurrence
string

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.

start
CalendarDateTime

An object specifying the start date and time of the session. If the session is a recurring session, start must contain a localDateTime.

end
CalendarDateTime

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?

Create a session.

Copy Code
1import { sessions } from "wix-bookings-backend";
2
3export function createNonRecurringSessions(scheduleId) {
4 const sessionInfo = {
5 scheduleId,
6 start: {
7 timestamp: new Date("2021-02-15T12:00:00.000-07:00")
8 },
9 end: {
10 timestamp: new Date("2021-02-15T13:00:00.000-07:00")
11 },
12 type: "WORKING_HOURS"
13 };
14
15 const options = { suppressAuth: true };
16
17 return sessions.createSession(sessionInfo, options)
18 .then((session) => {
19 return session;
20 })
21 .catch((error) => {
22 console.error('Failed to create session:', error);
23 });
24}
25
26 /* Returns a Promise that resolves to a session object:
27 * {
28 * "_id": "2mmoW0vwKcSFyxtOfCdMhHQCHOQ1j8BjlhonXsthFhhClxedYCD7W67Dzj8Gcsw0EBU60ml88FFboL9qt39lLftLn3tcMtFZoPu9",
29 * "notes": "",
30 * "scheduleId": "aec380c0-ca2c-43c2-98f4-9aebbd3276f3",
31 * "scheduleOwnerId": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae",
32 * "start": {
33 * "timestamp": "2021-02-15T19:00:00.000Z"
34 * },
35 * "end": {
36 * "timestamp": "2021-02-15T20:00:00.000Z"
37 * },
38 * "status": "CONFIRMED",
39 * "tags": [],
40 * "type": "WORKING_HOURS"
41 * }
42 */
Create a recurring session for a resource.

Copy Code
1import { sessions } from "wix-bookings-backend";
2
3export function createRecurringSessions(scheduleId) {
4 const recurringSession = {
5 scheduleId,
6 start: {
7 localDateTime: {
8 year: 2021,
9 monthOfYear: 3,
10 dayOfMonth: 1,
11 hourOfDay: 9,
12 minutesOfHour: 0
13 }
14 },
15 end: {
16 localDateTime: {
17 year: 2021,
18 monthOfYear: 3,
19 dayOfMonth: 1,
20 hourOfDay: 17,
21 minutesOfHour: 0
22 }
23 },
24 type: 'WORKING_HOURS',
25 recurrence: 'FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z'
26 };
27 const options = { suppressAuth: true };
28
29 return sessions.createSession(recurringSession, options)
30 .then((session) => {
31 return session;
32 })
33 .catch((error) => {
34 console.error('Failed to create session:', error);
35 });
36}
37
38 /* Returns a Promise that resolves to a session object:
39 * {
40 * "_id": "aec380c0ca2c43c298f49aebbd3276f3-10c6d84adc9247e7b9cd17e12b01addc",
41 * "notes": "",
42 * "recurrence": "FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z",
43 * "scheduleId": "aec380c0-ca2c-43c2-98f4-9aebbd3276f3",
44 * "scheduleOwnerId": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae",
45 * "start": {
46 * "localDateTime": {
47 * "year": 2021,
48 * "monthOfYear": 3,
49 * "dayOfMonth": 1,
50 * "hourOfDay": 9,
51 * "minutesOfHour": 0
52 * }
53 * },
54 * "end": {
55 * "localDateTime": {
56 * "year": 2021,
57 * "monthOfYear": 3,
58 * "dayOfMonth": 1,
59 * "hourOfDay": 17,
60 * "minutesOfHour": 0
61 * }
62 * },
63 * "status": "CONFIRMED",
64 * "tags": [],
65 * "type": "WORKING_HOURS"
66 * }
67 */