Creates a category.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createCategory(category: Category): Promise<Category>;
Category to create.
import { categories } from "wix-events.v2";
import { webMethod, Permissions } from "wix-web-module";
import { elevate } from "wix-auth";
const elevatedCreateCategory = elevate(categories.createCategory);
/*
* Sample category value:
* {
* "name": "leather",
* "states": ["MANUAL"]
* }
*/
export const myCreateCategoryFunction = webMethod(
Permissions.Anyone,
async (category) => {
try {
const createdCategory = await elevatedCreateCategory(category);
console.log("Created category: ", createdCategory);
return createdCategory;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
/* Promise resolves to:
* {
* "name": "leather",
* "states": [
* "MANUAL"
* ],
* "_id": "7952f110-26fa-45a2-b9eb-d2997784659d",
* "_createdDate": "2024-04-23T11:16:38.455Z"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.