# 分类

# 创建分类

# 接口调用说明:

POST https://lxapi.lexiangla.com/cgi-bin/v1/categories

# 请求document

{
    "data": {
        "type": "category",
        "attributes": {
            "name": "API新建分类",
            "target_type": "doc",
            "weight": 10
        },
        "relationships": {
            "parent": {
                "data": {
                    "type": "category",
                    "id": "3dc335a852dc11e6b49a0800278acc25"
                }
            }
        }
    }
}

# 参数说明:

参数 是否必须 默认值 说明
name 分类名称
target_type 分类所属模块,支持:doc、thread、team、class、course、event、album。
doc 表示文档,thread 表示论坛,team 表示K吧,class 表示课程,course 表示课程素材,event 表示活动,exam 表示考试,album表示相册
weight 0 用于分类排序,越小越优先展示
parent 父分类

# SDK封装方法使用示例:

$attributes = [
    'name' => 'API新建分类',
    'target_type' => 'doc'
];
$options = [
    'parent_id' => '3dc335a852dc11e6b49a0800278acc25',
    'weight' => 10
];

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->postCategory(StaffID, $attributes, $options);

# 响应document

# 201 Created 状态码
{
    "data": {
        "type": "category",
        "id": "a4beb36a534b11edb13c825f1ee115a3",
        "attributes": {
            "name": "API新建分类",
            "weight": 10
        }
    }
}

# 更新分类

# 接口调用说明:

PATCH https://lxapi.lexiangla.com/cgi-bin/v1/categories/{category_id}

# 请求document

{
    "data": {
        "type": "category",
        "attributes": {
            "name": "API新建更新分类",
            "weight":100
        }
    }
}

# 参数说明:

参数 是否必须 默认值 说明
category_id 分类id
category.name 分类名称

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$attributes = [
    'name' => 'API新建分类_putw',
];
$response = $Lxapi->patchCategory('StaffID','ef380b7ca67911e89a9f10e7c61c70fc', $attributes);

# 响应document

# 200 OK 状态码
{
    "data": {
        "type": "category",
        "id": "b485e9d0f00711e9a9795254009b5a66",
        "attributes": {
            "name": "API更新分类"
        }
    }
}
# 400 Bad Request 状态码
{
    "errors": {
        "detail": "该分类已存在"
    }
}

# 删除分类

# 接口调用说明:

DELETE https://lxapi.lexiangla.com/cgi-bin/v1/categories/{category_id}

# 参数说明:

参数 是否必须 默认值 说明
category_id 分类id

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$response = $Lxapi->deleteCategory('StaffID','ef380b7ca67911e89a9f10e7c61c70fc');

# 响应document

# 204 No Content 状态码
[]
# 404 Not Found 状态码
{
    "errors": {
        "detail": "不存在ID为`fab2ec5eefef11e99cb65254009b5a66`的category资源"
    }
}

# 获取分类列表

可以获取应用的分类属性,用于设置实体的 category_id 属性

# 接口调用说明:

GET https://lxapi.lexiangla.com/cgi-bin/v1/categories

# 参数说明:

支持分页参数和排序:(通用说明?

支持时间范围过滤

参数 是否必须 默认值 说明
target_type 需要获取分类列表的应用类型,支持:doc、thread、class、course、team、event、roadmap、album。
doc 表示文档,thread 表示论坛,class表示课程,course表示课堂素材,team 表示K吧,event 表示活动, roadmap 表示项目,exam 表示考试;
k吧自定义开课分类:team_id传值k吧id,且target_type:class
k吧自定义素材分类:team_id传入k吧id,且target_type:course
k吧自定义相册分类:team_id传入k吧id,且target_type:album
parent_id 父分类id,为空时默认拉取第一级分类,若要拉取次级分类需要添加此参数
team_id k吧id,当需要查询自定义k吧课堂和素材分类时传入

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->get('categories', [
    'target_type' => 'doc',
    // 'parent_id' => '3dc35dda52dc11e6ae140800278acc25',
]);

# 响应document

# 200 OK 状态码
{
    "data":[
        {
            "type":"category",
            "id":"3dc335a852dc11e6b49a0800278acc25",
            "attributes":{
                "name":"技术运维",
                "weight":0
            },
            "meta":{
                "children_count":"0"
            }
        },
        {
            "type":"category",
            "id":"3dc35dda52dc11e6ae140800278acc25",
            "attributes":{
                "name":"产品市场",
                "weight":0
            },
            "meta":{
                "children_count":"2"
            }
        },
        {
            "type":"category",
            "id":"3dc38ce252dc11e6a16f0800278acc25",
            "attributes":{
                "name":"设计用研",
                "weight":0
            },
            "meta":{
                "children_count":"0"
            }
        },
        {
            "type":"category",
            "id":"3dc3e2dc52dc11e695060800278acc25",
            "attributes":{
                "name":"质量管理",
                "weight":10
            },
            "meta":{
                "children_count":"0"
            }
        },
        {
            "type":"category",
            "id":"3dc3f7e052dc11e690ef0800278acc25",
            "attributes":{
                "name":"企管文化",
                "weight":0
            },
            "meta":{
                "children_count":"0"
            }
        },
        {
            "type":"category",
            "id":"3dc4337252dc11e693940800278acc25",
            "attributes":{
                "name":"其他",
                "weight":0
            },
            "meta":{
                "children_count":"0"
            }
        }
    ]
}

# 参数说明:

参数 说明
data.id 分类id
data.attributes.name 分类名称
data.attributes.weight 分类排序,越小越优先展示
data.meta.children_count 当前分类下子分类数量

# 获取分类详情信息

# 接口调用说明:

GET https://lxapi.lexiangla.com/cgi-bin/v1/categories/{category_id}

# 参数说明:

参数 是否必须 默认值 说明
category_id 分类id

# 响应document

# 204 No Content 状态码
{
    "data": {
        "type": "category",
        "id": "926f1deefbd711eaa44f22f21195fed5",
        "attributes": {
            "name": "入职须知",
            "weight": 10         
        },
        "relationships": {
            "parent": {
                "data": {
                    "type": "category",
                    "id": "926ed9a6fbd711ea92e222f21195fed5"
                }
            }
        }
    },
    "included": [
        {
            "type": "category",
            "id": "926ed9a6fbd711ea92e222f21195fed5",
            "attributes": {
                "name": "开课分类"
            }
        }
    ]
}

# 参数说明:

参数 说明
data.id 分类id
data.attributes.name 分类名称
data.attributes.weight 分类排序,越小越优先展示
data.meta.children_count 当前分类下子分类数量
data.relationships.parent 父分类
# 404 Not Found 状态码
{
    "errors": {
        "detail": "不存在ID为`fab2ec5eefef11e99cb65254009b5a66`的category资源"
    }
}