Token-Seller: YOUR_TOKEN_SELLER Shop-ID: 31026 (optional, có thể dùng query parameter) Hoặc: Authorization: Bearer YOUR_TOKEN_SELLER Shop-ID: 31026 (optional, có thể dùng query parameter)
GET /list-category-shop?shop_id=31026&type=all&parent_id=0&include_children=1&include_products_count=0&page=1&limit=500
| Tham số | Loại | Bắt buộc | Mô tả |
|---|---|---|---|
Token-Seller |
header | ✓ | Token-Seller từ API get-token-seller (hoặc Authorization: Bearer) |
shop_id |
query/header | ✓ | ID của shop cần lấy danh mục |
type |
query | - | Loại danh mục: 'all', 'parents', 'children' (mặc định: 'all') |
parent_id |
query | - | ID danh mục cha để lấy danh mục con (mặc định: 0) |
include_children |
query | - | Có bao gồm danh mục con không (1: có, 0: không, mặc định: 1) |
include_products_count |
query | - | Có đếm số sản phẩm không (1: có, 0: không, mặc định: 0) |
page |
query | - | Trang hiện tại (mặc định: 1) |
limit |
query | - | Số bản ghi mỗi trang (1-1000, mặc định: 500) |
{
"success": true,
"message": "Lấy danh sách danh mục thành công",
"data": {
"categories": [
{
"id": 14871,
"shop_id": 31026,
"name": "Mũi họng",
"slug": "mui-ho",
"parent_id": 0,
"order": 14,
"icon": "",
"image": "",
"description": "",
"title": "Mũi họng",
"meta_description": "",
"show_on_homepage": 0,
"link": "",
"banner_image": "",
"left_image": "",
"cat_id_socdo": "9,131",
"category_url": "https://socdo.vn/danh-muc/14871/mui-ho.html",
"icon_data": {
"type": "default",
"content": ""
},
"image_url": "",
"banner_image_url": "",
"left_image_url": "",
"is_parent": true,
"level": 1,
"parent_info": null,
"products_count": null,
"children": [],
"children_count": 0,
"badges": []
},
{
"id": 14870,
"shop_id": 23133,
"name": "Mỹ phẩm - Thực phẩm chức năng",
"slug": "my-pham-thuc-pham-chuc-nang",
"parent_id": 0,
"order": 1,
"icon": "",
"image": "",
"description": "",
"title": "Mỹ phẩm - Thực phẩm chức năng",
"meta_description": "",
"show_on_homepage": 0,
"link": "",
"banner_image": "",
"left_image": "",
"cat_id_socdo": "11,207,205",
"category_url": "https://socdo.vn/danh-muc/14870/my-pham-thuc-pham-chuc-nang.html",
"icon_data": {
"type": "default",
"content": ""
},
"image_url": "",
"banner_image_url": "",
"left_image_url": "",
"is_parent": true,
"level": 1,
"parent_info": null,
"products_count": 25,
"children": [
{
"id": 14869,
"name": "Nhu yếu phẩm",
"slug": "nhu-yeu-pham",
"order": 2,
"url": "https://socdo.vn/danh-muc/14869/nhu-yeu-pham.html"
}
],
"children_count": 1,
"badges": []
}
],
"pagination": {
"current_page": 1,
"total_pages": 1,
"total_records": 2,
"per_page": 500,
"has_next": false,
"has_prev": false
},
"filters": {
"type": "all",
"parent_id": 0,
"include_children": 1,
"include_products_count": 0,
"shop_id": 31026
}
}
}
{
"message": "Không tìm thấy Token-Seller"
}
{
"message": "Shop_ID không hợp lệ"
}
{
"message": "Token-Seller hoặc Shop_ID không hợp lệ"
}
{
"success": false,
"message": "Lỗi truy vấn database"
}
// Lấy danh sách danh mục shop
async function getShopCategories(shopId, options = {}) {
try {
const params = new URLSearchParams({
shop_id: shopId,
type: options.type || 'all',
parent_id: options.parent_id || 0,
include_children: options.include_children || 1,
include_products_count: options.include_products_count || 0,
page: options.page || 1,
limit: options.limit || 500
});
const response = await fetch(`https://api.socdo.vn/mini-app/v1/list-category-shop?${params}`, {
method: 'GET',
headers: {
'Token-Seller': localStorage.getItem('seller_token'),
'Shop-ID': shopId
}
});
const result = await response.json();
if (result.success) {
console.log('Danh sách danh mục:', result.data.categories);
console.log('Phân trang:', result.data.pagination);
return result;
} else {
console.error('Lỗi lấy danh mục:', result.message);
return result;
}
} catch (error) {
console.error('Lỗi kết nối:', error);
return { success: false, message: 'Lỗi kết nối mạng' };
}
}
// Sử dụng
getShopCategories(31026, {
type: 'parents',
include_children: 1,
include_products_count: 1
}).then(result => {
if (result.success) {
// Hiển thị danh sách danh mục
result.data.categories.forEach(category => {
console.log(`Danh mục: ${category.name} (${category.children_count} danh mục con)`);
});
} else {
alert('Lỗi: ' + result.message);
}
});
curl -X GET "https://api.socdo.vn/mini-app/v1/list-category-shop?shop_id=31026&type=all&include_children=1" \ -H "Token-Seller: YOUR_TOKEN_SELLER" \ -H "Shop-ID: 31026"
API tự động xử lý các loại hình ảnh: