createCategory( )


Creates a category.

Authentication

This function requires elevated permissions and runs only on the backend and on dashboard pages.

Permissions
Manage Events - all permissions
Learn more about app permissions.
Method Declaration
Copy
function createCategory(category: Category): Promise<Category>;
Method Parameters
categoryCategoryRequired

Category to create.

Returns
Return Type:Promise<Category>
JavaScript
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" * } */
Errors

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

Did this help?