Creates a resource.
The createResource()
function returns a Promise that resolves to the created resource.
Bookings resources are created with a schedule. The schedule and its sessions determine the resource's availability. Note that the schedule must contain a start date in the availability.start
property.
For resources that are available during the business's default hours, add the business's schedule as a linked schedule in the resource's schedule. For resources that have their own hours, create sessions with type "WORKING_HOURS"
using the resource's schedule.
You can use both individual and recurring sessions to define resource availability. You cannot use availability constraints for resource schedules.
When creating a resource using createResource()
, include the resource's schedule information. Set the schedule information as follows:
scheduleInfo.availability.linkedSchedules
array in the scheduleInfo
parameter. The default hours can bee found in the Dashboard under Settings in the Bookings section, on the Appointment hours page."WORKING_HOURS"
using the createSession()
function. Use the scheduleId
returned from createResource()
when creating the sessions. These session can be single sessions or recurring sessions.Notes:
WORKING_HOURS
sessions in the resource calendar.options.suppressAuth
parameter to true
.Notes:
function createResource(
resourceInfo: ResourceInfo,
scheduleInfo: Array<ResourceScheduleInfo>,
options: Options,
): Promise<Resource>;
Information to use when creating a resource.
List of schedules to be assigned to the created resource. Currently only a single schedule is allowed. If provided, any additional schedules in the resource object will be ignored.
An object representing the available options for creating a resource.
import { Permissions, webMethod } from "wix-web-module";
import { resources } from "wix-bookings-backend";
export const getBusinessSchedule = webMethod(Permissions.Anyone, () => {
return resources
.queryResourceCatalog()
.eq("slugs.name", "business")
.find()
.then((results) => {
const businessResource = results.items[0].resource;
return businessResource;
});
});
export const createStaffWithBusinessHours = webMethod(
Permissions.Anyone,
async (staffInfo) => {
staffInfo = {
name: "John Doe",
email: "john@doe.com",
phone: "555 4567",
description: "Fitness Instructor",
};
const businessResource = await getBusinessSchedule();
const businessResourceScheduleId = businessResource.scheduleIds[0];
const schedules = [
{
availability: {
linkedSchedules: [
{
scheduleId: businessResourceScheduleId,
},
],
start: new Date(),
},
},
];
const resource = {
name: staffInfo.name,
email: staffInfo.email,
phone: staffInfo.phone,
description: staffInfo.description,
tags: ["staff"],
};
const options = { suppressAuth: true };
return resources
.createResource(resource, schedules, options)
.then((resource) => {
return resource;
})
.catch((error) => {
console.error("Failed to create resource: ", error);
return error;
});
},
);
/* Example of a returned resource:
* "_id": "6235c808-c3c6-49f2-a000-bc8eded9f106",
* "name": "John Doe",
* "email": "john@doe.com",
* "phone": "555 4567",
* "description": "Fitness Instructor",
* "tags": [
* "staff"
* ],
* "scheduleIds": [
* "a5d20a3a-eb25-497a-9fc1-f546ac8422fc"
* ],
* "status": "CREATED"
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.