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