Creates a service.
When creating a service you must specify the following fields:
type
(SDK | REST):
Whether it's an appointment-based service, class, or course.name
: Service name that's displayed to customers.onlineBooking
:
Settings determining whether customers can book online, whether the business
must manually confirm bookings, and whether customers can request to book an
appointment time slot that already has a booking request awaiting business
confirmation.payment
(SDK | REST):
How customers can pay when signing up for the service.Depending on which type of service you're creating, you may also need to specify supported session durations.
Classes and courses
Don't specify schedule.availabilityConstraints.sessionDurations
.
Appointment-based services without varied pricing based on session length
Specify the single supported session duration in the
schedule.availabilityConstraints.sessionDurations
array.
Appointment-based services with varied pricing based on session length
schedule.availabilityConstraints.sessionDurations
.schedule.availabilityConstraints.sessionDurations
,
even though these values are ignored.function createService(service: Service): Promise<Service>;
Service to create.
Create a class with a capacity of 30 people.
import { services } from "@wix/bookings";
import { categories } from "@wix/bookings";
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)"
}
*/
There are 21 errors with this status code.
This method may also return standard errors. Learn more about standard Wix errors.