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.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createBadge(badge: Badge): Promise<Badge>;
Badge to create.
import { badges } from "wix-members-backend";
/* Sample badge value:
* {
* backgroundColor: "#42A5F5",
* description: "Recognized Contributor Badge",
* icon: "http://example.com/badge-icon.svg",
* PermissionsEnabled: true,
* textColor: "#FFFFFF,
* title: "Contributor Badge
* }
* }
*/
export async function myCreateBadgeFunction(badge) {
try {
const newBadge = await badges.createBadge(badge);
console.log("New badge created: ", newBadge);
return newBadge;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "_createdDate": "2024-01-18T13:08:22.116Z",
* "_id": "b025f7a8-9c3e-4f5d-a2e7-8dc1bf3ca0f1",
* "_updatedDate": "2024-01-18T13:08:22.116Z",
* "backgroundColor": "#796EFF",
* "description": "Recognized Contributor",
* "icon": "http://example.com/badge-icon.svg",
* "permissionsEnabled": false,
* "slug": "contributor-badge-1",
* "textColor": "#FFFFFF",
* "title": "Contributor Badge"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.