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. (dashboard page code)

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

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