Lấy Danh Sách Danh Mục Shop
API lấy danh sách danh mục sản phẩm của shop cụ thể. Hỗ trợ phân trang, lọc theo loại danh mục (cha/con), và bao gồm thông tin chi tiết về từng danh mục như hình ảnh, mô tả, danh mục con.
GET https://api.socdo.vn/mini-app/v1/list-category-shop
Request Headers
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)
Query Parameters
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ố
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)
Response thành công (200)
{
    "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
        }
    }
}
Response lỗi (401 - Token không hợp lệ)
{
    "message": "Không tìm thấy Token-Seller"
}
Response lỗi (400 - Shop_ID không hợp lệ)
{
    "message": "Shop_ID không hợp lệ"
}
Response lỗi (401 - Token-Seller không hợp lệ)
{
    "message": "Token-Seller hoặc Shop_ID không hợp lệ"
}
Response lỗi (500 - Lỗi database)
{
    "success": false,
    "message": "Lỗi truy vấn database"
}
Ví dụ JavaScript
// 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);
    }
});
Ví dụ cURL
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"
Lưu ý quan trọng
  • Token-Seller Required: API yêu cầu Token-Seller hợp lệ từ API get-token-seller (có thể gửi qua header Token-Seller hoặc Authorization: Bearer)
  • Shop Validation: Token-Seller và Shop_ID phải khớp với nhau trong database
  • Phân trang: Hỗ trợ phân trang với giới hạn tối đa 1000 bản ghi/trang
  • Danh mục con: Có thể bao gồm danh mục con của danh mục cha
  • Đếm sản phẩm: Có thể đếm số sản phẩm trong mỗi danh mục (tùy chọn)
  • Hình ảnh: Tự động tạo URL đầy đủ cho các hình ảnh
  • Icon Data: Xử lý icon dạng hình ảnh hoặc text/font
Luồng xử lý
  1. Kiểm tra Token-Seller từ header Token-Seller hoặc Authorization
  2. Lấy Shop_ID từ query parameter hoặc header Shop-ID
  3. Validate Token-Seller và Shop_ID trong bảng shop
  4. Xây dựng query dựa trên type và các tham số lọc
  5. Thực hiện phân trang và lấy dữ liệu từ category_sanpham_shop
  6. Xử lý thông tin danh mục cha/con và hình ảnh
  7. Trả về kết quả với cấu trúc JSON chuẩn
Các loại danh mục
  • type=all: Lấy tất cả danh mục của shop
  • type=parents: Chỉ lấy danh mục cha (cat_main = 0)
  • type=children: Chỉ lấy danh mục con (cat_main > 0)
Xử lý hình ảnh

API tự động xử lý các loại hình ảnh:

  • image_url: Hình ảnh chính của danh mục (cat_img)
  • banner_image_url: Hình banner của danh mục (cat_img_banner)
  • left_image_url: Hình bên trái của danh mục (cat_img_left)
  • icon_data: Thông tin icon (hình ảnh hoặc text/font)