WIX Booking: createSession() error "entity_not_found"

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);
    });
}