内容分类操作

获取内容分类详情

接口

GET https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/:category_id/

其中 content_group_id 是内容库的 ID, category_id 是内容分类的 ID

代码示例

  1. curl -X GET \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v2.2/content/1/category/1/
  1. var request = require("request");
  2. var options = { method: 'GET',
  3. url: 'https://cloud.minapp.com/oserve/v2.2/content/1/category/1/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
  7. request(options, function (error, response, body) {
  8. if (error) throw new Error(error);
  9. console.log(body);
  10. });
  1. <?php
  2. $content_group_id = 1; // 内容库的 ID
  3. $category_id = 1; // 内容分类的 ID
  4. $url = "https://cloud.minapp.com/oserve/v2.2/content/{$content_group_id}/category/{$category_id}/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. $res = curl_exec($ch);
  17. curl_close($ch);

返回示例

  1. {
  2. "id": 1,
  3. "name": "category",
  4. "parent": null,
  5. "subcategories": [
  6. {
  7. "id": 2,
  8. "name": "subcategory",
  9. "parent": {
  10. "id": 1,
  11. "name": "category"
  12. },
  13. "subcategories": [],
  14. "created_at": 1519901783,
  15. "updated_at": 1519901783
  16. }
  17. ],
  18. "created_at": 1516963449,
  19. "updated_at": 1516963449
  20. }

返回参数说明

参数类型说明
idInteger分类 ID
nameString分类名称
parentObject分类的父类
subcategoriesObject Array子类名称
created_atInteger分类创建时间
updated_atInteger分类更新时间

获取内容分类列表

接口

GET https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/

该接口支持通过参数 return_total_count 指定是否返回查询对象总数,以协助不关心对象总数只关心查询结果列表的开发者提升接口响应速度。同时,从 v2.2 版本开始该接口默认不返回查询对象总数,欲获取总数的开发者需要显式指定 return_total_count 参数。

提交参数

  • parent 内容分类父分类列表查询

https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/?parent__isnull=true

  • name 内容分类名称的等值查询

https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/?name=category

  • return_total_count 指定是否在 meta 中返回 total_count

https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/?return_total_count=0

若开发者只需要获取对象总数,则可以通过设置 limit=1 以及 return_total_count=1 来达到该效果,total_count 可从返回的 meta 中获取

请求示例:

  1. https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/?limit=1&return_total_count=1

代码示例

  1. curl -X GET \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v2.2/content/1/category/
  1. var request = require("request");
  2. var options = { method: 'GET',
  3. url: 'https://cloud.minapp.com/oserve/v2.2/content/1/category/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
  7. request(options, function (error, response, body) {
  8. if (error) throw new Error(error);
  9. console.log(body);
  10. });
  1. <?php
  2. $content_group_id = 1;// 内容库的 ID
  3. $url = "https://cloud.minapp.com/oserve/v2.2/content/{$content_group_id}/category/";
  4. $ch = curl_init();
  5. $header = array(
  6. "Authorization: Bearer {$token}",
  7. 'Content-Type: application/json; charset=utf-8'
  8. );
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  15. $res = curl_exec($ch);
  16. curl_close($ch);

返回示例

  1. {
  2. "meta": {
  3. "limit": 20,
  4. "next": null,
  5. "offset": 0,
  6. "previous": null,
  7. "total_count": 2
  8. },
  9. "objects": [
  10. {
  11. "id": 1,
  12. "name": "category",
  13. "parent": null,
  14. "subcategories": [
  15. {
  16. "id": 2,
  17. "name": "subcategory",
  18. "parent": {
  19. "id": 1,
  20. "name": "category"
  21. },
  22. "subcategories": [],
  23. "created_at": 1519901783,
  24. "updated_at": 1519901783
  25. }
  26. ],
  27. "created_at": 1516963449,
  28. "updated_at": 1516963449
  29. },
  30. {
  31. "id": 2,
  32. "name": "subcategory",
  33. "parent": {
  34. "id": 1516963449144537,
  35. "name": "category"
  36. },
  37. "subcategories": [],
  38. "created_at": 1519901783,
  39. "updated_at": 1519901783
  40. }
  41. ]
  42. }

创建内容分类

接口

POST https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/

参数说明

Content-Type: application/json

参数类型必填说明
nameStringY分类名称
parentIntegerN父分类 ID

warning注意:最多只允许三层嵌套分类

代码示例

  1. curl -X POST \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. -d '{
  5. "name": "分类1",
  6. }' \
  7. https://cloud.minapp.com/oserve/v2.2/content/1/category/
  1. var request = require("request");
  2. var options = { method: 'POST',
  3. url: 'https://cloud.minapp.com/oserve/v2.2/content/1/category/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
  7. body: { name: "分类1" },
  8. json: true
  9. };
  10. request(options, function (error, response, body) {
  11. if (error) throw new Error(error);
  12. console.log(body);
  13. });
  1. <?php
  2. $content_group_id = 1;// 内容库的 ID
  3. $param['name'] = 'CreateCategory';
  4. $url = "https://cloud.minapp.com/oserve/v2.2/content/{$content_group_id}/category/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_POST, true);
  14. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  17. $res['response'] = curl_exec($ch); // 反馈结果
  18. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  19. curl_close($ch);

返回示例

  1. {
  2. "id": 3,
  3. "name": "分类1",
  4. "parent": null,
  5. "subcategories": [],
  6. "created_at": 1519910966,
  7. "updated_at": 1519910966
  8. }

状态码说明

201: 创建成功

400: 同一父分类下的子分类名不能相同;父分类 ID 不合法

编辑内容分类

接口

PUT https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/:category_id/

代码示例

  1. curl -X PUT \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. -d '{
  5. "name": "Test Category"
  6. }' \
  7. https://cloud.minapp.com/oserve/v2.2/content/1/category/3/
  1. var request = require("request");
  2. var options = { method: 'PUT',
  3. url: 'https://cloud.minapp.com/oserve/v2.2/content/1/category/3/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
  7. body: { name: 'Test Category' },
  8. json: true };
  9. request(options, function (error, response, body) {
  10. if (error) throw new Error(error);
  11. console.log(body);
  12. });
  1. <?php
  2. $content_group_id = 1; // 内容库 ID
  3. $category_id = 1;// 内容分类的 ID
  4. $url = "https://cloud.minapp.com/oserve/v2.2/content/{$content_group_id}/category/{$category_id}/";
  5. $param['name'] = 'updateCategory';
  6. $ch = curl_init();
  7. $header = array(
  8. "Authorization: Bearer {$token}",
  9. 'Content-Type: application/json; charset=utf-8'
  10. );
  11. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  12. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  13. curl_setopt($ch, CURLOPT_URL, $url);
  14. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  18. $res['response'] = curl_exec($ch); // 反馈结果
  19. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  20. curl_close($ch);

返回示例

  1. {
  2. "id": 3,
  3. "name": "Test Category",
  4. "parent": null,
  5. "subcategories": [],
  6. "created_at": 1519910966,
  7. "updated_at": 1519910966
  8. }

状态码说明

200: 修改成功

400: 同一父分类下的子分类名不能相同;父分类 ID 不合法

删除内容分类

接口

DELETE https://cloud.minapp.com/oserve/v2.2/content/:content_group_id/category/:category_id/

代码示例

  1. curl -X DELETE \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v2.2/content/1/category/1/
  1. var request = require("request");
  2. var options = { method: 'DELETE',
  3. url: 'https://cloud.minapp.com/oserve/v2.2/content/1/category/1/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
  7. request(options, function (error, response, body) {
  8. if (error) throw new Error(error);
  9. console.log(body);
  10. });
  1. <?php
  2. $content_group_id = 1; // 内容库 ID
  3. $category_id = 1;// 内容分类的 ID
  4. $url = "https://cloud.minapp.com/oserve/v2.2/content/{$content_group_id}/category/{$category_id}/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. $res['response'] = curl_exec($ch); // 反馈结果
  17. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  18. curl_close($ch);

状态码说明

204: 删除成功