updateBadge( )
Updates a badge.
Description
The updateBadge()
function returns a Promise
that resolves to the updated badge.
Note: This function replaces the deprecated
wix-users-backend.badges.updateBadge()
. 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.
Only the properties passed in the BadgeInfo
object will be updated. All other properties will remain the same.
Because the badge slug
is based on the badge title
,
if you change title
, slug
is updated accordingly.
badgeId
must be an ID from your site's
Members/Badges
collection.
Typically, you retrieve the ID from the collection using a query or through a dataset.
Syntax
function updateBadge(badgeId: string, badgeInfo: BadgeInfo): Promise<Badge>
updateBadge Parameters
NAME
TYPE
DESCRIPTION
ID of the badge to update.
Settings for the updated badge.
Returns
Fulfilled - Updated 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 myUpdateBadgeFunction() {4 const badgeId = "571495e9-98af-4ec9-b854-16c0293c9312"5 const badgeInfo = {6 title: "Updated Rising Star",7 description: "Contributed 5... wait, no... 10 posts this month!",8 backgroundColor: "#FED8B1",9 textColor: "#000000",10 icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg"11 };1213 return badges.updateBadge(badgeId, badgeInfo)14 .then((badge) => {15 const badgeTitle = badge.title;16 const badgeSlug = badge.slug;17 return badge;18 })19 .catch((error) => {20 console.error(error);21 });22}2324/*25 * Promise resolves to:26 * {27 * "_id": "571495e9-98af-4ec9-b854-16c0293c9312",28 * "_createdDate": "2021-05-20T00:02:18.794Z",29 * "_updatedDate": "2021-05-20T05:41:55.691Z",30 * "title": "Updated Rising Star",31 * "slug": "updated-rising-star",32 * "description": "Contributed 5... wait, no... 10 posts this month!",33 * "backgroundColor": "#FED8B1",34 * "textColor": "#000000",35 * "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",36 * "roleId": "571495e9-98af-4ec9-b854-16c0293c9312"37 * }38 */
1import { badges } from 'wix-members-backend';23export function myUpdateBadgeFunction() {4 const badgeId = "95fad9e6-d4dc-4d84-98a2-ae8660cce599";5 const badgeInfo = {6 title: "Fancypants New Title"7 };89 return badges.updateBadge(badgeId, badgeInfo)10 .then((badge) => {11 const badgeTitle = badge.title;12 const badgeSlug = badge.slug;13 return badge;14 })15 .catch((error) => {16 console.error(error);17 });18}1920/*21 * Promise resolves to:22 * {23 * "_id": "95fad9e6-d4dc-4d84-98a2-ae8660cce599",24 * "_createdDate": "2021-05-06T12:53:57.984Z",25 * "_updatedDate": "2021-05-20T05:44:50.199Z",26 * "title": "Fancypants New Title",27 * "slug": "fancypants-new-title",28 * "description": "",29 * "backgroundColor": "#796EFF",30 * "textColor": "#FFFFFF",31 * "icon": "",32 * "roleId": "95fad9e6-d4dc-4d84-98a2-ae8660cce599"33 * }34 */