createService( )
Creates a new service.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function createService(service: Service): Promise<Service>
createService Parameters
NAME
TYPE
DESCRIPTION
Service to be created.
Returns
The created service.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the service was created.
Service ID.
Date and time the service was updated.
Policy determining under what conditions this service can be booked. For example, whether the service can only be booked up to 30 minutes before it begins.
The category the service is associated with.
Conferencing options for this service.
Default maximum number of customers that can book the service. The service cannot be booked beyond this capacity.
Service description, such as High-class hair styling, cuts, straightening and color.
Extensions enabling users to save custom data related to the service.
The form used when booking the service.
Whether the service is hidden from the site.
The locations this service is offered at.
In case of multiple (more than 1) location, All locations must be of type BUSINESS
.
For courses only: Currently, only 1 location is supported, for all location types.
The main slug for the service. mainSlug
is either taken from the current service name or is a custom slug set by the business owner.
mainSlug
is used to construct the service's URLs.
Media associated with the service.
Service name.
Online booking settings.
Payment options for booking the service.
Revision number, which increments by 1 each time the service is updated. To prevent conflicting changes, the existing revision must be used when updating a service.
The service's schedule, which can be used to manage the service's sessions.
Custom SEO data for the service.
Order of a service within a category.
IDs of the staff members providing the service. For appointments only.
A slug is the last part of the URL address that serves as a unique identifier of the service. The list of supported slugs includes past service names for backwards compatibility, and a custom slug if one was set by the business owner.
Short service description, such as Hair styling.
Service type.
Supported Values:
- "APPOINTMENT"
- "CLASS"
- "COURSE"
URLs to various service-related pages, such as the calendar page and the booking page.
Was this helpful?
Create a class with a capacity of 30 people.
12import { services } from 'wix-bookings.v2';3import { categories } from 'wix-bookings.v1';45async function getFirstCategory() {6 const response = await categories.listCategories();7 return response.categories[0]8}910async function createClass() {11 const category = await getFirstCategory();1213 const serviceToBeCreated = {14 type: services.ServiceType.CLASS,15 name: "Group Cat Hugging",16 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.",17 tagLine: "Get some purr therapy with our cat hugging service!",18 defaultCapacity: 30,19 category: category,20 media: {21 mainMedia: {22 image: "wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg#originWidth=800&originHeight=1000"23 }24 },25 payment: {26 rateType: services.RateType.FIXED,27 fixed: {28 price: {29 value: "25",30 currency: "USD"31 }32 },33 options: {34 online: true,35 inPerson: false,36 deposit: false,37 pricingPlan: false38 }39 },40 onlineBooking: {41 enabled: true42 },43 }4445 const newService = await services.createService(serviceToBeCreated);4647 console.log('Success! Created a new service:', newService);4849 return newService;50}5152/* Promise resolves to:53 * {54 "type": "CLASS",55 "sortOrder": 3,56 "name": "Group Cat Hugging",57 "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.",58 "tagLine": "Get some purr therapy with our cat hugging service!",59 "defaultCapacity": 30,60 "media": {61 "items": [],62 "mainMedia": {63 "image": "wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg/4b3901ffcb8d7ad81a613779d92c9702.jpg#originWidth=800&originHeight=1000"64 }65 },66 "hidden": false,67 "category": {68 "name": "Our Services",69 "sortOrder": 0,70 "_id": "99b3c3af-3dd1-4fcd-8d97-2fcedcb2908c"71 },72 "payment": {73 "rateType": "FIXED",74 "fixed": {75 "price": {76 "value": "25",77 "currency": "USD"78 }79 },80 "options": {81 "online": true,82 "inPerson": false,83 "deposit": false,84 "pricingPlan": false85 },86 "pricingPlanIds": []87 },88 "onlineBooking": {89 "enabled": true90 },91 "locations": [92 {93 "type": "BUSINESS"94 }95 ],96 "bookingPolicy": {97 "revision": "1",98 "name": "Default policy",99 "customPolicyDescription": {100 "enabled": true,101 "description": ""102 },103 "default": true,104 "limitEarlyBookingPolicy": {105 "enabled": false,106 "earliestBookingInMinutes": 10080107 },108 "limitLateBookingPolicy": {109 "enabled": false,110 "latestBookingInMinutes": 1440111 },112 "bookAfterStartPolicy": {113 "enabled": false114 },115 "cancellationPolicy": {116 "enabled": true,117 "limitLatestCancellation": false,118 "latestCancellationInMinutes": 1440119 },120 "reschedulePolicy": {121 "enabled": true,122 "limitLatestReschedule": false,123 "latestRescheduleInMinutes": 1440124 },125 "waitlistPolicy": {126 "enabled": false,127 "capacity": 10,128 "reservationTimeInMinutes": 10129 },130 "participantsPolicy": {131 "enabled": true,132 "maxParticipantsPerBooking": 1133 },134 "resourcesPolicy": {135 "enabled": false,136 "autoAssignAllowed": false137 },138 "_id": "ede8ad9e-44e1-480e-833f-542aea019bd0",139 "_createdDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)",140 "_updatedDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)"141 },142 "schedule": {143 "_id": "8d9560d3-72b9-45c0-a16d-1e73f7d38e11"144 },145 "staffMemberIds": [],146 "staffMembers": [],147 "resourceGroups": [],148 "serviceResources": [],149 "supportedSlugs": [150 {151 "name": "group-cat-hugging",152 "custom": false,153 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"154 }155 ],156 "mainSlug": {157 "name": "group-cat-hugging",158 "custom": false,159 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"160 },161 "urls": {162 "servicePage": "https://www.example.com/services-v2-test/service-page/group-cat-hugging",163 "bookingPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging",164 "calendarPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging"165 },166 "revision": "1",167 "_id": "1204a214-d1fb-41c8-886a-1ec461b990dd",168 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)",169 "_updatedDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"170}171 */
Create an appointment provided by specific staff members.
1import { services } from 'wix-bookings.v2';2import { categories } from 'wix-bookings.v1';34async function getFirstCategory() {5 const response = await categories.listCategories();6 return response.categories[0]7}89async function createAppointment(staffMemberIds) {1011 const category = await getFirstCategory();1213 const serviceToBeCreated = {14 type: services.ServiceType.APPOINTMENT,15 name: "Personal Cat Hugging",16 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.",17 tagLine: "Get some purr therapy with our cat hugging service!",18 category: category,19 media: {20 mainMedia: {21 image: "wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg/#originWidth=800&originHeight=1000"22 }23 },24 payment: {25 rateType: services.RateType.FIXED,26 fixed: {27 price: {28 value: "25",29 currency: "USD"30 }31 },32 options: {33 online: true,34 inPerson: false,35 deposit: false,36 pricingPlan: false37 },38 },39 staffMemberIds: staffMemberIds40 }4142 const newService = await services.createService(serviceToBeCreated);4344 console.log('Success! Created a new service:', newService);4546 return newService;47}4849/* Promise resolves to:50 * {51 "type": "APPOINTMENT",52 "sortOrder": 3,53 "name": "Group Cat Hugging",54 "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.",55 "tagLine": "Get some purr therapy with our cat hugging service!",56 "defaultCapacity": 30,57 "media": {58 "items": [],59 "mainMedia": {60 "image": "wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg/4b3901ffcb8d7ad81a613779d92c9702.jpg#originWidth=800&originHeight=1000"61 }62 },63 "hidden": false,64 "category": {65 "name": "Our Services",66 "sortOrder": 0,67 "_id": "99b3c3af-3dd1-4fcd-8d97-2fcedcb2908c"68 },69 "payment": {70 "rateType": "FIXED",71 "fixed": {72 "price": {73 "value": "25",74 "currency": "USD"75 }76 },77 "options": {78 "online": true,79 "inPerson": false,80 "deposit": false,81 "pricingPlan": false82 },83 "pricingPlanIds": []84 },85 "onlineBooking": {86 "enabled": true87 },88 "locations": [89 {90 "type": "BUSINESS"91 }92 ],93 "bookingPolicy": {94 "revision": "1",95 "name": "Default policy",96 "customPolicyDescription": {97 "enabled": true,98 "description": ""99 },100 "default": true,101 "limitEarlyBookingPolicy": {102 "enabled": false,103 "earliestBookingInMinutes": 10080104 },105 "limitLateBookingPolicy": {106 "enabled": false,107 "latestBookingInMinutes": 1440108 },109 "bookAfterStartPolicy": {110 "enabled": false111 },112 "cancellationPolicy": {113 "enabled": true,114 "limitLatestCancellation": false,115 "latestCancellationInMinutes": 1440116 },117 "reschedulePolicy": {118 "enabled": true,119 "limitLatestReschedule": false,120 "latestRescheduleInMinutes": 1440121 },122 "waitlistPolicy": {123 "enabled": false,124 "capacity": 10,125 "reservationTimeInMinutes": 10126 },127 "participantsPolicy": {128 "enabled": true,129 "maxParticipantsPerBooking": 1130 },131 "resourcesPolicy": {132 "enabled": false,133 "autoAssignAllowed": false134 },135 "_id": "ede8ad9e-44e1-480e-833f-542aea019bd0",136 "_createdDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)",137 "_updatedDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)"138 },139 "schedule": {140 "_id": "8d9560d3-72b9-45c0-a16d-1e73f7d38e11"141 },142 "staffMemberIds": [],143 "staffMembers": [],144 "resourceGroups": [],145 "serviceResources": [],146 "supportedSlugs": [147 {148 "name": "group-cat-hugging",149 "custom": false,150 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"151 }152 ],153 "mainSlug": {154 "name": "group-cat-hugging",155 "custom": false,156 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"157 },158 "urls": {159 "servicePage": "https://www.example.com/services-v2-test/service-page/group-cat-hugging",160 "bookingPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging",161 "calendarPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging"162 },163 "revision": "1",164 "_id": "1204a214-d1fb-41c8-886a-1ec461b990dd",165 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)",166 "_updatedDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"167 }168 */169
Create a course that can accommodate 30 people.
1import { services } from 'wix-bookings.v2';2import { categories } from 'wix-bookings.v1';34async function getFirstCategory() {5 const response = await categories.listCategories();6 return response.categories[0]7}89async function createCourse() {1011 const category = await getFirstCategory();1213 const serviceToBeCreated = {14 type: services.ServiceType.COURSE,15 name: "Cat Hugging Training",16 description: "Introducing the Purrfect Hug - the ultimate cat cuddling experience! Our team of expert cuddlers will train you to become the best cat hugger around.",17 tagLine: "Get some purr therapy training with our cat hugging experts",18 defaultCapacity: 30,19 category: category,20 media: {21 mainMedia: {22 image: "wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg/#originWidth=800&originHeight=1000"23 }24 },25 payment: {26 rateType: services.RateType.FIXED,27 fixed: {28 price: {29 value: "150",30 currency: "USD"31 }32 },33 options: {34 online: true,35 inPerson: false,36 deposit: false,37 pricingPlan: false38 },39 },40 onlineBooking: {41 enabled: true42 },43 }4445 const newService = await services.createService(serviceToBeCreated);4647 console.log('Success! Created a new service:', newService);4849 return newService;50}5152/* Promise resolves to:53 * {54 "type": "COURSE",55 "sortOrder": 3,56 "name": "Cat Hugging Training",57 "description": "Introducing the Purrfect Hug - the ultimate cat cuddling experience! Our team of expert cuddlers will train you to become the best cat hugger around.".58 "tagLine": "Get some purr therapy training with our cat hugging experts",59 "defaultCapacity": 30,60 "media": {61 "items": [],62 "mainMedia": {63 "image": "wix:image://v1/4b3901ffcb8d7ad81a613779d92c9702.jpg/4b3901ffcb8d7ad81a613779d92c9702.jpg#originWidth=800&originHeight=1000"64 }65 },66 "hidden": false,67 "category": {68 "name": "Our Services",69 "sortOrder": 0,70 "_id": "99b3c3af-3dd1-4fcd-8d97-2fcedcb2908c"71 },72 "payment": {73 "rateType": "FIXED",74 "fixed": {75 "price": {76 "value": "25",77 "currency": "USD"78 }79 },80 "options": {81 "online": true,82 "inPerson": false,83 "deposit": false,84 "pricingPlan": false85 },86 "pricingPlanIds": []87 },88 "onlineBooking": {89 "enabled": true90 },91 "locations": [92 {93 "type": "BUSINESS"94 }95 ],96 "bookingPolicy": {97 "revision": "1",98 "name": "Default policy",99 "customPolicyDescription": {100 "enabled": true,101 "description": ""102 },103 "default": true,104 "limitEarlyBookingPolicy": {105 "enabled": false,106 "earliestBookingInMinutes": 10080107 },108 "limitLateBookingPolicy": {109 "enabled": false,110 "latestBookingInMinutes": 1440111 },112 "bookAfterStartPolicy": {113 "enabled": false114 },115 "cancellationPolicy": {116 "enabled": true,117 "limitLatestCancellation": false,118 "latestCancellationInMinutes": 1440119 },120 "reschedulePolicy": {121 "enabled": true,122 "limitLatestReschedule": false,123 "latestRescheduleInMinutes": 1440124 },125 "waitlistPolicy": {126 "enabled": false,127 "capacity": 10,128 "reservationTimeInMinutes": 10129 },130 "participantsPolicy": {131 "enabled": true,132 "maxParticipantsPerBooking": 1133 },134 "resourcesPolicy": {135 "enabled": false,136 "autoAssignAllowed": false137 },138 "_id": "ede8ad9e-44e1-480e-833f-542aea019bd0",139 "_createdDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)",140 "_updatedDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)"141 },142 "schedule": {143 "_id": "8d9560d3-72b9-45c0-a16d-1e73f7d38e11"144 },145 "staffMemberIds": [],146 "staffMembers": [],147 "resourceGroups": [],148 "serviceResources": [],149 "supportedSlugs": [150 {151 "name": "group-cat-hugging",152 "custom": false,153 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"154 }155 ],156 "mainSlug": {157 "name": "group-cat-hugging",158 "custom": false,159 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"160 },161 "urls": {162 "servicePage": "https://www.example.com/services-v2-test/service-page/group-cat-hugging",163 "bookingPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging",164 "calendarPage": "https://www.example.com/services-v2-test/booking-calendar/group-cat-hugging"165 },166 "revision": "1",167 "_id": "1204a214-d1fb-41c8-886a-1ec461b990dd",168 "_createdDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)",169 "_updatedDate": "Tue Jan 16 2024 17:15:30 GMT+0100 (Central European Standard Time)"170 }171 */172