Subcategories allow for better classification and filtering of objects.
Subcategories must be created within an existing category and inherit the category’s permissions and settings. Your company is automatically determined from your API key.
Endpoint
curl -X POST "https://api.g2cplatform.com/v2/categories/{CATEGORY_ID}/subcategories" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Smartphones",
"description": "Mobile devices and smartphones",
"image": "base64_encoded_image_data"
}'
Request
HTTP Method
POST
URL
https://api.g2cplatform.com/v2/categories/{CATEGORY_ID}/subcategories
Path Parameters
| Parameter | Type | Required | Description |
|---|
CATEGORY_ID | string (UUID) | ✅ | Parent category identifier |
X-API-Key: YOUR_API_KEY
Content-Type: application/json
Request Body
| Field | Type | Required | Description |
|---|
name | string | ✅ | Subcategory name |
description | string | ❌ | Subcategory description (max 2048 chars) |
image | string (binary) | ❌ | Base64 encoded image data (max 10MB) |
Response
Success Response (200)
{
"status": "success",
"data": {
"id": "sub_7f8a9b2c-4d5e-6f7g-8h9i-0j1k2l3m4n5o"
},
"timestamp": "2025-08-02T10:30:00Z"
}
Error Responses
400 Bad Request
{
"error": "Invalid request data",
"code": "VALIDATION_ERROR",
"details": {
"name": ["Name is required"],
"description": ["Description too long (max 2048 characters)"]
},
"timestamp": "2025-08-02T10:30:00Z"
}
404 Not Found
{
"error": "Category not found",
"code": "CATEGORY_NOT_FOUND",
"timestamp": "2025-08-02T10:30:00Z"
}
Use Cases
Basic Subcategory Creation
async function createSubcategory(categoryId, name, description = null) {
const requestBody = { name };
if (description) {
requestBody.description = description;
}
const response = await fetch(
`https://api.g2cplatform.com/v2/categories/${categoryId}/subcategories`,
{
method: 'POST',
headers: {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
}
);
return response.json();
}
Create Multiple Subcategories
async function createMultipleSubcategories(categoryId, subcategories) {
const results = [];
for (const subcategory of subcategories) {
try {
const result = await createSubcategory(
categoryId,
subcategory.name,
subcategory.description
);
results.push({ success: true, data: result.data, name: subcategory.name });
} catch (error) {
results.push({ success: false, error: error.message, name: subcategory.name });
}
}
return results;
}
// Usage
const subcategories = [
{ name: 'Smartphones', description: 'Mobile devices and smartphones' },
{ name: 'Laptops', description: 'Portable computers and laptops' },
{ name: 'Tablets', description: 'Tablet devices and accessories' }
];
const results = await createMultipleSubcategories(categoryId, subcategories);
Next Steps