Search...
getBadge( )
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';34/* Sample _id value: '50dca3d3-f142-44ca-87e9-d9302e1d4dd5' */56 export async function myGetBadgeFunction(_id) {7 try {8 const elevatedGetBadge = elevate(badges.getBadge);9 const badge = await elevatedGetBadge(_id);1011 console.log('Retrieved badge: ', badge);12 return badge;13 } catch (error) {14 console.error(error);15 // Handle the error1617 }18 }1920/* 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 */
Get badge details. (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { badges } from 'wix-members.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '50dca3d3-f142-44ca-87e9-d9302e1d4dd5' */67export const myGetBadgeFunction = webMethod(Permissions.Anyone, async (_id) => {8 try {9 const elevatedGetBadge = elevate(badges.getBadge);10 const badge = await elevatedGetBadge(_id);1112 console.log('Retrieved badge: ', badge);13 return badge;14 } catch (error) {15 console.error(error);16 // Handle the error17 }18});1920/* 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 */34