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 { Permissions, webMethod } from "wix-web-module";
2import { sessions } from "wix-bookings-backend";
3
4export 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 };
15
16 const options = { suppressAuth: true };
17
18 return sessions
19 .createSession(sessionInfo, options)
20 .then((session) => {
21 return session;
22 })
23 .catch((error) => {
24 console.error("Failed to create session:", error);
25 });
26});
27
28/* 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 */
Create a recurring session for a resource.

Copy Code
1
2import { Permissions, webMethod } from "wix-web-module";
3import { sessions } from "wix-bookings-backend";
4
5export 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 };
30
31 return sessions
32 .createSession(recurringSession, options)
33 .then((session) => {
34 return session;
35 })
36 .catch((error) => {
37 console.error("Failed to create session:", error);
38 });
39});
40
41/* 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": 0
55 * }
56 * },
57 * "end": {
58 * "localDateTime": {
59 * "year": 2021,
60 * "monthOfYear": 3,
61 * "dayOfMonth": 1,
62 * "hourOfDay": 17,
63 * "minutesOfHour": 0
64 * }
65 * },
66 * "status": "CONFIRMED",
67 * "tags": [],
68 * "type": "WORKING_HOURS"
69 * }
70 */
71