I’m having trouble with
A permission error in my Wix Velo site when trying to query draft events from the backend.
Even though I’m logged in using the site owner’s email (the same account I use to edit the site in the Wix Dashboard), the backend call fails with this error:
{
"success": false,
"error": "message: Requires WIX_EVENTS.READ_DRAFT_EVENTS permission; MemberIdentity id='f5a852dc-390d-4e28-a11d-e5fc2f16d9b7'
details:
applicationError:
description: Requires WIX_EVENTS.READ_DRAFT_EVENTS permission; MemberIdentity id='f5a852dc-390d-4e28-a11d-e5fc2f16d9b7'
code: PERMISSION_DENIED
data:
context:
instanceId: 3e5ce0e4-4c02-4704-95b3-978f343cc8e7
siteMemberId: f5a852dc-390d-4e28-a11d-e5fc2f16d9b7
identities:
- person:
type: SITEMEMBER
hasUserRole: true
Working in
Wix Editor
Site link
Link: https://www.ezdestinations.com/blank-5?rc=test-site
What I’ve tried so far
I have tried using the elevated permission within the backend code both the .jsw and .js file. And tried with different account with the admin access to the wix project. Also those accounts are the site members with login credentials created within the site.
Code:
//adminEvents.js
import { wixEventsV2 } from 'wix-events.v2';
import { elevate } from 'wix-auth';
export async function getAllEventsElevated() {
return await elevate(async () => {
let allEvents = [];
let offset = 0;
const batchSize = 100;
while (true) {
const query = await wixEventsV2.queryEvents({ includeDrafts: true })
.ascending('dateAndTimeSettings.startDate')
.limit(batchSize)
.skip(offset)
.find();
allEvents.push(...query.items);
if (query.items.length < batchSize) break;
offset += batchSize;
}
return allEvents;
})();
}
// adminEvents.jsw
import { webMethod, Permissions } from 'wix-web-module';
import { getAllEventsElevated } from 'backend/adminevents.js';
export function getAllEventsData() {
return webMethod(Permissions.Admin, async () => {
try {
const events = await getAllEventsElevated();
return { success: true, events };
} catch (error) {
return { success: false, error: error.message };
}
})();
}
//This is how I called it in frontend
const result = await getAllEventsData();
