Lists the badges.
The listBadges
function returns a Promise that resolves when the badges are retrieved. Retrieves up to 1000 badges, given the requested paging. Default paging.limit is 100, paging.offset - 0.
This function is not a universal function and runs only on the backend.
function listBadges(options: ListBadgesOptions): Promise<ListBadgesResponse>;
import { badges } from "wix-members.v2";
import { elevate } from "wix-auth";
/* Sample options value:
* {
* paging: {
* limit: 3,
* offset: 0
* }
* }
*/
export async function myListBadgesFunction(options) {
try {
const elevatedListBadges = elevate(badges.listBadges);
const myBadges = await elevatedListBadges(options);
console.log("List of badges: ", myBadges);
return myBadges;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "badges": [
* {
* "_createdDate": "2024-01-18T13:53:11.659Z",
* "_id": "b657b857-774a-4dde-9b0e-f364d61092ea",
* "_updatedDate": "2024-01-18T13:53:11.659Z",
* "backgroundColor": "#796EFF",
* "description": "Completed challenging tasks and achieved milestones.",
* "icon": "https://static.wixstatic.com/shapes/11062b_30b982c4ceb141d884fa15ecfb07d26c.svg",
* "permissionsEnabled": false,
* "slug": "achievement-unlocked",
* "textColor": "#FFFFFF",
* "title": "Achievement Unlocked"
* },
* {
* "_createdDate": "2024-01-18T13:53:37.067Z",
* "_id": "e80fed60-687e-4b91-a24c-252c4b32227b",
* "_updatedDate": "2024-01-18T13:53:37.067Z",
* "backgroundColor": "#FF5C79",
* "description": "Recognized for outstanding community contributions and leadership.",
* "icon": "https://static.wixstatic.com/shapes/cb523e8b3f9b4908b85a4a1c577af32b.svg",
* "permissionsEnabled": false,
* "slug": "community-hero",
* "textColor": "#FFFFFF",
* "title": "Community Hero"
* },
* {
* "_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"
* }
* ],
* "metadata": {
* "count": 3,
* "offset": 0,
* "tooManyToCount": false,
* "total": 3
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.