Linkit

Categories

Hierarchical product categorization with unlimited nesting depth

Categories

Categories organize your product catalog into a hierarchical tree. Each category can have a parent, forming nested paths like Electronics > Phones > Smartphones. Products can be assigned to any category at any level.


The Category Object

{
  "id": "cat_abc123",
  "category_code": "CAT-PHONES",
  "organization_id": "org_abc123",
  "name_en": "Smartphones",
  "name_ar": "هواتف ذكية",
  "parent_id": "cat_electronics",
  "depth": 2,
  "path": "Electronics > Phones > Smartphones",
  "product_count": 150,
  "created": "2024-01-15T10:30:00Z",
  "updated": "2024-01-16T14:22:00Z"
}

Fields

FieldTypeDescription
idstringInternal Linkit ID
category_codestringYour unique identifier
name_enstringCategory name in English
name_arstringCategory name in Arabic
parent_idstringParent category ID (null for root)
depthintegerNesting level (0 = root)
pathstringFull breadcrumb path
product_countintegerNumber of products in this category

List Categories

GET /api/v1/categories

Query Parameters

ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger20Items per page (max 100)
parent_idstring-Filter by parent (use null for root categories)
searchstring-Search in category names

Example Request

curl -X GET "https://linkit.works/api/v1/categories?parent_id=null&limit=50" \
  -H "Authorization: Bearer your_token_here"
const response = await fetch(
  'https://linkit.works/api/v1/categories?parent_id=null&limit=50',
  { headers: { 'Authorization': 'Bearer your_token_here' } }
);
const categories = await response.json();
import requests

response = requests.get(
    'https://linkit.works/api/v1/categories',
    params={'parent_id': 'null', 'limit': 50},
    headers={'Authorization': 'Bearer your_token_here'}
)
categories = response.json()

Get Single Category

GET /api/v1/categories/code/{categoryCode}

Returns the full category object including path and product count.


Create Category

POST /api/v1/categories

Request Body

{
  "category_code": "CAT-NEW",
  "name_en": "New Category",
  "name_ar": "فئة جديدة",
  "parent_id": "cat_parent123"
}

Required Fields

FieldTypeConstraints
category_codestringMax 50 chars, unique per organization

Optional Fields

FieldTypeConstraints
name_enstringMax 255 chars
name_arstringMax 255 chars
parent_idstringMust reference existing category

Setting parent_id places this category as a child. Depth and path are computed automatically.

Response (201 Created)

{
  "success": true,
  "message": "Category created successfully",
  "data": {
    "id": "cat_new123",
    "category_code": "CAT-NEW",
    "depth": 1,
    "path": "Parent > New Category"
  },
  "timestamp": "2024-01-15T10:30:00Z"
}

Update Category

PUT /api/v1/categories/code/{categoryCode}

Full replacement. Include all fields you want to keep.


Move Category

Change a category's parent, which recalculates depth and path for it and all descendants.

PATCH /api/v1/categories/code/{categoryCode}/move

Request Body

{
  "new_parent_id": "cat_other_parent"
}

Set new_parent_id to null to make the category a root node.

Circular reference protection

You cannot move a category under one of its own descendants. The API returns 409 Conflict if this is attempted.


Delete Category

DELETE /api/v1/categories/code/{categoryCode}
ParameterTypeDefaultDescription
forcebooleanfalseDelete even if it has sub-categories or products

Deletion behavior

By default, categories with children or associated products cannot be deleted. With force=true, child categories are re-parented to the deleted category's parent, and products are unassigned.


Error Responses

409 Conflict (Has Children)

{
  "code": 409,
  "error": "Category has sub-categories",
  "details": { "child_count": 5, "hint": "Use force=true to delete anyway" }
}

409 Conflict (Circular Reference)

{
  "code": 409,
  "error": "Circular reference detected",
  "details": { "category_code": "CAT-001", "target_parent": "CAT-003" }
}