Search.../

createBadge( )

Creates a badge.

Description

The createBadge() function returns a Promise that resolves to the newly created badge.

Note: This function replaces the deprecated wix-users-backend.badges.createBadge(). The deprecated function will continue to work, but it will not receive updates. To keep any existing code compatible with future changes, see the migration instructions.

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.

Syntax

function createBadge(badgeInfo: BadgeInfo): Promise<Badge>

createBadge Parameters

NAME
TYPE
DESCRIPTION
badgeInfo
BadgeInfo

Settings for the new badge.

Returns

Fulfilled - New badge. Rejected - Error message.

Return Type:

Promise<Badge>
NAME
TYPE
DESCRIPTION
_id
string

Badge ID.

title
string

Badge title.

slug
string

Badge's unique URL as used in a dynamic page.

description
string

Badge description.

backgroundColor
string

Badge background color as a hexadecimal RGB color value.

Defaults to "#796EFF" (purple).

textColor
string

Badge text color as a hexadecimal RGB color value.

Defaults to "#FFFFFF" (white).

icon
string

Badge icon as an SVG image. One of:

  • An external web URL in the following format: http(s)://<image url>.
  • The source URL for a Wix Media Manager file. Wix Media Manager file names in a wix:image://... format are not supported.
roleId
string

ID of the role that badge members are assigned to.

_createdDate
Date

Date and time the badge was created.

_updatedDate
Date

Date and time the badge was last updated.

Was this helpful?

Create a badge

Copy Code
1import { badges } from 'wix-members-backend';
2
3export function myCreateBadgeFunction() {
4 const badgeInfo = {
5 title: "Rising Star",
6 description: "Contributed 5 posts this month",
7 backgroundColor: "#FED8B1",
8 textColor: "#000000",
9 icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg"
10 };
11
12 return badges.createBadge(badgeInfo)
13 .then((badge) => {
14 const badgeTitle = badge.title;
15 const badgeSlug = badge.slug;
16 return badge;
17 })
18 .catch((error) => {
19 console.error(error);
20 });
21}
22
23/*
24 * Promise resolves to:
25 * {
26 * "_id": "571495e9-98af-4ec9-b854-16c0293c9312",
27 * "_createdDate": "2021-05-20T00:02:18.794Z",
28 * "_updatedDate": "2021-05-20T00:02:18.794Z",
29 * "title": "Rising Star",
30 * "slug": "rising-star",
31 * "description": "Contributed 5 posts this month",
32 * "backgroundColor": "#FED8B1",
33 * "textColor": "#000000",
34 * "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",
35 * "roleId": "571495e9-98af-4ec9-b854-16c0293c9312"
36 * }
37 */
Create a badge using only a title

Copy Code
1import { badges } from 'wix-members-backend';
2
3export function myCreateBadgeFunction() {
4 const badgeInfo = {
5 title: "Community Mod"
6 };
7
8 return badges.createBadge(badgeInfo)
9 .then((badge) => {
10 const badgeTitle = badge.title;
11 const badgeSlug = badge.slug;
12 return badge;
13 })
14 .catch((error) => {
15 console.error(error);
16 });
17}
18
19/*
20 * Promise resolves to:
21 * {
22 * "_id": "236ee192-004b-4a14-a189-1ca2d08fea5d",
23 * "_createdDate": "2021-05-19T23:54:30.862Z",
24 * "_updatedDate": "2021-05-19T23:54:30.862Z",
25 * "title": "Community Mod",
26 * "slug": "community-mod",
27 * "description": "",
28 * "backgroundColor": "#796EFF",
29 * "textColor": "#FFFFFF",
30 * "icon": "",
31 * "roleId": "236ee192-004b-4a14-a189-1ca2d08fea5d"
32 * }
33 */