Search.../

queryEvents( )

Creates a query to retrieve a list of Wix events.

Description

The queryEvents() function builds a query to retrieve a list of Wix events and returns a EventsQueryBuilder object.

The returned object contains the query definition which is typically used to run the query using the find() function.

You can refine the query by chaining EventsQueryBuilder functions onto the query. EventsQueryBuilder functions enable you to sort, filter, and control the results that queryEvents.find() returns.

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

The functions that are chained to queryEvents() are applied in the order they are called. For example, if you sort on the _createdDate property in ascending order and then on the status property in descending order, the results are sorted first by the created date of the items and then, if there are multiple results with the same date, the items are sorted by status in descending order, per created date value.

The following EventsQueryBuilder functions are supported for queryEvents().

For a full description of the Wix Event object, see the object returned for the items property in EventsQueryResult.

PropertySupported Filters & Sorting
_ideq(), ne(), hasSome()
titleeq(), ne(), lt(), le(), gt(), ge(), hasSome(), contains(),ascending(), descending()
statuseq(), ne(), hasSome(), contains()
createdByeq(), ne(), hasSome()
scheduling.startDatelt(), le(), gt(), ge(), ascending(), descending()
scheduling.endDatelt(), le(), gt(), ge(), ascending(), descending()
_createdDateascending(), descending()
_updatedDateascending(), descending()
slugeq(), ne(), lt(), le(), gt(), ge(), hasSome(), contains(), ascending(), descending()

You can only use one filter function for each property. If a property is used in more than one filter, only the first filter will work.

Notes:

  • A guest can only see their own Wix events unless suppressAuth is set to true in the queryOptions for the find() function.
  • When using the queryEvents() function immediately following a change to your Wix events, the data retrieved may not contain your most recent changes. See Wix-data and Eventual Consistency for more information. To solve this problem, you can use the setTimeout() function to delay querying for a number of seconds, following any changes to your Wix events data.

Only those with "Manage Events" permissions can query Wix events. Only the events they are authorized to receive are returned.

Syntax

function queryEvents(): EventsQueryBuilder

queryEvents Parameters

This function does not take any parameters.

Returns

Contains functionality for refining a Wix events query. The EventsQueryBuilder functions enable you to run, sort, filter, and control which results a query returns.

Typically, you build a query using any of the event query functions, refine the query by chaining EventsQueryBuilder functions, and then execute the query by chaining the find() function.

For example, the following code returns the first 5 upcoming Wix events created by a given event manager, including scheduled events and events that have started. The events are listed in ascending order by the event's start date.

import { wixEvents } from 'wix-events-backend';
wixEvents.queryEvents()
.eq("createdBy", "4c47c608-cfa8-4037-93ac-738f09560ed3")
.hasSome("status", ["SCHEDULED", "STARTED"])
.ascending("scheduling.startDate")
.limit(5)
.find()
.then( (results) => {
console.log(results.items);
} );
javascript | Copy Code

Return Type:

Was this helpful?

Retrieve the newest Wix event that has the "SCHEDULED" status

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { wixEvents } from 'wix-events-backend';
3
4export const myQueryEventsFunction = webMethod(Permissions.Anyone, async () => {
5 try {
6 await wixEvents.queryEvents()
7 .hasSome("status", ["SCHEDULED"])
8 .descending("createdDate")
9 .find()
10 .then((results) => {
11 const items = results.items;
12 const firstItem = items[0];
13 console.log('Success! Events:', firstItem);
14 return firstItem;
15 })
16 } catch (error) {
17 console.error(error);
18 // Handle the error
19 }
20});
21
22/* Promise resolves to:
23 {
24 "about": "Join us for Nature's Symphony: A Musical Journey Through Wildlife at the iconic Royal Albert Hall.",
25 "assignedContactsLabel": "custom.natures-symphony-a-musical-journey-through-wildl",
26 "calendarLinks": {
27 "google": "http://calendar.google.com/calendar/render?action=TEMPLATE&text=Nature%27s+Symphony%3A+A+Musical+Journey+Through+Wildlife.&dates=&location=Kensington+Gore%2C+London+SW7%2C+UK&details=Thank+you+for+registering+to+our+event%21+Your+tickets+are+attached+to+this+email.+Don%27t+forget+to+bring+them.%0A%0AWe%27re+looking+forward+to+seeing+you+there.%0A%0AHere+are+the+details%3A%0A%0ANature%27s+Symphony%3A+A+Musical+Journey+Through+Wildlife.%0AThe+date+will+be+announced+soon%2C+stay+tuned%21%0ARoyal+Albert+Hall%2C+Kensington+Gore%2C+London+SW7%2C+UK",
28 "ics": "https://www.wixevents.com/media/v2/calendar?token=JWS.eyJraWQiOiJpb21iOUJ0eSIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaW5zdGFuY2VJZFwiOlwiMWY2ZGM5MDYtODAzZC00NjUwLTgzZjUtNzJlYTFkODgxMDBiXCIsXCJldmVudElkXCI6e1widmFsdWVcIjpcImQxNTJmNDJjLTcyMWMtNDc3MC1hMTc4LWYwZTZjMWQ1NWYyN1wifSxcIm9jTGlua1wiOm51bGx9IiwiaWF0IjoxNjk5NTMxNjUzfQ.tiiCPGnU-ZD9ZKRoJe6vqcyi0HeHDCju6GKphZEDtN0"
29 },
30 "categories": [],
31 "createdBy": "",
32 "_createdDate": "2023-11-08T15:06:13.353Z",
33 "description": "Immerse yourself in the enchanting harmony of nature's symphony as it intertwines with the power of music!",
34 "eventUrl": {
35 "baseUrl": "https://mysite.com/events",
36 "path": "/event-details-registration/natures-symphony-a-musical-journey-through-wildlife"
37 },
38 "form": {
39 "inputGroups": [
40 {
41 "_id": "name",
42 "inputs": [
43 {
44 "additionalLabels": [],
45 "label": "First name",
46 "maxLength": 50,
47 "name": "firstName",
48 "options": [],
49 "required": true,
50 "type": "TEXT"
51 },
52 {
53 "additionalLabels": [],
54 "label": "Last name",
55 "maxLength": 50,
56 "name": "lastName",
57 "options": [],
58 "required": true,
59 "type": "TEXT"
60 }
61 ],
62 "orderIndex": 0,
63 "system": true,
64 "type": "NAME"
65 },
66 {
67 "_id": "email",
68 "inputs": [
69 {
70 "additionalLabels": [],
71 "label": "Email",
72 "maxLength": 255,
73 "name": "email",
74 "options": [],
75 "required": true,
76 "type": "TEXT"
77 }
78 ],
79 "orderIndex": 1,
80 "system": true,
81 "type": "INPUT"
82 }
83 ],
84 "messages": {
85 "checkout": {
86 "checkoutLabel": "Continue",
87 "title": "Add your details"
88 },
89 "registrationClosed": {
90 "exploreEventsLabel": "See other events",
91 "message": "Registration is closed"
92 },
93 "rsvp": {
94 "noMessages": {
95 "confirmationTitle": "Sorry You Can't Make It",
96 "shareLabel": "Share",
97 "title": "Add your details"
98 },
99 "rsvpNo": "Not Going",
100 "rsvpYes": "I'm Going",
101 "submitRsvpLabel": "SUBMIT",
102 "waitingMessages": {
103 "addToCalendarLabel": "Add to Calendar",
104 "confirmationMessage": "We'll update you if additional spots become available.",
105 "confirmationTitle": "Thanks! You've been added to the waitlist.",
106 "shareLabel": "Share",
107 "title": "Looks like this event is full. Join the waitlist."
108 },
109 "yesMessages": {
110 "addToCalendarLabel": "Add to Calendar",
111 "confirmationMessage": "An email with all the event info was sent to you.",
112 "confirmationTitle": "Thank you!",
113 "shareLabel": "Share",
114 "title": "Add your details"
115 }
116 }
117 }
118 },
119 "guestList": {
120 "public": true
121 },
122 "_id": "d152f42c-721c-4770-a178-f0e6c1d55f27",
123 "language": "en",
124 "location": {
125 "address": {
126 "formatted": "Kensington Gore, London SW7, UK",
127 "location": {
128 "latitude": 51.5009132,
129 "longitude": -0.1766086
130 },
131 "city": "London",
132 "country": "GB",
133 "postalCode": "SW7 2BL",
134 "streetAddress": {
135 "name": "Kensington Gore",
136 "number": "SW7",
137 "apt": ""
138 }
139 },
140 "name": "Royal Albert Hall",
141 "tbd": false,
142 "type": "VENUE"
143 },
144 "registration": {
145 "initialType": "TICKETS",
146 "restrictedTo": "VISITOR",
147 "rsvp": {
148 "responseOptions": "YES_ONLY",
149 "waitlist": false
150 },
151 "status": "CLOSED",
152 "tickets": {
153 "formAssignedPerTicket": false,
154 "highestTicketPrice": {},
155 "lowestTicketPrice": {},
156 "tax": {}
157 },
158 "type": "TICKETS"
159 },
160 "scheduling": {
161 "formatted": "The date will be announced soon, stay tuned!",
162 "hideEndDate": false,
163 "showTimeZone": false,
164 "startDateFormatted": "",
165 "startTimeFormatted": "",
166 "tbd": true,
167 "tbdMessage": "The date will be announced soon, stay tuned!"
168 },
169 "slug": "natures-symphony-a-musical-journey-through-wildlife",
170 "status": "SCHEDULED",
171 "summary": {
172 "rsvp": {},
173 "tickets": {
174 "revenue": {},
175 "totalSales": {}
176 }
177 },
178 "title": "Nature's Symphony: A Musical Journey Through Wildlife.",
179 "_updatedDate": "2023-11-08T15:06:13.000Z",
180 "videoConferencing": {
181 "session": {}
182 }
183}
184*/