I am flabbergasted by the error from this code. Any insight? I am trying to create a session blocking the schedule of a resource. I am using the _id from the Schedule database. The error message seems to say that the _id of the schedule I am trying to assign a session to is "entity_not_found" I wonder if I'm using the wrong id field? I have tried switching to "WORKING_HOURS" for the type field, and multiple scheduleIds. I am lost. PLEASE HELP!
import wixData from 'wix-data';
import { sessions } from "wix-bookings-backend";
let sched = "b263b6c9-efa9-407e-b096-114512ab2d03"
export async function createNonRecurringSessions(sched, sdate, edate) {
const sessionInfo = {
scheduleId: sched,
start: {
timestamp: new Date(sdate)
},
end: {
timestamp: new Date(edate)
},
type: "EVENT",
tags: ["Blocked"]
};
const options2 = { suppressAuth: true };
return sessions.createSession(sessionInfo, options2)
.then((session) => {
return session;
})
.catch((error) => {
console.error('Failed to create session:', error);
});
}
Failed to create session:
message:
entity_not_found,
details: {
"entity":"schedule",
"scheduleId":"b263b6c9-efa9-407e-b096-114512ab2d03",
"targetDate":"",
"scheduleVersion":""}
: Not Found
details:
applicationError:
description: Not Found
code: NOT_FOUND
data: {}
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); }); }