Search.../

getBadge( )

Developer Preview

Retrieves information about a badge.

Description

The getBadge function returns a Promise that resolves when the badge information is retrieved.

The _id 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.

This function is not a universal function and runs only on the backend.

Syntax

function getBadge(_id: string): Promise<GetBadgeResponse>

getBadge Parameters

NAME
TYPE
DESCRIPTION
_id
string

Badge ID.

Returns

Return Type:

Promise<
GetBadgeResponse
>
NAME
TYPE
DESCRIPTION
badge
Badge

Badge.

Was this helpful?

Get badge details.

Copy Code
1import { badges } from 'wix-members.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: '50dca3d3-f142-44ca-87e9-d9302e1d4dd5' */
5
6 export async function myGetBadgeFunction(_id) {
7 try {
8 const elevatedGetBadge = elevate(badges.getBadge);
9 const badge = await elevatedGetBadge(_id);
10
11 console.log('Retrieved badge: ', badge);
12 return badge;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16
17 }
18 }
19
20/* Promise resolves to:
21 * {
22 * "_createdDate": "2024-01-18T10:27:14.878Z",
23 * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",
24 * "_updatedDate": "2024-01-18T10:27:14.878Z",
25 * "backgroundColor": "#13785C",
26 * "description": "Most comments on site.",
27 * "icon": "https://static.wixstatic.com/shapes/11062b_73d6472a03884c758f9d39f83a1218c2.svg",
28 * "permissionsEnabled": false,
29 * "slug": "top-commenter",
30 * "textColor": "#FFFFFF",
31 * "title": "Top commenter"
32 * }
33 */