Hey @Roger Hunt , It’s Jacob from Wix Bookings.
Your code is OK, the problem is that the scheduleId you got from the Schedules collection belongs to a service. When you want to create a BLOCKED time for a staff member, you need to apply the scheduleId of that staff member.
import { sessions } from "wix-bookings-backend";
import { resources } from "wix-bookings-backend";
export async function createNonRecurringSessions() {
let resources = await queryResourceCatalog()
let staffScheduleId = resources[0].resource.scheduleIds[0]
const sessionInfo = {
scheduleId: staffScheduleId,
start: {
timestamp: new Date("2023-04-21T09:00:00.000Z")
},
end: {
timestamp: new Date("2023-04-21T10:00:00.000Z")
},
type: "EVENT",
tags: ["Blocked"],
notes: "Blocked time with Velo code"
};
console.log("sessionInfo:", sessionInfo);
return sessions.createSession(sessionInfo, {suppressAuth: true})
.then((session) => {
return session;
})
.catch((error) => {
console.error('Failed to create session:', error);
});
}
export async function queryResourceCatalog() {
return resources.queryResourceCatalog()
.find()
.then((results) => {
return results.items.filter(item => item.resource.name != "business");
})
.catch((error) => {
console.error(error);
});
}
Hey Roger, no, you can’t get the resources’ scheduleId from a collection and you really don’t need to because you can get this info from resources API. See the ’ queryResourceCatalog’ function in my code.
Regarding the documentation, I agree that it’s not clear at all. I’ll pass it on. Thanks for that.