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.

Authentication
  • When developing websites or building an app with Blocks, this method may require elevated permissions, depending on the identity of the user calling it and the calling user’s permissions.
  • When building apps without Blocks or for headless projects, you can only call this method directly when authenticated as a Wix app or Wix user identity. When authenticated as a different identity, you can call this method using elevation.
  • Elevation permits users to call methods they typically cannot access. Therefore, you should only use it intentionally and securely.
Permissions
Manage Badges
Learn more about app permissions.
Method Declaration
Copy
function createBadge(badge: Badge): Promise<Badge>;
Method Parameters
badgeBadgeRequired

Badge to create.

Returns
Return Type:Promise<Badge>
JavaScript
import { badges } from "@wix/members"; /* 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" * } */
Errors

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

Did this help?