getCategory( )


Gets a category by the specified ID.

The getCategory() function returns a Promise that resolves to a category whose ID matches the specified ID.

Permissions
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about app permissions.
Method Declaration
Copy
function getCategory(
  categoryId: string,
  options: GetCategoryOptions,
): Promise<GetCategoryResponse>;
Method Parameters
categoryIdstringRequired

Category ID.


optionsGetCategoryOptions

Options specifying which fields to return.

Returns
Return Type:Promise<GetCategoryResponse>
JavaScript
import { categories } from "wix-blog-backend"; /* Sample categoryId value: * 'f489bf39-3297-4854-8429-e19dbefdca0e' */ export async function getCategoryFunction(categoryId) { try { const result = await categories.getCategory(categoryId); const label = result.category.label; const slug = result.category.slug; console.log("Retrieved Result:", result); return result; } catch (error) { console.error(error); } } /* Promise resolves to: * { * "category": { * "_id": "f489bf39-3297-4854-8429-e19dbefdca0e", * "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245", * "description": "my category description", * "displayPosition": 0, * "label": "My Category", * "language": "en", * "postCount": 1, * "slug": "my-category", * "title": "My Category", * "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e" * } * } */
Errors

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

Did this help?