Search.../

updateService( )

Developer Preview

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.

Admin Method

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
_id
string

Service ID.

service
UpdateService

Returns

The updated service.

Return Type:

Promise<
Service
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the service was created.

_id
string

Service ID.

_updatedDate
Date

Date and time the service was updated.

bookingPolicy
BookingPolicy

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.

category
V2Category

The category the service is associated with.

conferencing
Conferencing

Conferencing options for this service.

defaultCapacity
number

Default maximum number of customers that can book the service. The service cannot be booked beyond this capacity.

description
string

Service description, such as High-class hair styling, cuts, straightening and color.

extendedFields
ExtendedFields

Extensions enabling users to save custom data related to the service.

form
Form

The form used when booking the service.

hidden
boolean

Whether the service is hidden from the site.

locations
Array<
Location
>

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.

mainSlug
Slug

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
Media

Media associated with the service.

name
string

Service name.

onlineBooking
OnlineBooking

Online booking settings.

payment
Payment

Payment options for booking the service.

revision
string

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.

schedule
Schedule

The service's schedule, which can be used to manage the service's sessions.

seoData
SeoSchema

Custom SEO data for the service.

sortOrder
number

Order of a service within a category.

staffMemberIds
Array<
string
>

IDs of the staff members providing the service. For appointments only.

supportedSlugs
Array<
Slug
>

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.

tagLine
string

Short service description, such as Hair styling.

type
string

Service type.

Supported Values:

  • "APPOINTMENT"
  • "CLASS"
  • "COURSE"
urls
URLs

URLs to various service-related pages, such as the calendar page and the booking page.

Was this helpful?

Update a service with a full update

Update a service given the entire service, with the changes applied.

Copy Code
1import { services } from 'wix-bookings.v2';
2
3async 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: false
23 },
24 },
25 onlineBooking: {
26 enabled: true
27 },
28 }
29
30 const newName = "Cat Hugging Training - Advanced";
31 const createdService = await services.createService(serviceToBeCreated);
32 const updatedService = await services.updateService(createdService._id, {...createdService, name: newName});
33
34 console.log('Success! Updated a service:', updatedService);
35
36 return updatedService;
37}
38
39/* 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": false
61 },
62 "pricingPlanIds": []
63 },
64 "onlineBooking": {
65 "enabled": true
66 },
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": 10080
83 },
84 "limitLateBookingPolicy": {
85 "enabled": false,
86 "latestBookingInMinutes": 1440
87 },
88 "bookAfterStartPolicy": {
89 "enabled": false
90 },
91 "cancellationPolicy": {
92 "enabled": true,
93 "limitLatestCancellation": false,
94 "latestCancellationInMinutes": 1440
95 },
96 "reschedulePolicy": {
97 "enabled": true,
98 "limitLatestReschedule": false,
99 "latestRescheduleInMinutes": 1440
100 },
101 "waitlistPolicy": {
102 "enabled": false,
103 "capacity": 10,
104 "reservationTimeInMinutes": 10
105 },
106 "participantsPolicy": {
107 "enabled": true,
108 "maxParticipantsPerBooking": 1
109 },
110 "resourcesPolicy": {
111 "enabled": false,
112 "autoAssignAllowed": false
113 },
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 with a partial update

Update a service given only the fields that need to be updated. For example, update only the service name.

Copy Code
1import { services } from 'wix-bookings.v2';
2
3/*
4 * Sample serviceId value: 'ff61204b-b19a-5cc8-823b-7eed8ae5fc28'
5 * Sample serviceName value: 'Cat Hugging Training - Advanced'
6 * Sample serviceRevision value: 1
7 */
8async function updateServiceName(serviceId, serviceName, serviceRevision) {
9 const updatedService = await services.updateService(serviceId, {
10 id: serviceId, name: serviceName, revision: serviceRevision
11 });
12
13 console.log('Success! Updated the service name:', updatedService, serviceName);
14
15 return updatedService;
16}
17
18/* 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": false
40 },
41 "pricingPlanIds": []
42 },
43 "onlineBooking": {
44 "enabled": true
45 },
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": 10080
62 },
63 "limitLateBookingPolicy": {
64 "enabled": false,
65 "latestBookingInMinutes": 1440
66 },
67 "bookAfterStartPolicy": {
68 "enabled": false
69 },
70 "cancellationPolicy": {
71 "enabled": true,
72 "limitLatestCancellation": false,
73 "latestCancellationInMinutes": 1440
74 },
75 "reschedulePolicy": {
76 "enabled": true,
77 "limitLatestReschedule": false,
78 "latestRescheduleInMinutes": 1440
79 },
80 "waitlistPolicy": {
81 "enabled": false,
82 "capacity": 10,
83 "reservationTimeInMinutes": 10
84 },
85 "participantsPolicy": {
86 "enabled": true,
87 "maxParticipantsPerBooking": 1
88 },
89 "resourcesPolicy": {
90 "enabled": false,
91 "autoAssignAllowed": false
92 },
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