This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Creates a new service.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createService(service: Service): Promise<Service>;
Service to be created.
Create a class with a capacity of 30 people.
import { services } from "wix-bookings.v2";
import { categories } from "wix-bookings.v1";
async function getFirstCategory() {
const response = await categories.listCategories();
return response.categories[0];
}
async function createClass() {
const category = await getFirstCategory();
const serviceToBeCreated = {
type: services.ServiceType.CLASS,
name: "Group Cat Hugging",
description:
"Introducing the Purrfect Hug - the ultimate cat cuddling experience! Our team of expert cuddlers will come to your home and provide your furry feline with the warmest and snuggliest hugs around.",
tagLine: "Get some purr therapy with our cat hugging service!",
defaultCapacity: 30,
category: category,
media: {
mainMedia: {
image:
"wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg#originWidth=800&originHeight=1000",
},
},
payment: {
rateType: services.RateType.FIXED,
fixed: {
price: {
value: "25",
currency: "USD",
},
},
options: {
online: true,
inPerson: false,
deposit: false,
pricingPlan: false,
},
},
onlineBooking: {
enabled: true,
},
};
const newService = await services.createService(serviceToBeCreated);
console.log("Success! Created a new service:", newService);
return newService;
}
/* Promise resolves to:
* {
"type": "CLASS",
"sortOrder": 3,
"name": "Group Cat Hugging",
"description": "Introducing the Purrfect Hug - the ultimate cat cuddling experience! Our team of expert cuddlers will come to your home and provide your furry feline with the warmest and snuggliest hugs around.",
"tagLine": "Get some purr therapy with our cat hugging service!",
"defaultCapacity": 30,
"media": {
"items": [],
"mainMedia": {
"image": "wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg/4b3901ffcb8d7ad81a613779d92c9702.jpg#originWidth=800&originHeight=1000"
}
},
"hidden": false,
"category": {
"name": "Our Services",
"sortOrder": 0,
"_id": "99b3c3af-3dd1-4fcd-8d97-2fcedcb2908c"
},
"payment": {
"rateType": "FIXED",
"fixed": {
"price": {
"value": "25",
"currency": "USD"
}
},
"options": {
"online": true,
"inPerson": false,
"deposit": false,
"pricingPlan": false
},
"pricingPlanIds": []
},
"onlineBooking": {
"enabled": true
},
"locations": [
{
"type": "BUSINESS"
}
],
"bookingPolicy": {
"revision": "1",
"name": "Default policy",
"customPolicyDescription": {
"enabled": true,
"description": ""
},
"default": true,
"limitEarlyBookingPolicy": {
"enabled": false,
"earliestBookingInMinutes": 10080
},
"limitLateBookingPolicy": {
"enabled": false,
"latestBookingInMinutes": 1440
},
"bookAfterStartPolicy": {
"enabled": false
},
"cancellationPolicy": {
"enabled": true,
"limitLatestCancellation": false,
"latestCancellationInMinutes": 1440
},
"reschedulePolicy": {
"enabled": true,
"limitLatestReschedule": false,
"latestRescheduleInMinutes": 1440
},
"waitlistPolicy": {
"enabled": false,
"capacity": 10,
"reservationTimeInMinutes": 10
},
"participantsPolicy": {
"enabled": true,
"maxParticipantsPerBooking": 1
},
"resourcesPolicy": {
"enabled": false,
"autoAssignAllowed": false
},
"_id": "ede8ad9e-44e1-480e-833f-542aea019bd0",
"_createdDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)",
"_updatedDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)"
},
"schedule": {
"_id": "8d9560d3-72b9-45c0-a16d-1e73f7d38e11"
},
"staffMemberIds": [],
"staffMembers": [],
"resourceGroups": [],
"serviceResources": [],
"supportedSlugs": [
{
"name": "group-cat-hugging",
"custom": false,
"_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"
}
],
"mainSlug": {
"name": "group-cat-hugging",
"custom": false,
"_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"
},
"urls": {
"servicePage": "https://www.example.com/services-v2-test/service-page/group-cat-hugging",
"bookingPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging",
"calendarPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging"
},
"revision": "1",
"_id": "1204a214-d1fb-41c8-886a-1ec461b990dd",
"_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)",
"_updatedDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"
}
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.