Introduction
Â
The Badges API enables you to create badges on your website, and assign them to site members, either from your site dashboard, or from your live site. Badges are set up in your site dashboard. Wix does not provide preset badges.
Badges assigned to specific site members help them stand out from other members. You can use badges to create specific categories of members within your site.
With the Badges API, you can customize how badges are created and assigned, including, for example, automating creation of specific categories of members who will recieve a given badge, or delegating assignment of badges to site members themselves.
Learn more about member badges.
Terminology
- Badge: a visible label to be displayed on a site member's profile. A badge has a name (mandatory), an icon, and a background color.
Before you begin
-
Badge permissions - badges can grant site members special permissions to access specific pages. You can set badge permissions in the Site Members area of the dashboard. Badge permissions can't be set in the API. Site members receive permissions once a permission-granting badge is assigned to them.
-
Member permissions cannot be managed via the badges API. You must set them in the site's dashboard.
Setup
To use the Badges API, install the @wix/members
package using npm or Yarn:
1npm install @wix/members
or
1yarn add @wix/members
Then import { badges }
from @wix/members
:
1import { badges } from '@wix/members'
Assigns a badge to site members.
The assignBadge()
function returns a Promise that resolves when the specified badge is assigned to the specified members.
The badgeId
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.
Permission Scopes
For app development, you must have one of the following permission scopes:function assignBadge(_id: string, memberIds: Array<string>): Promise<AssignBadgeResponse>
Creates a badge.
The createBadge()
function returns a Promise that resolves to the newly created badge.
New badges do not have any badge permissions by default. You can set badge permissions from the Badges page in the Dashboard.
If backgroundColor
or textColor
are not specified, they default to "#796EFF"
(purple) and "#FFFFFF"
(white) respectively.
Permission Scopes
For app development, you must have one of the following permission scopes:function createBadge(badge: Badge): Promise<Badge>
Deletes a badge.
The deleteBadge()
function returns a Promise that resolves when the specified badge is deleted.
The badgeId
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.
Permission Scopes
For app development, you must have one of the following permission scopes:function deleteBadge(_id: string): Promise<void>
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.
Permission Scopes
For app development, you must have one of the following permission scopes:function getBadge(_id: string): Promise<Badge>
Retrieves member count per badge.
The getMemberCountsPerBadge
function returns a Promise that resolves when the member counts of each badge are retrieved.
This function is not a universal function and runs only on the backend.
Permission Scopes
For app development, you must have one of the following permission scopes:function getMemberCountsPerBadge(): Promise<GetMemberCountsPerBadgeResponse>
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.
Permission Scopes
For app development, you must have one of the following permission scopes:function listBadges(options: ListBadgesOptions): Promise<ListBadgesResponse>
Lists the badges assigned to each of the specified site members.
The listBadgesPerMember()
function returns a Promise that resolves to a list of badge IDs associated with each of the specified members.
This function is not a universal function and runs only on the backend.
Permission Scopes
For app development, you must have one of the following permission scopes:function listBadgesPerMember(memberIds: Array<string>): Promise<ListMembersBadgeIdsResponse>
Lists the IDs of all members assigned to a badge.
The listMembersByBadge()
function returns a Promise that resolves to a list of member IDs assigned to the specified badge.
Retrieves up to 1000 site members who have a specified badge. Default paging.limit
is 100, paging.offset
- 0.
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.
Permission Scopes
For app development, you must have one of the following permission scopes:function listMembersByBadge(_id: string, options: ListMembersByBadgeOptions): Promise<ListMembersResponse>
Removes site members from an assigned badge.
The unassignBadge()
function returns a Promise that resolves when the specified members are removed as holders of the specified badge.
The badgeId
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.
Permission Scopes
For app development, you must have one of the following permission scopes:function unassignBadge(_id: string, memberIds: Array<string>): Promise<void>
Updates a badge.
The updateBadge()
function returns a Promise that resolves to the updated badge.
Only the properties passed in the BadgeInfo
object will be updated. All other properties will remain the same.
Because the badge slug
is based on the badge title
, if you change title
, slug
is updated accordingly.
badgeId
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.
Permission Scopes
For app development, you must have one of the following permission scopes:function updateBadge(_id: string, badge: UpdateBadge): Promise<Badge>
Updates badges' display order.
The badgeId
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
Permission Scopes
For app development, you must have one of the following permission scopes:function updateBadgesDisplayOrder(badgeIds: Array<string>): Promise<UpdateBadgesDisplayOrderResponse>