createService( )


Creates a service.

Required fields

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.

Session durations

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

  • Specify all supported session durations in schedule.availabilityConstraints.sessionDurations.
  • Note that Wix Bookings doesn't display these values to customers and ignores them in pricing and availability calculations. Instead session durations are retrieved from the relevant service variants (SDK | REST).
  • It is mandatory to specify schedule.availabilityConstraints.sessionDurations, even though these values are ignored.
Authentication
  • When developing websites or building an app with Blocks, this method may require elevated permissions, depending on the identity of the user calling it and the calling user’s permissions.
  • When building apps without Blocks or for headless projects, you can only call this method directly when authenticated as a Wix app or Wix user identity. When authenticated as a different identity, you can call this method using elevation.
  • Elevation permits users to call methods they typically cannot access. Therefore, you should only use it intentionally and securely.
Permissions
Manage Bookings - all permissions
Manage Bookings
Learn more about app permissions.
Method Declaration
Copy
function createService(service: Service): Promise<Service>;
Method Parameters
serviceServiceRequired

Service to create.

Returns
Return Type:Promise<Service>

Create a class with a capacity of 30 people.

JavaScript
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)" } */
Errors
400Invalid Argument

There are 21 errors with this status code.

This method may also return standard errors. Learn more about standard Wix errors.

Did this help?