论坛

创建帖子

接口调用说明:

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

请求document

{
  "data": {
    "type": "thread", 
    "attributes": {
      "title": "通过API创建帖子", 
      "content": "<p>这是帖子内容,支持富文本</p>"
    }, 
    "relationships": {
      "category": {
        "data": {
          "type": "category", 
          "id": "62a0b1a67fff11e7aa685254009d059e"
        }
      }
    }
  }
}

参数说明:

参数 是否必须 默认值 说明
thread.type 资源对象类型,必须为 thread,表示帖子
thread.title 帖子标题
thread.content 帖子内容
thread.category 关联的资源对象,类型为 category,表示帖子所属分类
category.id 分类ID
created_at 服务器当前时间 帖子的创建时间
updated_at 服务器当前时间 帖子的更新时间
read_count 0 帖子的阅读数/浏览数

SDK封装方法使用示例:

$attributs = [
    'title' => '通过API创建帖子',
    'content' => '<p>这是帖子内容,支持富文本</p>',
    'category_id' => '62a0b1a67fff11e7aa685254009d059e',
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->postThread(StaffID, $attributs, $options = []);

响应document

201 Created 状态码
{
  "links": {
    "self": {
      "href": "https://lxapi.lexiangla.com/cgi-bin/v1/threads/63c88fb0831c11e888d65254002b6735"
    }
  }, 
  "data": {
    "type": "thread", 
    "id": "63c88fb0831c11e888d65254002b6735", 
    "attributes": {
      "title": "通过API创建帖子", 
      "content": "<p>这是帖子内容,支持富文本</p>", 
      "summary": "这是帖子内容,支持富文本", 
      "updated_at": "2018-07-09 10:04:19", 
      "created_at": "2018-07-09 10:04:19"
    }, 
    "relationships": {
      "owner": {
        "data": {
          "type": "staff", 
          "id": "StaffID"
        }
      }, 
      "category": {
        "data": {
          "type": "category", 
          "id": "c41215f654f711e88ed65254002b6735"
        }
      }
    }
  }, 
  "included": [
    {
      "type": "staff", 
      "id": "StaffID", 
      "attributes": {
        "name": "张三", 
        "english_name": "ThreeZhang",
        "organization":"运营组"
      }
    }, 
    {
      "type": "category", 
      "id": "c41215f654f711e88ed65254002b6735", 
      "attributes": {
        "name": "分类A"
      }
    }
  ]
}

获取单条帖子

接口调用说明:

GET https://lxapi.lexiangla.com/cgi-bin/v1/threads/{ThreadID}

参数说明:

参数 是否必须 默认值 说明
ThreadID 帖子的ID

SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$response = $Lxapi->getThread('51bb2f84a67c11e8ae1610e7c61c70fc');

响应document

200 状态码

{
    "links":{
        "self":{
            "href":"https://lxapi.lexiangla.com/cgi-bin/v1/threads/51bb2f84a67c11e8ae1610e7c61c70fc"
        }
    },
    "data":{
        "type":"thread",
        "id":"51bb2f84a67c11e8ae1610e7c61c70fc",
        "attributes":{
            "title":"通过API创建帖子",
            "content":"<p>这是一条通过LXAPI创建的帖子</p>",
            "summary":"这是一条通过LXAPI创建的帖子",
            "read_count":100,
            "post_count":0,
            "like_count":0,
            "created_at":"2018-08-22 09:55:00",
            "updated_at":"2018-08-22 09:55:00"
        },
        "relationships":{
            "owner":{
                "data":{
                    "type":"staff",
                    "id":"StaffID"
                }
            },
            "category":{
                "data":{
                    "type":"category",
                    "id":"ba96198e4e6c11e6bd740800278acc25"
                }
            }
        }
    },
    "included":[
        {
            "type":"staff",
            "id":"StaffID",
            "attributes":{
                "name":"张三",
                "english_name":"ThreeZhang",
                "organization":"运营组"
            }
        },
        {
            "type":"category",
            "id":"ba96198e4e6c11e6bd740800278acc25",
            "attributes":{
                "name":"产品讨论"
            }
        }
    ]
}

404 状态码

{
    "errors":{
        "detail":"不存在ID为`51bb2f84a67c11e8ae1610e7c61c70ff`的thread资源"
    }
}

删除帖子

接口调用说明:

DELETE https://lxapi.lexiangla.com/cgi-bin/v1/threads/{ThreadID}

参数说明:

参数 是否必须 默认值 说明
ThreadID 帖子的ID

SDK封装方法使用示例:

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

响应document

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

创建回帖

接口调用说明:

POST https://lxapi.lexiangla.com/cgi-bin/v1/threads/{ThreadID}/posts

请求document

{
    "data":{
        "type":"post",
        "attributes":{
            "content":"<p>顶</p>"
        }
    }
}

参数说明:

参数 是否必须 默认值 说明
ThreadID 要回复的帖子ID
content 回帖内容

SDK封装方法使用示例:

$attributs = [
  'content' => '<p>顶</p>',
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->postThreadPost(StaffID, ThreadID, $attributs, $options = []);

响应document

201 Created 状态码
{
    "links":{
        "self":{
            "href":"https://lxapi.lexiangla.com/cgi-bin/v1/threads/63c88fb0831c11e888d65254002b6735/posts/4ad747ce834b11e89a7f5254002b6735"
        }
    },
    "data":{
        "type":"post",
        "id":"4ad747ce834b11e89a7f5254002b6735",
        "attributes":{
            "content":"<p>顶</p>",
            "floor":1,
            "summary":"顶",
            "updated_at":"2018-07-09 15:40:03",
            "created_at":"2018-07-09 15:40:03"
        },
        "relationships":{
            "owner":{
                "data":{
                    "type":"staff",
                    "id":"StaffID"
                }
            },
            "thread":{
                "data":{
                    "type":"thread",
                    "id":"63c88fb0831c11e888d65254002b6735"
                }
            }
        }
    },
    "included":[
        {
            "type":"staff",
            "id":"StaffID",
            "attributes":{
                "name":"张三",
                "english_name":"ThreeZhang",
                "organization":"运营组"
            }
        },
        {
            "type":"thread",
            "id":"63c88fb0831c11e888d65254002b6735",
            "attributes":{
                "title":"通过API创建帖子",
                "summary":"这是帖子内容,支持富文本",
                "created_at":"2018-07-09 10:04:19"
            }
        }
    ]
}