Search.../

assignBadge( )

Assigns a badge to site members.

Description

The assignBadge() function returns a Promise that resolves when the specified badge is assigned to the specified members.

The badgeId parameter 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 assignBadge(_id: string, memberIds: Array<string>): Promise<AssignBadgeResponse>

assignBadge Parameters

NAME
TYPE
DESCRIPTION
_id
string

Badge ID.

memberIds
Array<
string
>

List of member IDs to assign to the badge.

Returns

Return Type:

Promise<
AssignBadgeResponse
>
NAME
TYPE
DESCRIPTION
memberIds
Array<
string
>

List of member IDs assigned to the badge.

Was this helpful?

Assign a badge.

Copy Code
1import { badges } from 'wix-members.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample id value: 'd5786246-271d-40d1-bbe5-346244e89799'
5 *
6 * Sample memberIds value:
7 * [
8 * '7d368843-6f0c-4037-8d0e-b7e36a8a0c32'
9 * ]
10 */
11
12export async function myAssignBadgeFunction(_id, memberIds) {
13 try {
14 const elevatedAssignBadge = elevate(badges.assignBadge);
15 const membersIdsWithBadge = await elevatedAssignBadge(_id, memberIds);
16
17 console.log('MemberIds with assigned badge: ', membersIdsWithBadge);
18 return membersIdsWithBadge;
19 } catch (error) {
20 console.error(error);
21 // Handle the error
22 }
23}
24
25/* Promise resolves to:
26 * {
27 * "memberIds": [
28 * "7d368843-6f0c-4037-8d0e-b7e36a8a0c32"
29 * ]
30 * }
31 */