Search...
listBadges( )
Lists the badges.
Description
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.
Syntax
function listBadges(options: ListBadgesOptions): Promise<ListBadgesResponse>
listBadges Parameters
NAME
TYPE
DESCRIPTION
options
Optional
ListBadgesOptions
Returns
Return Type:
Promise<
ListBadgesResponse
>NAME
TYPE
DESCRIPTION
badges
Array<
Badge
>List of badges.
metadata
PagingMetadata
Metadata for the paginated results.
Was this helpful?
Lists all badges.
Copy Code
1import { badges } from 'wix-members.v2';2import { elevate } from 'wix-auth';34/* Sample options value:5 * {6 * paging: {7 * limit: 3,8 * offset: 09 * }10 * }11 */1213export async function myListBadgesFunction (options) {14 try {15 const elevatedListBadges = elevate(badges.listBadges);16 const myBadges = await elevatedListBadges(options);1718 console.log('List of badges: ', myBadges)19 return myBadges;20 } catch (error) {21 console.error(error);22 // Handle the error2324 }25}26/* Promise resolves to:27 * {28 * "badges": [29 * {30 * "_createdDate": "2024-01-18T13:53:11.659Z",31 * "_id": "b657b857-774a-4dde-9b0e-f364d61092ea",32 * "_updatedDate": "2024-01-18T13:53:11.659Z",33 * "backgroundColor": "#796EFF",34 * "description": "Completed challenging tasks and achieved milestones.",35 * "icon": "https://static.wixstatic.com/shapes/11062b_30b982c4ceb141d884fa15ecfb07d26c.svg",36 * "permissionsEnabled": false,37 * "slug": "achievement-unlocked",38 * "textColor": "#FFFFFF",39 * "title": "Achievement Unlocked"40 * },41 * {42 * "_createdDate": "2024-01-18T13:53:37.067Z",43 * "_id": "e80fed60-687e-4b91-a24c-252c4b32227b",44 * "_updatedDate": "2024-01-18T13:53:37.067Z",45 * "backgroundColor": "#FF5C79",46 * "description": "Recognized for outstanding community contributions and leadership.",47 * "icon": "https://static.wixstatic.com/shapes/cb523e8b3f9b4908b85a4a1c577af32b.svg",48 * "permissionsEnabled": false,49 * "slug": "community-hero",50 * "textColor": "#FFFFFF",51 * "title": "Community Hero"52 * },53 * {54 * "_createdDate": "2024-01-18T10:27:14.878Z",55 * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",56 * "_updatedDate": "2024-01-18T10:27:14.878Z",57 * "backgroundColor": "#13785C",58 * "description": "Most comments on site.",59 * "icon": "https://static.wixstatic.com/shapes/11062b_73d6472a03884c758f9d39f83a1218c2.svg",60 * "permissionsEnabled": false,61 * "slug": "top-commenter",62 * "textColor": "#FFFFFF",63 * "title": "Top commenter"64 * }65 * ],66 * "metadata": {67 * "count": 3,68 * "offset": 0,69 * "tooManyToCount": false,70 * "total": 371 * }72 * }73 */
Lists all badges. (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 options value:6 * {7 * paging: {8 * limit: 3,9 * offset: 010 * }11 * }12 */1314export const myListBadgesFunction = webMethod(Permissions.Anyone, async (options) => {15 try {16 const elevatedListBadges = elevate(badges.listBadges);17 const myBadges = await elevatedListBadges(options);1819 console.log('List of badges: ', myBadges)20 return myBadges;21 } catch (error) {22 console.error(error);23 // Handle the error2425 }26});27/* Promise resolves to:28 * {29 * "badges": [30 * {31 * "_createdDate": "2024-01-18T13:53:11.659Z",32 * "_id": "b657b857-774a-4dde-9b0e-f364d61092ea",33 * "_updatedDate": "2024-01-18T13:53:11.659Z",34 * "backgroundColor": "#796EFF",35 * "description": "Completed challenging tasks and achieved milestones.",36 * "icon": "https://static.wixstatic.com/shapes/11062b_30b982c4ceb141d884fa15ecfb07d26c.svg",37 * "permissionsEnabled": false,38 * "slug": "achievement-unlocked",39 * "textColor": "#FFFFFF",40 * "title": "Achievement Unlocked"41 * },42 * {43 * "_createdDate": "2024-01-18T13:53:37.067Z",44 * "_id": "e80fed60-687e-4b91-a24c-252c4b32227b",45 * "_updatedDate": "2024-01-18T13:53:37.067Z",46 * "backgroundColor": "#FF5C79",47 * "description": "Recognized for outstanding community contributions and leadership.",48 * "icon": "https://static.wixstatic.com/shapes/cb523e8b3f9b4908b85a4a1c577af32b.svg",49 * "permissionsEnabled": false,50 * "slug": "community-hero",51 * "textColor": "#FFFFFF",52 * "title": "Community Hero"53 * },54 * {55 * "_createdDate": "2024-01-18T10:27:14.878Z",56 * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",57 * "_updatedDate": "2024-01-18T10:27:14.878Z",58 * "backgroundColor": "#13785C",59 * "description": "Most comments on site.",60 * "icon": "https://static.wixstatic.com/shapes/11062b_73d6472a03884c758f9d39f83a1218c2.svg",61 * "permissionsEnabled": false,62 * "slug": "top-commenter",63 * "textColor": "#FFFFFF",64 * "title": "Top commenter"65 * }66 * ],67 * "metadata": {68 * "count": 3,69 * "offset": 0,70 * "tooManyToCount": false,71 * "total": 372 * }73 * }74 */