getBadge( )


Retrieves information about a badge.

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.

Permissions
Manage Badges
Read Badges
Learn more about app permissions.
Method Declaration
Copy
function getBadge(_id: string): Promise<Badge>;
Method Parameters
_idstringRequired

Badge ID.

Returns
Return Type:Promise<Badge>
JavaScript
import { badges } from "wix-members.v2"; import { elevate } from "wix-auth"; /* Sample _id value: '50dca3d3-f142-44ca-87e9-d9302e1d4dd5' */ export async function myGetBadgeFunction(_id) { try { const elevatedGetBadge = elevate(badges.getBadge); const badge = await elevatedGetBadge(_id); console.log("Retrieved badge: ", badge); return badge; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "_createdDate": "2024-01-18T10:27:14.878Z", * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4", * "_updatedDate": "2024-01-18T10:27:14.878Z", * "backgroundColor": "#13785C", * "description": "Most comments on site.", * "icon": "https://static.wixstatic.com/shapes/11062b_73d6472a03884c758f9d39f83a1218c2.svg", * "permissionsEnabled": false, * "slug": "top-commenter", * "textColor": "#FFFFFF", * "title": "Top commenter" * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?