updateBadge( )


Updates a badge.

The updateBadge() function returns a Promise that resolves to the updated badge.

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.

Method Declaration
Copy
function updateBadge(badgeId: string, badgeInfo: BadgeInfo): Promise<Badge>;
Method Parameters
badgeIdstringRequired

ID of the badge to update.


badgeInfoBadgeInfoRequired

Settings for the updated badge.

Returns
Return Type:Promise<Badge>
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { badges } from "wix-members-backend"; export const myUpdateBadgeFunction = webMethod(Permissions.Anyone, () => { const badgeId = "571495e9-98af-4ec9-b854-16c0293c9312"; const badgeInfo = { title: "Updated Rising Star", description: "Contributed 5... wait, no... 10 posts this month!", backgroundColor: "#FED8B1", textColor: "#000000", icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg", }; return badges .updateBadge(badgeId, 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-20T05:41:55.691Z", * "title": "Updated Rising Star", * "slug": "updated-rising-star", * "description": "Contributed 5... wait, no... 10 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?