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.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function updateBadge(_id: string, badge: UpdateBadge): Promise<Badge>;
Badge ID.
import { badges } from "wix-members.v2";
/* Sample _id value: '215be5d9-4b32-4861-9eb5-2152930dd0b4'
*
* Sample badge value:
* {
* backgroundColor: "#FED8B1",
* description: "Contributed 5 posts this month",
* icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",
* textColor: "#000000",
* title: "Rising Star"
* }
*/
export async function myUpdateBadgeFunction(_id, badge) {
try {
const updateBadge = await badges.updateBadge(_id, badge);
console.log("Updated badge:", updateBadge);
return updateBadge;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "_createdDate": "2024-01-18T10:27:14.878Z",
* "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",
* "_updatedDate": "2024-01-18T14:50:36.174Z",
* "backgroundColor": "#FED8B1",
* "description": "Contributed 5 posts this month",
* "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",
* "permissionsEnabled": true,
* "slug": "super-contributor",
* "textColor": "#000000",
* "title": "Rising Star"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.