updateService( )
Updates a service.
Description
Partial updates are supported.
Each time the service is updated, revision
increments by 1. You must include the
number of the existing revision when
updating the service. This ensures you're working with the
latest service information and prevents unintended overwrites.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function updateService(_id: string, service: UpdateService): Promise<Service>
updateService Parameters
NAME
TYPE
DESCRIPTION
Service ID.
Returns
The updated 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?
Update a service given the entire service, with the changes applied.
1import { services } from 'wix-bookings.v2';23async function updateService() {4 const serviceToBeCreated = {5 type: services.ServiceType.APPOINTMENT,6 name: "Cat Hugging Training",7 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.",8 tagLine: "Get some purr therapy training with our cat hugging experts",9 defaultCapacity: 30,10 payment: {11 rateType: services.RateType.FIXED,12 fixed: {13 price: {14 value: "150",15 currency: "USD"16 }17 },18 options: {19 online: true,20 inPerson: false,21 deposit: false,22 pricingPlan: false23 },24 },25 onlineBooking: {26 enabled: true27 },28 }2930 const newName = "Cat Hugging Training - Advanced";31 const createdService = await services.createService(serviceToBeCreated);32 const updatedService = await services.updateService(createdService._id, {...createdService, name: newName});3334 console.log('Success! Updated a service:', updatedService);3536 return updatedService;37}3839/* Promise resolves to:40 * {41 "type": "CLASS",42 "sortOrder": 0,43 "name": "Cat Hugging Training - Advanced",44 "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.",45 "tagLine": "Get some purr therapy training with our cat hugging experts",46 "defaultCapacity": 30,47 "hidden": false,48 "payment": {49 "rateType": "FIXED",50 "fixed": {51 "price": {52 "value": "150",53 "currency": "USD"54 }55 },56 "options": {57 "online": true,58 "inPerson": false,59 "deposit": false,60 "pricingPlan": false61 },62 "pricingPlanIds": []63 },64 "onlineBooking": {65 "enabled": true66 },67 "locations": [68 {69 "type": "BUSINESS"70 }71 ],72 "bookingPolicy": {73 "revision": "1",74 "name": "Default policy",75 "customPolicyDescription": {76 "enabled": true,77 "description": ""78 },79 "default": true,80 "limitEarlyBookingPolicy": {81 "enabled": false,82 "earliestBookingInMinutes": 1008083 },84 "limitLateBookingPolicy": {85 "enabled": false,86 "latestBookingInMinutes": 144087 },88 "bookAfterStartPolicy": {89 "enabled": false90 },91 "cancellationPolicy": {92 "enabled": true,93 "limitLatestCancellation": false,94 "latestCancellationInMinutes": 144095 },96 "reschedulePolicy": {97 "enabled": true,98 "limitLatestReschedule": false,99 "latestRescheduleInMinutes": 1440100 },101 "waitlistPolicy": {102 "enabled": false,103 "capacity": 10,104 "reservationTimeInMinutes": 10105 },106 "participantsPolicy": {107 "enabled": true,108 "maxParticipantsPerBooking": 1109 },110 "resourcesPolicy": {111 "enabled": false,112 "autoAssignAllowed": false113 },114 "_id": "ede8ad9e-44e1-480e-833f-542aea019bd0",115 "_createdDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)",116 "_updatedDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)"117 },118 "schedule": {119 "_id": "8bf39bc0-a05a-49ff-9ee3-fc29d698988d"120 },121 "staffMemberIds": [],122 "staffMembers": [],123 "resourceGroups": [],124 "serviceResources": [],125 "supportedSlugs": [126 {127 "name": "cat-hugging-training-advanced",128 "custom": false,129 "_createdDate": "Wed Jan 17 2024 09:37:28 GMT+0100 (Central European Standard Time)"130 },131 {132 "name": "cat-hugging-training-1",133 "custom": false,134 "_createdDate": "Wed Jan 17 2024 09:37:27 GMT+0100 (Central European Standard Time)"135 }136 ],137 "mainSlug": {138 "name": "cat-hugging-training-advanced",139 "custom": false,140 "_createdDate": "Wed Jan 17 2024 09:37:28 GMT+0100 (Central European Standard Time)"141 },142 "urls": {143 "servicePage": "https://www.example.com/services-v2-test/service-page/cat-hugging-training-advanced",144 "bookingPage": "https://www.example.com/services-v2-test/booking-calendar/cat-hugging-training-advanced",145 "calendarPage": "https://www.example.com/services-v2-test/booking-calendar/cat-hugging-training-advanced"146 },147 "revision": "2",148 "_id": "a262b133-e7a1-4498-a722-8340ed3f3db3",149 "_createdDate": "Wed Jan 17 2024 09:37:27 GMT+0100 (Central European Standard Time)",150 "_updatedDate": "Wed Jan 17 2024 09:37:28 GMT+0100 (Central European Standard Time)"151 }152 */153
Update a service given only the fields that need to be updated. For example, update only the service name.
1import { services } from 'wix-bookings.v2';23/*4 * Sample serviceId value: 'ff61204b-b19a-5cc8-823b-7eed8ae5fc28'5 * Sample serviceName value: 'Cat Hugging Training - Advanced'6 * Sample serviceRevision value: 17 */8async function updateServiceName(serviceId, serviceName, serviceRevision) {9 const updatedService = await services.updateService(serviceId, {10 id: serviceId, name: serviceName, revision: serviceRevision11 });1213 console.log('Success! Updated the service name:', updatedService, serviceName);1415 return updatedService;16}1718/* Promise resolves to:19 * {20 "type": "CLASS",21 "sortOrder": 0,22 "name": "Cat Hugging Training - Advanced",23 "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.",24 "tagLine": "Get some purr therapy training with our cat hugging experts",25 "defaultCapacity": 30,26 "hidden": false,27 "payment": {28 "rateType": "FIXED",29 "fixed": {30 "price": {31 "value": "150",32 "currency": "USD"33 }34 },35 "options": {36 "online": true,37 "inPerson": false,38 "deposit": false,39 "pricingPlan": false40 },41 "pricingPlanIds": []42 },43 "onlineBooking": {44 "enabled": true45 },46 "locations": [47 {48 "type": "BUSINESS"49 }50 ],51 "bookingPolicy": {52 "revision": "1",53 "name": "Default policy",54 "customPolicyDescription": {55 "enabled": true,56 "description": ""57 },58 "default": true,59 "limitEarlyBookingPolicy": {60 "enabled": false,61 "earliestBookingInMinutes": 1008062 },63 "limitLateBookingPolicy": {64 "enabled": false,65 "latestBookingInMinutes": 144066 },67 "bookAfterStartPolicy": {68 "enabled": false69 },70 "cancellationPolicy": {71 "enabled": true,72 "limitLatestCancellation": false,73 "latestCancellationInMinutes": 144074 },75 "reschedulePolicy": {76 "enabled": true,77 "limitLatestReschedule": false,78 "latestRescheduleInMinutes": 144079 },80 "waitlistPolicy": {81 "enabled": false,82 "capacity": 10,83 "reservationTimeInMinutes": 1084 },85 "participantsPolicy": {86 "enabled": true,87 "maxParticipantsPerBooking": 188 },89 "resourcesPolicy": {90 "enabled": false,91 "autoAssignAllowed": false92 },93 "_id": "ede8ad9e-44e1-480e-833f-542aea019bd0",94 "_createdDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)",95 "_updatedDate": "Thu Dec 14 2023 16:14:33 GMT+0100 (Central European Standard Time)"96 },97 "schedule": {98 "_id": "8bf39bc0-a05a-49ff-9ee3-fc29d698988d"99 },100 "staffMemberIds": [],101 "staffMembers": [],102 "resourceGroups": [],103 "serviceResources": [],104 "supportedSlugs": [105 {106 "name": "cat-hugging-training-advanced",107 "custom": false,108 "_createdDate": "Wed Jan 17 2024 09:37:28 GMT+0100 (Central European Standard Time)"109 },110 {111 "name": "cat-hugging-training-1",112 "custom": false,113 "_createdDate": "Wed Jan 17 2024 09:37:27 GMT+0100 (Central European Standard Time)"114 }115 ],116 "mainSlug": {117 "name": "cat-hugging-training-advanced",118 "custom": false,119 "_createdDate": "Wed Jan 17 2024 09:37:28 GMT+0100 (Central European Standard Time)"120 },121 "urls": {122 "servicePage": "https://www.example.com/services-v2-test/service-page/cat-hugging-training-advanced",123 "bookingPage": "https://www.example.com/services-v2-test/booking-calendar/cat-hugging-training-advanced",124 "calendarPage": "https://www.example.com/services-v2-test/booking-calendar/cat-hugging-training-advanced"125 },126 "revision": "2",127 "_id": "a262b133-e7a1-4498-a722-8340ed3f3db3",128 "_createdDate": "Wed Jan 17 2024 09:37:27 GMT+0100 (Central European Standard Time)",129 "_updatedDate": "Wed Jan 17 2024 09:37:28 GMT+0100 (Central European Standard Time)"130 }131 */132