# 文件夹

文件夹是用于协助整理文档的一个属性,它不同于分类的定义。

只有K吧才有文件夹的概念,每个K吧可构建自己的文件夹树去放置文档,而全局知识库可理解成有且只有一个文件夹(因此不可创建)。

# 获取文件夹列表

# 接口调用说明

GET https://lxapi.lexiangla.com/cgi-bin/v1/directories?directory_id=directoryId&team_id=teamId

# 参数说明:

参数 是否必须 默认值 说明
directoryId 文件夹ID,不指定时默认为K吧根目录
teamId K吧ID

# 响应document

# 200 OK 状态码
{
    "data": [
        {
            "type": "category",
            "id": "df20bd06831611e7b3719a23ffd8621b",
            "attributes": {
                "name": "事故分析"
            }
        },
        {
            "type": "category",
            "id": "df23b628831611e79680a56a61f29217",
            "attributes": {
                "name": "案例分析"
            }
        },
        {
            "type": "category",
            "id": "df241e1a831611e7a341e8203947a597",
            "attributes": {
                "name": "用户体验"
            }
        },
        {
            "type": "category",
            "id": "df24acd6831611e7a11256d6e4332b2a",
            "attributes": {
                "name": "会议纪要"
            }
        },
        {
            "type": "category",
            "id": "f211ea30e11d11eabdc50242ac150006",
            "attributes": {
                "name": "a"
            }
        },
        {
            "type": "category",
            "id": "f62db6b2e11d11eaa18c0242ac150006",
            "attributes": {
                "name": "b"
            }
        },
        {
            "type": "category",
            "id": "f9d5bac6e11d11eaaad10242ac150006",
            "attributes": {
                "name": "a'a"
            }
        }
    ],
    "links": {
        "first": "http://lxapi.lexiangla.com/cgi-bin/v1/directories?team_id=df1eb1aa831611e78643e529bd527cf3&page=1",
        "last": "http://lxapi.lexiangla.com/cgi-bin/v1/directories?team_id=df1eb1aa831611e78643e529bd527cf3&page=1",
        "prev": null,
        "next": null
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "path": "http://lxapi.swan.local/cgi-bin/v1/directories",
        "per_page": 20,
        "to": 7,
        "total": 7
    }
}
# 400 Bad Request 状态码
{
    "errors": [
        {
            "detail": "{\"team_id\":[\"team id 是无效的.\"]}"
        }
    ]
}

# 创建文件夹

# 接口调用说明:

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

# 请求document

{
    "data": {
        "type": "directory", 
        "attributes": {
            "name": "开放接口创建的文件夹"
        }, 
        "relationships": {
            "team": {
                "data": {
                    "type": "team", 
                    "id": "32a8260cb4cc11e8b44bc3f89d9cfabc"
                }
            }, 
            "parent": {
                "data": {
                    "type": "directory", 
                    "id": "f1572bcecd3711e8b8ee7fe8c886e03c"
                }
            }
        }
    }
}

# 参数说明:

参数 是否必须 默认值 说明
name 文件夹名称
team 所属K吧
parent 父节点,不传入时默认为K吧第一级目录

# SDK封装方法使用示例:

$attributes = [
    'name' => '开放接口创建的文件夹',
    'team_id' => '32a8260cb4cc11e8b44bc3f89d9cfabc',
];
$options = [
    'parent_id' => 'f1572bcecd3711e8b8ee7fe8c886e03c'
];

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

# 响应document

# 201 Created 状态码
{
    "data": {
        "type": "directory", 
        "id": "9a76e154cd3811e8b2b8cfb4fc928df1", 
        "attributes": {
            "name": "开放接口创建的文件夹"
        }
    }
}

# 删除文件夹

# 接口调用说明:

DELETE https://lxapi.lexiangla.com/cgi-bin/v1/directories/{directoryId}

# 参数说明:

参数 是否必须 默认值 说明
directoryId 文件夹ID

# SDK封装方法使用示例:

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

# 响应document

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

# 更新文件夹

# 接口调用说明:

PATCH https://lxapi.lexiangla.com/cgi-bin/v1/directories/{directoryId}

# 请求document

{
    "data": {
    	"type": "directory",
        "attributes": {
            "name": "API更改文件夹"
        }
    }
}

# 参数说明:

参数 是否必须 默认值 说明
directory.name 文件夹名称

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$attributes = [
    'name' => 'API更改文件夹'
];
$response = $Lxapi->patchDirectory('StaffID','ef380b7ca67911e89a9f10e7c61c70fc', $attributes);

# 响应document

# 200 ok 状态码
{
    "data": {
        "type": "directory",
        "id": "c14150406fb711e9a9d25254009b5a66",
        "attributes": {
            "name": "API更改文件夹"
        }
    }
}
# 404 Not Found 状态码
{
    "errors": {
        "detail": "不存在ID为`c14150406fb1e9a9d25254009b5a66`的directory资源"
    }
}

# 移动文件夹内文件

# 接口调用说明:

PATCH https://lxapi.lexiangla.com/cgi-bin/v1/directories/{directoryId}/move

# 请求document

{
    "data": {
        "type": "directory", 
        "attributes": {
            "name": "文档移动"
        }, 
        "relationships": {
            "parent": {
                "data": {
                    "type": "directory", 
                    "id": "a5af5ed2f54911e8a9205254009b5a66"
                }
            }
        }
    }
}

# 参数说明:

参数 是否必须 默认值 说明
directoryId 文件ID
directory.parent.id 父文件夹ID

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$attributes = [
    "name" => "文档移动",
    'parent_id' => 'f1572bcecd3711e8b8ee7fe8c886e03c'
];
$response = $Lxapi->moveDirectory('StaffID','ef380b7ca67911e89a9f10e7c61c70fc', $attributes);

# 响应document

# 200 ok 状态码
{
    "data": {
        "type": "directory",
        "id": "8a2c33acef2f11e9a8375254009b5a66",
        "attributes": {
            "name": "文档移动"
        },
        "relationships": {
            "parent": {
                "data": {
                    "type": "directory",
                    "id": "a5af5ed2f54911e8a9205254009b5a66"
                }
            }
        }
    },
     "included": [
        {
            "type": "directory",
            "id": "a5af5ed2f54911e8a9205254009b5a66",
            "attributes": {
                "name": "文档更新"
            }
        }
    ]
}
# 404 Not Found 状态码
{
    "errors": {
        "detail": "不存在ID为`c14150406fb1e9a9d25254009b5a66`的directory资源"
    }
}