Search.../

querySessions( )

Retrieves a list of the sessions according to the specified filters and paging.

Description

The querySessions() function builds a query to retrieve a list of sessions, and returns a SessionQueryBuilder object. The returned object contains the query definition, which is typically used to run the query using the find() function.

The SessionQueryBuilder functions enable you to run, filter, and control which results a query returns.

Typically, you build a query using the session query function, refine the query by chaining SessionQueryBuilder functions, and then execute the query by chaining the find() function.

The query must include the following SessionQueryBuilder functions:

  • ge("end.timestamp", "<timestamp value>")
  • lt("start.timestamp", "<timestamp value>")

Use start and end to set the range of dates you want to return in your session query. Use ge("end.timestamp", "<timestamp value>") to set the lower limit of your query range as greater or equal to the end date of the earliest session, and lt("start.timestamp", "<timestamp value>") to set the upper limit as less than the start date of the latest session. Sessions that are partially within the requested date range will be included in the returned sessions.

query

The query runs with the following SessionQueryBuilder defaults that you can override:

By default, recurring sessions, sessions that define recurrence patterns, are not returned in the query. Only instances of the recurring sessions are returned. To query recurring sessions, use .ne("recurrence",null) and .eq("scheduleId", "<value>"). While instances of recurring sessions can be queried for all schedules, recurring sessions can only be queried for a specified schedule ID.

The following query builder filters are supported for querySessions().

PropertySupported Filters                                                           
scheduleIdeq(),hasSome()
endge()
startlt()
tagseq(), hasSome()
typeeq(), hasSome()
recurrencene()

For a full description of the Session object, see the object returned for the items property in SessionQueryResult.

Notes:

  • If timestamp not specified when creating a session, it is calculated as the UTC date and time using localDateTime and the business's timezone.
  • Sessions that occur as a result of a linked schedule are not returned in a session query. For example, WORKING_HOURS sessions for a resource that has the default business hours in its linkedSchedules array, will not be returned in a query.
  • Only users with Bookings Admin permissions can view participant information in a session query. You can override the permissions by setting the suppressAuth options to true.

Syntax

function querySessions(): SessionQueryBuilder

querySessions Parameters

This function does not take any parameters.

Returns

A SessionQueryBuilder object representing the refined query.

Was this helpful?

Create a query, add filters, and run it

Copy Code
1import { sessions } from "wix-bookings-backend";
2
3// ...
4
5return sessions.querySessions()
6 .eq("scheduleId", "9299760d-8a4a-4f89-b348-1fc611f4be17")
7 .ge("end.timestamp","2020-01-01T08:00:00.000Z")
8 .lt("start.timestamp", "2021-06-01T08:00:00.000Z")
9 .limit(5)
10 .find({suppressAuth:true})
11 .then((results) => {
12 if (results.items.length > 0) {
13 const items = results.items;
14 const firstItem = items[0];
15 const totalCount = results.totalCount;
16 const pageSize = results.pageSize;
17 const currentPage = results.currentPage;
18 const totalPages = results.totalPages;
19 const hasNext = results.hasNext();
20 const hasPrev = results.hasPrev();
21 const length = results.length;
22 const query = results.query;
23 return results.items;
24 } else {
25 // handle case where no matching items found
26 }
27 })
28 .catch((error) => {
29 console.error(error);
30 });
31
32 /* Returns a Promise that resolves to an array of sessions.
33 *
34 * [
35 * {
36 * "end": {
37 * "localDateTime": {
38 * "year": 2020,
39 * "monthOfYear": 12,
40 * "dayOfMonth": 31,
41 * "hourOfDay": 18,
42 * "minutesOfHour": 0
43 * },
44 * "timestamp": "2020-12-31T16:00:00.000Z"
45 * },
46 * "_id": "4jOkD28c0FrsNUSgzQzuLRkA2t1rv1FLTwquKmJyctoZm00vdeKFMyH4n9cCLtmQe8wvOVwmsJCUCPWT3LA2geDOBViOg62YOeTG
47 * cgvAnGyw6uKEiNVqqdHt8QVz4i7qMZu5irOPVjACrV2o5F5SFlTVokima8xqZJ3K8Mt5W8JtTsJi2KIa3BmFTWVGdkTgSQ0VtgHgVZWUkZS
48 * JRO9bmwylbZ9RmiJAAXeHMH4peyCBj1KWkxLTM6V5DFXqC9xxWE2e937Uk4dGhLsygwwECBXVCm3dtPgBdoEgmrfEWBOCLZGxoanZBKNamF
49 * FpYzUy2Anc7LTDAqZtUbN",
50 * "notes": "An updated note",
51 * "recurringSessionId": "9299760d8a4a4f89b3481fc611f4be17-d0156d516f264989b727b0da13a42662",
52 * "scheduleId": "9299760d-8a4a-4f89-b348-1fc611f4be17",
53 * "scheduleOwnerId": "e6b6108c-92bc-462b-937c-dab386909fd2",
54 * "start": {
55 * "localDateTime": {
56 * "year": 2020,
57 * "monthOfYear": 12,
58 * "dayOfMonth": 31,
59 * "hourOfDay": 10,
60 * "minutesOfHour": 0
61 * },
62 * "timestamp": "2020-12-31T08:00:00.000Z"
63 * },
64 * "status": "CONFIRMED",
65 * "tags": [],
66 * "type": "EVENT"
67 * },
68 * {
69 * "end": {
70 * "localDateTime": {
71 * "year": 2021,
72 * "monthOfYear": 1,
73 * "dayOfMonth": 4,
74 * "hourOfDay": 18,
75 * "minutesOfHour": 0
76 * },
77 * "timestamp": "2021-01-04T16:00:00.000Z"
78 * },
79 * "_id": *"4jOkD28c0FrsNUSgzQzuLRkA2t1rv1FLTwquKmJyctoZm00vdeKFMyH4n9cCLtmQe8wvOVwmsJCUCPWT3LA2geDOBViOg62YOeTGcgvAnGyw6uKE
80 * iNVqqdHt8QVz4i7qMZu5irOPVjACrV2o5F5SFlV7u2wmfZmcjnaGKeU15ZlbLQhG2uvyCf0hQuk6tKFmzj3xdqdDjdlKJCrJs2cslMgLxIotwGRWg
81 * ipZJM2wzo6c2XCSUYjYWHe7FmpcExTyKZ2JUD9iftin96C2Y6nYREYoJMXYFzBBtdmoQprQkm5dXOPg2oUWasimBH1Y2EehSBEWVmKxAmH12IH",
82 * "notes": "",
83 * "recurringSessionId": "9299760d8a4a4f89b3481fc611f4be17-ecc4a5932acb4b7bb8c27c6ffb57fd49",
84 * "scheduleId": "9299760d-8a4a-4f89-b348-1fc611f4be17",
85 * "scheduleOwnerId": "e6b6108c-92bc-462b-937c-dab386909fd2",
86 * "start": {
87 * "localDateTime": {
88 * "year": 2021,
89 * "monthOfYear": 1,
90 * "dayOfMonth": 4,
91 * "hourOfDay": 10,
92 * "minutesOfHour": 0
93 * },
94 * "timestamp": "2021-01-04T08:00:00.000Z"
95 * },
96 * "status": "CONFIRMED",
97 * "tags": [],
98 * "type": "WORKING_HOURS"
99 * },
100 * {
101 * "end": {
102 * "localDateTime": {
103 * "year": 2021,
104 * "monthOfYear": 1,
105 * "dayOfMonth": 6,
106 * "hourOfDay": 18,
107 * "minutesOfHour": 0
108 * },
109 * "timestamp": "2021-01-06T16:00:00.000Z"
110 * },
111 * "_id": *"4jOkD28c0FrsNUSgzQzuLRkA2t1rv1FLTwquKmJyctoZm00vdeKFMyH4n9cCLtmQe8wvOVwmsJCUCPWT3LA2geDOBViOg62YOeTGcgvAnGyw6uKE
112 * iNVqqdHt8QVz4i7qMZu5irOPVjACrV2o5F5SFkPrsq3Jhjbq8UeqhF4rOEyqzl3ZcVqpQtlI8Yyo6yRlAnbAWq5pradMKsvlkHC4QPrB5AcrYvmfD
113 * jteuRaWbm5JFSng4LouD3sCED8MUALsTSuUor4yNxYzE8aucYxUDpauUXDmkbSk0bmcpWVUwE6D79ogsY1libzXvGgJLxujpZFokC1fWNiLWwv",
114 * "notes": "",
115 * "recurringSessionId": "9299760d8a4a4f89b3481fc611f4be17-3d6b38529f544674a4976eca75e584ca",
116 * "scheduleId": "9299760d-8a4a-4f89-b348-1fc611f4be17",
117 * "scheduleOwnerId": "e6b6108c-92bc-462b-937c-dab386909fd2",
118 * "start": {
119 * "localDateTime": {
120 * "year": 2021,
121 * "monthOfYear": 1,
122 * "dayOfMonth": 6,
123 * "hourOfDay": 10,
124 * "minutesOfHour": 0
125 * },
126 * "timestamp": "2021-01-06T08:00:00.000Z"
127 * },
128 * "status": "CONFIRMED",
129 * "tags": [],
130 * "type": "WORKING_HOURS"
131 * },
132 * {
133 * "end": {
134 * "localDateTime": {
135 * "year": 2021,
136 * "monthOfYear": 1,
137 * "dayOfMonth": 7,
138 * "hourOfDay": 18,
139 * "minutesOfHour": 0
140 * },
141 * "timestamp": "2021-01-07T16:00:00.000Z"
142 * },
143 * "_id": *"4jOkD28c0FrsNUSgzQzuLRkA2t1rv1FLTwquKmJyctoZm00vdeKFMyH4n9cCLtmQe8wvOVwmsJCUCPWT3LA2geDOBViOg62YOeTGcgvAnGyw6uKE
144 * iNVqqdHt8QVz4i7qMZu5irOPVjACrV2o5F5SFlTVokima8xqZJ3K8Mt5W8JtTsJi2KIa3BmFTWVGdkTgSQ0VtgHgVZWUkZSJRO9bmwylbZ9RmiJAA
145 * XeHMH4w0TkFE1ZSlf0MBCfuln4l0G7oKGKuO90Ai25Ud0wzQ6B6APNYOpsUkqppufK8twT7VYGmrozTLrL2zb01cFcL7bbssRdAFCskSZWbDaP",
146 * "notes": "An updated note",
147 * "recurringSessionId": "9299760d8a4a4f89b3481fc611f4be17-d0156d516f264989b727b0da13a42662",
148 * "scheduleId": "9299760d-8a4a-4f89-b348-1fc611f4be17",
149 * "scheduleOwnerId": "e6b6108c-92bc-462b-937c-dab386909fd2",
150 * "start": {
151 * "localDateTime": {
152 * "year": 2021,
153 * "monthOfYear": 1,
154 * "dayOfMonth": 7,
155 * "hourOfDay": 10,
156 * "minutesOfHour": 0
157 * },
158 * "timestamp": "2021-01-07T08:00:00.000Z"
159 * },
160 * "status": "CONFIRMED",
161 * "tags": [],
162 * "type": "EVENT"
163 * },
164 * {
165 * "end": {
166 * "localDateTime": {
167 * "year": 2021,
168 * "monthOfYear": 1,
169 * "dayOfMonth": 8,
170 * "hourOfDay": 18,
171 * "minutesOfHour": 0
172 * },
173 * "timestamp": "2021-01-08T16:00:00.000Z"
174 * },
175 * "_id": *"4jOkD28c0FrsNUSgzQzuLRkA2t1rv1FLTwquKmJyctoZm00vdeKFMyH4n9cCLtmQe8wvOVwmsJCUCPWT3LA2geDOBViOg62YOeTGcgvAnGyw6uKE
176 * iNVqqdHt8QVz4i7qMZu5irOPVjACrV2o5F5SFkTukwrkodDkJBBtH3JaGj18FY3z9vvxDE0COr8D282JjVfq7YMAwQnTq4tYWYJkfPm7PDLI6zoWZ
177 * REstI4qEbt9u6qB3UHudvTCxqFYL1IOaWl48c2kHaCaEwfB53cbd5ndRAj4yv8JchSIwDa1rgxINU4JITqstE4QJ5FMugAnqVkzBjiH1P502ZB",
178 * "notes": "",
179 * "recurringSessionId": "9299760d8a4a4f89b3481fc611f4be17-6f9f945736fd4490b4b95fbb4b1326b3",
180 * "scheduleId": "9299760d-8a4a-4f89-b348-1fc611f4be17",
181 * "scheduleOwnerId": "e6b6108c-92bc-462b-937c-dab386909fd2",
182 * "start": {
183 * "localDateTime": {
184 * "year": 2021,
185 * "monthOfYear": 1,
186 * "dayOfMonth": 8,
187 * "hourOfDay": 10,
188 * "minutesOfHour": 0
189 * },
190 * "timestamp": "2021-01-08T08:00:00.000Z"
191 * },
192 * "status": "CONFIRMED",
193 * "tags": [],
194 * "type": "WORKING_HOURS"
195 * }
196 * ]
197 */