Skip to main content

Categories and Subcategories API

The Categories and Subcategories API allows you to manage the product categorization structure on the Nilo platform. These endpoints are essential for organizing products in the store.

Understanding Categories and Subcategories

Categories and subcategories in Nilo form a hierarchical structure that helps organize products effectively:

  • Categories: Top-level classifications that group related products

    • Can contain multiple subcategories
    • Have properties like name, internal code, weight, and image
    • Can be enabled/disabled to control visibility
    • Used for primary navigation and product organization
  • Subcategories: Second-level classifications within categories

    • Must belong to a parent category
    • Help create more specific product groupings
    • Share similar properties with categories
    • Enable more granular product organization

Important Considerations

  1. Unique Codes: Both categories and subcategories require unique internal codes
  2. Hierarchy: Subcategories must always have a valid parent category
  3. Weight: Used for controlling display order in listings (lower numbers appear first)
  4. Status: Both can be enabled/disabled independently
  5. Images: Categories can have associated images for better visual representation

Single Operations

Categories

Get all categories

GET/category

This endpoint allows you to retrieve all available categories on the platform.

Query Parameters

ParameterTypeRequiredDescription
takenumberNoNumber of items per page (maximum 50, minimum 1, default 50)
pagestringNoPage number (default 1)
enabledbooleanNoFilter by enabled status
cursorstringNoCursor for pagination. First call use 0, then use the cursor from the previous response

Response Codes

CodeDescription
200Successful operation - Categories retrieved
404Not found - Categories not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/category?take=10&page=1&enabled=true",
{
method: "GET",
headers: headers,
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Success Response Example

{
"data": [
{
"name": "Category",
"internalCode": "1235",
"image": "/qa/category/12442.png",
"enabled": true,
"children": [
{
"name": "Children Category",
"internalCode": "1236"
}
]
}
],
"page": {
"pageBased": {
"count": 230
},
"cursorBased": {
"hasNextPage": true,
"hasPreviousPage": false,
"firstCursor": "0",
"lastCursor": "49"
}
}
}

Get a specific category

GET/category/{code}

This endpoint allows you to retrieve the details of a specific category.

Path Parameters

ParameterTypeRequiredDescription
codestringYesCategory code

Response Codes

CodeDescription
200Successful operation - Category retrieved
404Not found - Category not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/category/7234",
{
method: "GET",
headers: headers,
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Success Response Example

{
"name": "Category",
"internalCode": "7234",
"image": "/qa/category/12442.png",
"enabled": true,
"parent": {
"name": "Parent Category",
"internalCode": "1235"
},
"children": [
{
"name": "Children Category",
"internalCode": "1236"
}
]
}

Create a category

POST/category

This endpoint allows you to create a new category on the platform.

Request Body Parameters

ParameterTypeRequiredDescription
namestringYesCategory name
internalCodestringYesInternal category code
weightintegerNoValue used for product positioning in listings (order of appearance)
imagestringNoPublic URL of the category image
Image Management

The image field expects a public and accessible URL. During processing, Nilo will download the image, store it on Nilo servers, and distribute it through a CDN for optimized loading. Use high-quality images - the platform will automatically generate optimized versions for different devices.

Request Body Example

{
"name": "New Category",
"internalCode": "9876",
"weight": 1,
"image": "/qa/category/9876.png"
}

Response Codes

CodeDescription
200Successful operation - Category created
404Not found - Error creating category

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
name: "New Category",
internalCode: "9876",
weight: 1,
image: "/qa/category/9876.png",
};

fetch("https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/category", {
method: "POST",
headers: headers,
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Update a category

PUT/category/{code}

This endpoint allows you to update an existing category.

Path Parameters

ParameterTypeRequiredDescription
codestringYesCategory code

Request Body Parameters

ParameterTypeRequiredDescription
namestringYesCategory name
weightintegerNoValue used for product positioning in listings (order of appearance)
imagestringNoPublic URL of the category image
Image Management

The image field expects a public and accessible URL. During processing, Nilo will download the image, store it on Nilo servers, and distribute it through a CDN for optimized loading.

Request Body Example

{
"name": "Updated Category",
"weight": 2,
"image": "/qa/category/updated.png"
}

Response Codes

CodeDescription
200Successful operation - Category updated
404Not found - Category not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
name: "Updated Category",
weight: 2,
image: "/qa/category/updated.png",
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/category/7234",
{
method: "PUT",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Upsert category

PUT/category

This endpoint allows you to create or update an existing category (upsert).

Request Body Parameters

ParameterTypeRequiredDescription
namestringYesCategory name
internalCodestringYesInternal category code
enabledbooleanYesCategory enabled status
weightintegerNoValue used for product positioning in listings (order of appearance)
imagestringNoPublic URL of the category image
Image Management

The image field expects a public and accessible URL. During processing, Nilo will download the image, store it on Nilo servers, and distribute it through a CDN for optimized loading.

Request Body Example

{
"name": "Upsert Category",
"internalCode": "5678",
"enabled": true,
"weight": 3,
"image": "/qa/category/upsert.png"
}

Response Codes

CodeDescription
200Successful operation - Category updated
404Not found - Category not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
name: "Upsert Category",
internalCode: "5678",
enabled: true,
weight: 3,
image: "/qa/category/upsert.png",
};

fetch("https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/category", {
method: "PUT",
headers: headers,
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Change category status

PUT/category/{code}/status

This endpoint allows you to enable or disable a category.

Path Parameters

ParameterTypeRequiredDescription
codestringYesCategory code

Request Body Parameters

ParameterTypeRequiredDescription
enabledbooleanYesEnabled status (true/false)

Request Body Example

{
"enabled": true
}

Response Codes

CodeDescription
200Successful operation - Status updated
404Not found - Category not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
enabled: true,
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/category/7234/status",
{
method: "PUT",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Subcategories

Create a subcategory

POST/subcategory

This endpoint allows you to create a new subcategory on the platform.

Request Body Parameters

ParameterTypeRequiredDescription
namestringYesSubcategory name
internalCodestringYesInternal subcategory code
parentCategoryInternalCodestringYesInternal code of the parent category
weightintegerNoValue used for product positioning in listings (order of appearance)

Request Body Example

{
"name": "New Subcategory",
"internalCode": "4321",
"parentCategoryInternalCode": "7234",
"weight": 1
}

Response Codes

CodeDescripción
200Successful operation - Subcategory created
404Not found - Error creating subcategory

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
name: "New Subcategory",
internalCode: "4321",
parentCategoryInternalCode: "7234",
weight: 1,
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/subcategory",
{
method: "POST",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Update a subcategory

PUT/subcategory/{code}

This endpoint allows you to update an existing subcategory.

Path Parameters

ParameterTypeRequiredDescription
codestringYesSubcategory code

Request Body Parameters

ParameterTypeRequiredDescripción
namestringYesSubcategory name
parentCategoryInternalCodestringYesInternal code of the parent category
weightintegerNoValue used for product positioning in listings (order of appearance)

Request Body Example

{
"name": "Updated Subcategory",
"parentCategoryInternalCode": "7234",
"weight": 2
}

Response Codes

CodeDescripción
200Successful operation - Subcategory updated
404Not found - Subcategory not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
name: "Updated Subcategory",
parentCategoryInternalCode: "7234",
weight: 2,
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/subcategory/4321",
{
method: "PUT",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Upsert subcategory

PUT/subcategory

This endpoint allows you to create or update an existing subcategory (upsert).

Request Body Parameters

ParameterTypeRequiredDescripción
namestringYesSubcategory name
internalCodestringYesInternal subcategory code
parentCategoryInternalCodestringYesInternal code of the parent category
enabledbooleanYesSubcategory enabled status
weightintegerNoValue used for product positioning in listings (order of appearance)

Request Body Example

{
"name": "Upsert Subcategory",
"internalCode": "8765",
"parentCategoryInternalCode": "7234",
"enabled": true,
"weight": 3
}

Response Codes

CodeDescripción
200Successful operation - Subcategory updated
404Not found - Subcategory not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
name: "Upsert Subcategory",
internalCode: "8765",
parentCategoryInternalCode: "7234",
enabled: true,
weight: 3,
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/subcategory",
{
method: "PUT",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Change subcategory status

PUT/subcategory/{code}/status

This endpoint allows you to enable or disable a subcategory.

Path Parameters

ParameterTypeRequiredDescripción
codestringYesSubcategory code

Request Body Parameters

ParameterTypeRequiredDescripción
enabledbooleanYesEnabled status (true/false)

Request Body Example

{
"enabled": true
}

Response Codes

CodeDescripción
200Successful operation - Status updated
404Not found - Subcategory not found

Example Usage

const headers = {
"x-api-key": "YOUR_API_KEY",
Authorization: "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
};

const data = {
enabled: true,
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/subcategory/4321/status",
{
method: "PUT",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Response Types

Success Response

{
"code": 200,
"message": "Operation successful"
}

Error Response

{
"code": 400,
"message": "Invalid request parameters"
}

Best Practices

  1. Consistent Naming: Use clear, descriptive names for categories and subcategories
  2. Code Structure: Create a logical structure for internal codes to make them easily identifiable
  3. Weight Management: Plan your weight values carefully to maintain desired ordering
  4. Status Control: Use status changes instead of deleting categories
  5. Parent References: Always verify parent category exists before creating subcategories
  6. Image Management: Use high-quality images with public URLs - Nilo will optimize them for different devices

Common Use Cases

  1. Initial Setup

    • Create main categories for your product catalog
    • Set up subcategories within each main category
    • Configure weights for proper display order
  2. Catalog Maintenance

    • Update category names or images
    • Enable/disable categories seasonally
    • Adjust weights to change display order

Security

All API endpoints require two types of authentication:

  1. API Key in header: x-api-key
  2. Authorization token in header: Authorization

Required Permissions

For category and subcategory endpoints, the following permissions are required:

  • For read operations: supplier/category.read
  • For write operations: supplier/category.write