Shop It Docs
Developer ResourcescatalogCategory

Category Module API & Integration Guide

HTTP contract reference for catalog category admin and customer/mobile APIs.

Audience: Mobile/web frontend developers Scope: Category discovery endpoints

1. How to Read / Quick Metadata

  • Module: Catalog / Category
  • Admin auth: JwtAuthGuard + RoleGuard + @Permissions(Categories_*)
  • Customer/mobile auth: public endpoints (@Public())
  • Surfaces:
    • Admin: /api/admin/categories
    • Customer: /api/categories
    • Mobile: /api/mobile/categories

2. High-Level Overview

Category APIs provide admin hierarchy management and public storefront category reads. Customer slug lookup supports old slug compatibility through slug-history fallback.

3. Core Concepts and Terminology

  • Category hierarchy: self-referential parent-child model.
  • Root category: parentId = null.
  • Visibility flag: isVisible controls storefront inclusion.
  • Slug continuity: old slugs are retained in category_slug_history.

4. Route Summary

MethodPathPermission
GET/api/admin/categoriesCategories_READ
GET/api/admin/categories/:idCategories_READ
POST/api/admin/categoriesCategories_CREATE
PATCH/api/admin/categories/:idCategories_UPDATE
DELETE/api/admin/categories/:idCategories_DELETE
POST/api/admin/categories/reorderCategories_UPDATE
GET/api/categories and /api/mobile/categoriesPublic
GET/api/categories/:slug and /api/mobile/categories/:slugPublic

Route Details

List Categories

AspectDetails
EndpointGET /api/categories or /api/mobile/categories
AuthPublic
Requestpagination, parentId, isVisible
ResponseResponseDto<CategoryDto[]>
Errors-

Category by Slug

AspectDetails
EndpointGET /api/categories/:slug or /api/mobile/categories/:slug
AuthPublic
Request-
ResponseResponseDto<CategoryDto>
Errors404 not found

5. Query Parameters

Admin list (GET /api/admin/categories)

  • Inherited from QueryDto: pagination, page, size, search
  • Filters: parentId, isVisible
  • Sort: name | order | createdAt | updatedAt
  • Order: asc | desc

Customer list (GET /api/categories)

  • Inherited from QueryDto: page, size, search
  • Defaults: pagination=false, sort=name, order=asc, isVisible=true
  • Filters: parentId, optional isVisible override
  • Sort: name | order | createdAt

6. Response Shape Examples

Category item

"
  "id": 1,
  "parentId": null,
  "order": 0,
  "isVisible": true,
"

Reorder payload

"
  "ids": [5, 2, 7, 1]
"

7. Enums

Category module does not define additional DB enums in its DTO contract. Sort allowlists are DTO-level enums/constraints:

  • Admin sort: name | order | createdAt | updatedAt
  • Customer sort: name | order | createdAt
  • Order: asc | desc

8. Integration Diagram

9. Caching

PrefixUsage
catalog:categories:list:customer list cache
catalog:category:slug:customer detail-by-slug cache

Write invalidation on admin create/update/delete/reorder clears category list/slug keyspaces.

10. Error Handling

HTTPerrorCodeCondition
400CATEGORY_SELF_PARENTCategory set as its own parent
400CATEGORY_MOVE_TO_DESCENDANTCategory moved under descendant
400CATEGORY_MISSING_PARENTParent category ID does not exist
400CATEGORY_DEPTH_EXCEEDEDParent chain exceeds depth 3
400CATEGORY_DUPLICATE_IDSReorder request contains duplicate IDs
400CATEGORY_INVALID_SORTUnsupported customer sort field
404CATEGORY_NOT_FOUNDCategory or slug not found
409CATEGORY_HAS_CHILDRENDelete blocked by existing child categories

11. Endpoint Reference + Payload Cheatsheet

11.1 Payload Cheatsheet Table (Every Endpoint)

MethodPathAuth / PermissionRequest DTO / ParamsSuccess DTONotes
GET/api/admin/categoriesAdmin + Categories_READQueryCategoriesAdminDto "" page?, size?, pagination?, search?, parentId?, isVisible?, sort?, order? ""CategoryAdminListItemDto[] paginatedAdmin category list
GET/api/admin/categories/:idAdmin + Categories_READpath: id (int)CategoryAdminDetailDtoAdmin category detail
POST/api/admin/categoriesAdmin + Categories_CREATEbody: CreateCategoryDto "" name, slug, description?, parentId?, order?, isVisible?, imageUrl? ""CategoryAdminDetailDtoCreates new category
PATCH/api/admin/categories/:idAdmin + Categories_UPDATEpath: id (int), body: UpdateCategoryDto "" name?, slug?, description?, parentId?, order?, isVisible?, imageUrl? ""CategoryAdminDetailDtoUpdates category
DELETE/api/admin/categories/:idAdmin + Categories_DELETEpath: id (int)"" success: true ""Deletes category
POST/api/admin/categories/reorderAdmin + Categories_UPDATEbody: ReorderCategoriesDto "" ids: number[] """" success: true ""Reorders categories
GET/api/categoriesPublicQueryCategoriesDto "" page?, size?, parentId?, isVisible?, sort?, order? ""CategoryListItemDto[]Customer category list
GET/api/mobile/categoriesPublicQueryCategoriesDto "" page?, size?, parentId?, isVisible?, sort?, order? ""CategoryListItemDto[]Mobile category list
GET/api/categories/:slugPublicpath: slug (string)CategoryDetailDtoCategory detail by slug (supports historical slugs)
GET/api/mobile/categories/:slugPublicpath: slug (string)CategoryDetailDtoMobile category detail by slug

11.1.1 Admin List Endpoint Query Variations

MethodPathQuery ParametersNotes
GET/api/admin/categories(no params)Default: page=1, size=20, sort=createdAt, order=desc
GET/api/admin/categories?page=2&size=10Custom page and size
GET/api/admin/categories?parentId=1Filter by parent
GET/api/admin/categories?parentId=nullRoot categories only
GET/api/admin/categories?isVisible=trueVisible categories only
GET/api/admin/categories?sort=name&order=ascSort by name ascending
GET/api/admin/categories?sort=order&order=ascSort by order
GET/api/admin/categories?sort=updatedAt&order=descSort by last update
GET/api/admin/categories?isVisible=falseHidden categories

11.1.2 Customer/Mobile List Endpoint Query Variations

MethodPathQuery ParametersNotes
GET/api/categories(no params)Default: no pagination, sort=name, order=asc, isVisible=true
GET/api/categories?page=1&size=10Paginated request
GET/api/categories?parentId=1Child categories of parent 1
GET/api/categories?parentId=nullRoot categories only
GET/api/categories?isVisible=trueExplicit visible filter
GET/api/categories?isVisible=falseHidden categories
GET/api/categories?sort=name&order=ascSort by name
GET/api/categories?sort=order&order=ascSort by display order
GET/api/categories?sort=createdAt&order=descSort by creation date
GET/api/mobile/categories?parentId=1&isVisible=trueMobile: visible children of parent 1

11.1.3 Category Detail Query Variations

MethodPathPath/Query ParametersNotes
GET/api/categories/old-slugslug=old-slugHistorical slug fallback
GET/api/mobile/categories/tradingslug=tradingMobile slug lookup

11.1.4 Create Category Request Variations

MethodPathRequest BodyNotes
POST/api/admin/categories"" "name": "Books", "slug": "books", "isVisible": true, "order": 0 ""With visibility and order
POST/api/admin/categories"" "name": "Newsletters", "slug": "newsletters", "imageUrl": "https://cdn.example.com/newsletter.jpg" ""With image

11.1.5 Update Category Request Variations

MethodPathRequest BodyNotes
PATCH/api/admin/categories/1"" "name": "Updated Name" ""Update name only
PATCH/api/admin/categories/1"" "slug": "new-slug" ""Update slug
PATCH/api/admin/categories/1"" "parentId": 2 ""Move to different parent
PATCH/api/admin/categories/1"" "isVisible": false ""Hide category
PATCH/api/admin/categories/1"" "order": 5 ""Update display order
PATCH/api/admin/categories/1"" "description": "New description" ""Update description

11.1.6 Reorder Categories Request

MethodPathRequest BodyNotes
POST/api/admin/categories/reorder"" "ids": [5, 2, 7, 1, 3] ""Sets order based on array position

11.1.7 Category Hierarchy Constraints

ScenarioConstraintError
Self-parentSet parentId to own IDCATEGORY_SELF_PARENT
Descendant parentSet parentId to descendantCATEGORY_MOVE_TO_DESCENDANT
Missing parentParentId doesn't existCATEGORY_MISSING_PARENT
Depth exceededParent chain > 3 levelsCATEGORY_DEPTH_EXCEEDED
Has childrenDelete category with childrenCATEGORY_HAS_CHILDREN

11.1.8 Error Response Variations

HTTPerrorCodeMessageScenario
400CATEGORY_SELF_PARENTCategory cannot be its own parent.parentId = self.id
400CATEGORY_MOVE_TO_DESCENDANTCannot move category under its descendant.Circular hierarchy
400CATEGORY_MISSING_PARENTParent category not found.Invalid parentId
400CATEGORY_DEPTH_EXCEEDEDCategory depth cannot exceed 3 levels.Parent chain too deep
400CATEGORY_DUPLICATE_IDSDuplicate category IDs in reorder request.ids array has duplicates
400CATEGORY_INVALID_SORTInvalid sort field.Unsupported sort
404CATEGORY_NOT_FOUNDCategory not found.Invalid ID or slug
409CATEGORY_HAS_CHILDRENCannot delete category with existing children.Delete with children

11.1.9 Cache Key Patterns

Cache KeyPatternTTL (seconds)Invalidation
Customer category listcatalog:categories:list:parentId:"parentId"-isVisible:"isVisible"-sort:"sort"-order:"order"600Admin create/update/delete/reorder
Category detail by slugcatalog:category:slug:"slug"600Admin update/delete
Admin category listcatalog:categories:admin:list:pagination:"page"-size:"size"-filters...60Admin mutations

11.1.10 Rate Limit Patterns

Route FamilyKey PatternLimit
Customer listrl:catalog:categories:customer:list-ip:"ip"60 req/min
Customer detailrl:catalog:categories:customer:detail-ip:"ip"120 req/min
Admin listrl:catalog:categories:admin:list-key:"adminId"60 req/min
Admin mutationsrl:catalog:categories:admin:mutate-key:"adminId"30 req/min

11.1.11 DTO Field Reference

CreateCategoryDto

FieldTypeRequiredValidationNotes
namestringYes1-100 charsCategory name
slugstringYes1-100 chars, URL-safeURL slug
descriptionstringNoMax 500 charsCategory description
parentIdnumberNoPositive integerParent category ID
ordernumberNoIntegerDisplay order
isVisiblebooleanNoDefault trueVisibility flag
imageUrlstringNoValid URLCategory image

UpdateCategoryDto

FieldTypeRequiredValidationNotes
namestringNo1-100 charsCategory name
slugstringNo1-100 chars, URL-safeURL slug
descriptionstringNoMax 500 charsCategory description
parentIdnumberNoPositive integerParent category ID
ordernumberNoIntegerDisplay order
isVisiblebooleanNo-Visibility flag
imageUrlstringNoValid URLCategory image

ReorderCategoriesDto

FieldTypeRequiredValidationNotes
idsnumber[]YesMin 1 item, no duplicatesCategory IDs in desired order

QueryCategoriesDto / QueryCategoriesAdminDto

FieldTypeRequiredNotes
pagenumberNoPage number
sizenumberNoPage size
paginationbooleanNoEnable pagination
searchstringNo(admin only) Search query
parentIdnumberNoFilter by parent
isVisiblebooleanNoFilter by visibility
sortstringNoSort field
orderstringNoSort order

12. Testing Scenarios

12.1 Suggested Test Scenarios

  • Admin creates root category, creates child category under it, and hierarchy displays correctly.
  • Admin changes category slug; old slug still resolves via historical slug fallback.
  • Customer list only returns visible categories; hidden categories filtered out.
  • Customer requests child categories by parentId; returns only direct children.
  • Admin attempts to set category as its own parent; receives 400 CATEGORY_SELF_PARENT.
  • Admin attempts to move category under its descendant; receives 400 CATEGORY_MOVE_TO_DESCENDANT.

See Also