Search.../

updateLoyaltyProgram( )

Developer Preview

Updates the site's loyalty program.

Description

The updateLoyaltyProgram() function returns a Promise that resolves when the loyalty program is updated.

With the updateLoyaltyProgram() function you can update the name of the loyalty program and the details of the collectible points unit. To activate the loyalty program use the activateLoyaltyProgram() function.

Note: Only visitors with Manage Loyalty permissions can update a loyalty program. You can override the permissions with the wix-auth elevate() function.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function updateLoyaltyProgram(loyaltyProgram: LoyaltyProgram): Promise<UpdateLoyaltyProgramResponse>

updateLoyaltyProgram Parameters

NAME
TYPE
DESCRIPTION
loyaltyProgram
LoyaltyProgram

Loyalty program fields to update.

Returns

Return Type:

Promise<
UpdateLoyaltyProgramResponse
>
NAME
TYPE
DESCRIPTION
loyaltyProgram
LoyaltyProgram

Updated loyalty program.

Was this helpful?

Update the loyalty program name and the name of its points (dashboard page code)

Copy Code
1import { programs } from 'wix-loyalty.v2';
2
3/* Sample loyaltyProgram object:
4 * {
5 * name: 'Flower Power Program',
6 * pointDefinition: {
7 * customName: 'Petals'
8 * }
9 * }
10 */
11
12export async function myUpdateLoyaltyProgramFunction(loyaltyProgram) {
13
14 const elevatedUpdateProgram = wixAuth.elevate(programs.updatedLoyaltyProgram)
15
16 try {
17 const updatedLoyaltyProgram = await elevatedUpdateProgram(loyaltyProgram);
18
19 const newName = updatedLoyaltyProgram.loyaltyProgram.name;
20 const newPointsName = updatedLoyaltyProgram.loyaltyProgram.pointDefinition.customName;
21
22 console.log('Success! The names of your loyalty program and its points are now: ', newName, newPointsName);
23
24 return updatedLoyaltyProgram;
25 } catch (error) {
26 console.error(error);
27 }
28}
29
30/* Promise resolves to:
31 * {
32 * "loyaltyProgram": {
33 * "name": "Flower Power Program",
34 * "pointDefinition": {
35 * "customName": "Petals",
36 * "icon": "shapes/8de38e8fe76f4e9f937ae23e9ba1eb04.svg"
37 * },
38 * "status": "ACTIVE",
39 * "_createdDate": "2022-11-07T15:26:12.798Z",
40 * "_updatedDate": "2022-11-09T10:07:08.601Z"
41 * }
42 * }
43 */
44
Update the loyalty program name and the name of its points (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { programs } from 'wix-loyalty.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample loyaltyProgram object:
6 * {
7 * name: 'Flower Power Program',
8 * pointDefinition: {
9 * customName: 'Petals'
10 * }
11 * }
12 */
13
14export const myUpdateLoyaltyProgramFunction = webMethod(Permissions.Anyone, async (loyaltyProgram) => {
15
16 const elevatedUpdateProgram = elevate(programs.updatedLoyaltyProgram)
17
18 try {
19 const updatedLoyaltyProgram = await elevatedUpdateProgram(loyaltyProgram);
20
21 const newName = updatedLoyaltyProgram.loyaltyProgram.name;
22 const newPointsName = updatedLoyaltyProgram.loyaltyProgram.pointDefinition.customName;
23
24 console.log('Success! The names of your loyalty program and its points are now: ', newName, newPointsName);
25
26 return updatedLoyaltyProgram;
27 } catch (error) {
28 console.error(error);
29 }
30});
31
32/* Promise resolves to:
33 * {
34 * "loyaltyProgram": {
35 * "name": "Flower Power Program",
36 * "pointDefinition": {
37 * "customName": "Petals",
38 * "icon": "shapes/8de38e8fe76f4e9f937ae23e9ba1eb04.svg"
39 * },
40 * "status": "ACTIVE",
41 * "_createdDate": "2022-11-07T15:26:12.798Z",
42 * "_updatedDate": "2022-11-09T10:07:08.601Z"
43 * }
44 * }
45 */
46