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
Settings for the new badge.
Returns
Fulfilled - New badge. Rejected - Error message.
Return Type:
NAME
TYPE
DESCRIPTION
Badge ID.
Badge title.
Badge's unique URL as used in a dynamic page.
Badge description.
Badge background color as a hexadecimal RGB color value.
Defaults to "#796EFF"
(purple).
Badge text color as a hexadecimal RGB color value.
Defaults to "#FFFFFF"
(white).
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.
ID of the role that badge members are assigned to.
Date and time the badge was created.
Date and time the badge was last updated.
Was this helpful?
1import { badges } from 'wix-members-backend';23export 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 };1112 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}2223/*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 */
1import { badges } from 'wix-members-backend';23export function myCreateBadgeFunction() {4 const badgeInfo = {5 title: "Community Mod"6 };78 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}1819/*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 */