Search.../

updateBadge( )

Updates a badge.

Description

The updateBadge() function returns a Promise that resolves to the updated badge.

Only the properties passed in the BadgeInfo object will be updated. All other properties will remain the same.

Because the badge slug is based on the badge title, if you change title, slug is updated accordingly.

badgeId must be an ID from your site's Members/Badges collection. Typically, you retrieve the ID from the collection using a query or through a dataset.

Admin Method

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

Syntax

function updateBadge(_id: string, badge: UpdateBadge): Promise<UpdateBadgeResponse>

updateBadge Parameters

NAME
TYPE
DESCRIPTION
_id
string

Badge ID.

badge
UpdateBadge

Returns

Return Type:

Promise<
UpdateBadgeResponse
>
NAME
TYPE
DESCRIPTION
badge
Badge

Updated badge.

Was this helpful?

Update existing badge.

Copy Code
1import { badges } from 'wix-members.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: '215be5d9-4b32-4861-9eb5-2152930dd0b4'
5 *
6 * Sample badge value:
7 * {
8 * backgroundColor: "#FED8B1",
9 * description: "Contributed 5 posts this month",
10 * icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",
11 * textColor: "#000000",
12 * title: "Rising Star"
13 * }
14 */
15
16export async function myUpdateBadgeFunction(_id, badge) {
17 try {
18 const elevatedUpdateBadge = elevate(badges.updateBadge);
19 const updateBadge = await elevatedUpdateBadge(_id, badge);
20
21 console.log('Updated badge:', updateBadge);
22 return updateBadge;
23 } catch (error) {
24 console.error(error);
25 // Handle the error
26 }
27
28}
29
30/* Promise resolves to:
31 * {
32 * "_createdDate": "2024-01-18T10:27:14.878Z",
33 * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",
34 * "_updatedDate": "2024-01-18T14:50:36.174Z",
35 * "backgroundColor": "#FED8B1",
36 * "description": "Contributed 5 posts this month",
37 * "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",
38 * "permissionsEnabled": true,
39 * "slug": "super-contributor",
40 * "textColor": "#000000",
41 * "title": "Rising Star"
42 * }
43 */