createBadge( )


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.

Method Declaration
Copy
function createBadge(badgeInfo: BadgeInfo): Promise<Badge>;
Method Parameters
badgeInfoBadgeInfoRequired

Settings for the new badge.

Returns
Return Type:Promise<Badge>
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { badges } from "wix-members-backend"; export const myCreateBadgeFunction = webMethod(Permissions.Anyone, () => { const badgeInfo = { title: "Rising Star", description: "Contributed 5 posts this month", backgroundColor: "#FED8B1", textColor: "#000000", icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg", }; return badges .createBadge(badgeInfo) .then((badge) => { const badgeTitle = badge.title; const badgeSlug = badge.slug; return badge; }) .catch((error) => { console.error(error); }); }); /* * Promise resolves to: * { * "_id": "571495e9-98af-4ec9-b854-16c0293c9312", * "_createdDate": "2021-05-20T00:02:18.794Z", * "_updatedDate": "2021-05-20T00:02:18.794Z", * "title": "Rising Star", * "slug": "rising-star", * "description": "Contributed 5 posts this month", * "backgroundColor": "#FED8B1", * "textColor": "#000000", * "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg", * "roleId": "571495e9-98af-4ec9-b854-16c0293c9312" * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?