# 论坛

# 创建帖子

# 接口调用说明:

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

# 请求document

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

# 参数说明:

参数 是否必须 默认值 说明
thread.type 资源对象类型,必须为 thread,表示帖子
thread.title 帖子标题
thread.content 帖子内容
thread.category 关联的资源对象,类型为 category,表示帖子所属分类
thread.is_anonymous 0 是否匿名,1表示匿名,0表示不匿名
category.id 分类id

# SDK封装方法使用示例:

$attributes = [
    'title' => '通过API创建帖子',
    'content' => '<p>这是帖子内容,支持富文本</p>',
    'category_id' => '62a0b1a67fff11e7aa685254009d059e',
];
$options = [
	"is_anonymous" => 1

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

# 响应document

# 201 Created 状态码
{
  "links": {
    "self": "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": "ThreeZhang"
        }
      },
      "category": {
        "data": {
          "type": "category",
          "id": "c41215f654f711e88ed65254002b6735"
        }
      }
    }
  },
  "included": [
    {
      "type": "staff",
      "id": "ThreeZhang",
      "attributes": {
        "name": "张三",
        "english_name": "ThreeZhang",
        "organization":"运营组"
      }
    },
    {
      "type": "category",
      "id": "c41215f654f711e88ed65254002b6735",
      "attributes": {
        "name": "分类A"
      }
    }
  ]
}

# 更新帖子

# 接口调用说明

 PUT https://lxapi.lexiangla.com/cgi-bin/v1/threads/{thread_id}

# 参数说明:

参数 是否必须 默认值 说明
thread_id 帖子的id

# 请求document

{
	"data": {
		"attributes": {
			"content": "编辑内容",
			"title": "帖子标题"
		},
		"relationships": {
			"category": {
				"data": {
					"type": "category",
					"id": "92f97e76fac511e9931e0a58ac1302d4"
				}
			}
		}
	}
}

# 参数说明:

参数 是否必须 默认值 说明
thread 表示论坛的帖子
thread.title 帖子标题,最大长度120字,不区分中文字母数字
thread.content 帖子内容
thread.relationships.category 关联的资源对象,类型为 category,表示帖子所属分类
category.id 分类ID

# SDK封装方法使用示例


$options = [
	"title" => "标题",
	"content" => '内容',
	"category_id" => '92f97e76fac511e9931e0a58ac1302d4'//分类id
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);	
$response = $Lxapi->putThread($StaffID, $thread_id, $options);

# 响应document

# 200 OK 状态码
{
    "data": {
        "relationships": {
            "category": {
                "data": {
                    "id": "92f97e76fac511e9931e0a58ac1302d4",
                    "type": "category"
                }
            }
        },
        "attributes": {
            "summary": "编辑内容",
            "like_count": 0,
            "updated_at": "2021-09-26 11:06:25",
            "is_anonymous": 1,
            "created_at": "2021-09-24 15:52:27",
            "post_count": 0,
            "title": "帖子标题",
            "content": "<p>编辑内容</p>",
            "read_count": 9
        },
        "id": "5c8338301d0c11ecb1349e146f8b5344",
        "type": "thread"
    },
    "links": {
        "self": "https://lxapi.lexiangla.com/cgi-bin/v1/threads/5c8338301d0c11ecb1349e146f8b5344"
    },
    "included": [
        {
            "attributes": {
                "name": "验证动态"
            },
            "id": "92f97e76fac511e9931e0a58ac1302d4",
            "type": "category"
        }
    ]
}

# 删除帖子

# 接口调用说明:

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

# 参数说明:

参数 是否必须 默认值 说明
thread_id 帖子的id

# SDK封装方法使用示例:

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

# 响应document

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

# 获取帖子列表

# 接口调用说明:

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

# 参数说明:

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

支持时间范围过滤

参数 是否必须 默认值 说明
sort -created_at 排序参数,支持按帖子的created_at,updated_at排序
page 1 当前页数
per_page 20 每页返回的数量

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->get('threads', [
    'page'=> 1,
    'per_page' => 3,
]);

# 响应document

# 200 Get 状态码
{
    "data": [
        {
            "type": "thread",
            "id": "b4e08256e10111e9a9330a58ac1302c9",
            "attributes": {
                "title": "hhh",
                "read_count": 4,
                "post_count": 2,
                "like_count": 0,
                "created_at": "2019-09-27 16:35:05",
                "updated_at": "2019-09-27 16:37:24"
            },
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff",
                        "id": "ThreeZhang"
                    }
                },
                "category": {
                    "data": {
                        "type": "category",
                        "id": "62ad3550bff611e9b0820a58ac13036d"
                    }
                }
            }
        }
    ],
    "links": {
        "first": "https://lexiangla.com/cgi-bin/v1/threads?per_page=1&***",
        "last": "https://lexiangla.com/cgi-bin/v1/threads?per_page=1&***",
        "prev": null,
        "next": "https://lexiangla.com/cgi-bin/v1/threads?per_page=1&***"
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 753,
        "path": "https://lexiangla.com/cgi-bin/v1/threads",
        "per_page": 1,
        "to": 1,
        "total": 753
    },
    "included": [
        {
            "type": "staff",
            "id": "ThreeZhang",
            "attributes": {
                "name": "张三",
                "english_name": null,
                "organization": "运营组"
            }
        },
        {
            "type": "category",
            "id": "62ad3550bff611e9b0820a58ac13036d",
            "attributes": {
                "name": "fefe"
            }
        }
    ]
}

# 参数说明

参数 说明
thread.type 资源对象类型,为thread,表示资源为论坛
thread.id 帖子实体id
thread.title 帖子的标题
thread.created_at 帖子的创建时间
thread.updated_at 帖子的更新时间
thread.read_count 帖子的访问量
thread.post_count 帖子的回复数量
thread.like_count 帖子的点赞数量
relationships.owner 帖子的创建人,匿名帖子不会返回
relationships.category 帖子所属类型

# 获取单条帖子

# 接口调用说明:

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

# 参数说明:

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

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$response = $Lxapi->get('threads/'. $thread_id);

# 响应document

# 200 状态码

{
    "links":{
        "self": "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":"ThreeZhang"
                }
            },
            "category":{
                "data":{
                    "type":"category",
                    "id":"ba96198e4e6c11e6bd740800278acc25"
                }
            }
        }
    },
    "included":[
        {
            "type":"staff",
            "id":"ThreeZhang",
            "attributes":{
                "name":"张三",
                "english_name":"ThreeZhang",
                "organization":"运营组"
            }
        },
        {
            "type":"category",
            "id":"ba96198e4e6c11e6bd740800278acc25",
            "attributes":{
                "name":"产品讨论"
            }
        }
    ]
}

# 404 状态码

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

# 创建回帖

本接口包含创建回帖、创建回帖回复、创建回帖回复的回复接口调用说明

# 接口调用说明:

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

# 创建回帖

# 请求document

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

# 参数说明:

参数 是否必须 默认值 说明
thread_id 表示论坛帖子的id
content 回帖内容

# SDK封装方法使用示例:

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

# 响应document

# 201 Created 状态码
{
    "links":{
        "self":"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":"ThreeZhang"
                }
            },
            "thread":{
                "data":{
                    "type":"thread",
                    "id":"63c88fb0831c11e888d65254002b6735"
                }
            }
        }
    },
    "included":[
        {
            "type":"staff",
            "id":"ThreeZhang",
            "attributes":{
                "name":"张三",
                "english_name":"ThreeZhang",
                "organization":"运营组"
            }
        },
        {
            "type":"thread",
            "id":"63c88fb0831c11e888d65254002b6735",
            "attributes":{
                "title":"通过API创建帖子",
                "summary":"这是帖子内容,支持富文本",
                "created_at":"2018-07-09 10:04:19"
            }
        }
    ]
}

# 创建回帖回复

# 请求document

{
    "data": {
        "type": "post", 
        "attributes": {
            "content": "123"
        }, 
        "relationships": {
            "reference": {
                "data": {
                    "type": "post", 
                    "id": "ef57c40ea34a11ec8b5ebe194d8ef501"
                }
            }
        }
    }
}

创建回帖回复的回复,请求同上

# 参数说明:

参数 是否必须 默认值 说明
thread_id 表示论坛帖子的id
data.type.post post 回复回帖的的类型
data.attributes.content 回帖回复的内容
data.relationships.reference.data.type post 回帖的类型
data.relationships.reference.data.id 回帖的id

# SDK封装方法使用示例:


$attributes = [
    'content' => '<p>回帖回复</p>',
];
$options=[
    'ref_id'=>$ref_id
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->postThreadPost($StaffID, $thread_id, $attributes, $options);

# 响应document

# 201 Created 状态码
{
    "data": {
        "type": "post", 
        "id": "aa6adec4bc9711ec8cacc632d1a82132", 
        "attributes": {
            "content": "<p>123</p>", 
            "floor": 8, 
            "summary": "123", 
            "updated_at": "2022-04-15 16:40:12", 
            "created_at": "2022-04-15 16:40:12"
        }, 
        "relationships": {
            "owner": {
                "data": {
                    "type": "staff", 
                    "id": "zhangsan"
                }
            }, 
            "reference": {
                "data": {
                    "type": "post", 
                    "id": "ef57c40ea34a11ec8b5ebe194d8ef501"
                }
            }, 
            "thread": {
                "data": {
                    "type": "thread", 
                    "id": "8f2af78ca34911ec8cc23a5ce69bdba6"
                }
            }
        }
    }, 
    "included": [
        {
            "type": "staff", 
            "id": "zhangsan", 
            "attributes": {
                "name": "张三", 
                "english_name": "别名", 
                "organization": "xxxx 产品经理"
            }
        }, 
        {
            "type": "post", 
            "id": "ef57c40ea34a11ec8b5ebe194d8ef501", 
            "attributes": {
                "floor": 3, 
                "summary": "aaa", 
                "created_at": "2022-03-14 11:57:58"
            }
        }, 
        {
            "type": "thread", 
            "id": "8f2af78ca34911ec8cc23a5ce69bdba6", 
            "attributes": {
                "title": "aaaa", 
                "summary": "帖子内容", 
                "created_at": "2022-03-14 11:48:07"
            }, 
            "links": {
                "platform": "https://lexiangla.com/threads/8f2af78ca34911ec8cc23a5ce69bdba6?company_from=559ca0529f4211ecad1f4ac6b68ba604"
            }
        }
    ]
}

# 参数说明

参数 说明
data.type 资源对象类型,为post,表示资源为回帖回复
data.id 回帖回复id
data.attributes.content 回帖回复内容
data.attributes.floor 回帖回复的楼层
data.attributes.summary 回帖回复概要
data.attributes.created_at 回帖回复的创建时间
data.attributes.updated_at 回帖回复的更新时间
data.relationships.owner 回帖回复的创建人
data.reference 回帖回复的父级,指在这条资源上进行的回复
data.thread 回帖所属帖子

# 更新回帖

# 接口调用说明

 PUT https://lxapi.lexiangla.com/cgi-bin/v1/threads/{thread_id}/posts/{post_id}

# 请求document

{
	"data": {
		"attributes": {
			"content": "只能更新回帖内容"
		}
	}
}

# 参数说明:

参数 是否必须 默认值 说明
thread_id 表示论坛帖子的id
post_id 表示回帖的id
thread.content 帖子内容

# SDK封装方法使用示例:

$options = [
	'content' => '帖子内容',
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->putThreadPost($StaffID, $thread_id, $post_id, $options);

# 响应document

# 200 OK 状态码
{
    "data": {
        "attributes": {
            "summary": "只能更新回帖内容",
            "like_count": 0,
            "updated_at": "2021-09-26 11:20:15",
            "created_at": "2021-09-26 11:16:44",
            "floor": 1,
            "content": "<p>只能更新回帖内容</p>"
        },
        "id": "2d5f149e1e7811ec921b5ec738852c6a",
        "type": "post"
    }
}

# 删除回帖

# 接口调用说明

 DELETE https://lxapi.lexiangla.com/cgi-bin/v1/threads/{thread_id}/posts/{post_id} 

# 参数说明:

参数 是否必须 默认值 说明
thread_id 表示论坛帖子的ID
post_id 表示回帖的ID

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->deleteThreadPost($StaffID, $thread_id, $post_id);

# 响应document

# 204 No Content 状态码
 []

# 获取回帖列表

# 接口调用说明:

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

# 参数说明:

参数 是否必须 默认值 说明
thread_id 表示论坛帖子的id

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->get('threads/' . $thread_id . '/posts');

# 响应document

# 200 Get 状态码
{
    "data": [
        {
            "type": "post", 
            "id": "ef57c40ea34a11ec8b5ebe194d8ef501", 
            "attributes": {
                "floor": 3, 
                "content": "<p>1111</p>", 
                "summary": "1111", 
                "like_count": 0, 
                "created_at": "2022-03-14 11:57:58", 
                "updated_at": "2022-04-15 15:04:32"
            }, 
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff", 
                        "id": "zhangsan"
                    }
                }
            }
        }, 
        {
            "type": "post", 
            "id": "021df98abc8911ecb44812e13a778dc6", 
            "attributes": {
                "floor": 5, 
                "content": "<p>顶</p>", 
                "summary": "顶", 
                "like_count": 0, 
                "created_at": "2022-04-15 14:55:17", 
                "updated_at": "2022-04-15 14:55:17"
            }, 
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff", 
                        "id": "LX001"
                    }
                }
            }
        }, 
        {
            "type": "post", 
            "id": "64d22632bc8911ec89422aced83d1fbb", 
            "attributes": {
                "floor": 6, 
                "content": "<p>2222</p>", 
                "summary": "2222", 
                "like_count": 0, 
                "created_at": "2022-04-15 14:58:02", 
                "updated_at": "2022-04-15 15:05:45"
            }, 
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff", 
                        "id": "LX001"
                    }
                }, 
                "reference": {
                    "data": {
                        "type": "post", 
                        "id": "ef57c40ea34a11ec8b5ebe194d8ef501"
                    }
                }
            }
        }
    ], 
    "included": [
        {
            "type": "staff", 
            "id": "zhangsan", 
            "attributes": {
                "name": "zhangsan", 
                "english_name": "别名", 
                "organization": "xxx 产品经理"
            }
        }, 
        {
            "type": "staff", 
            "id": "LX001", 
            "attributes": {
                "name": "lisi", 
                "english_name": "别名", 
                "organization": "xxxx公司"
            }
        }, 
        {
            "type": "post", 
            "id": "ef57c40ea34a11ec8b5ebe194d8ef501", 
            "attributes": {
                "floor": 3, 
                "summary": "1111", 
                "created_at": "2022-03-14 11:57:58"
            }
        }
    ]
}

# 参数说明

参数 说明
threads.type 资源对象类型,为post,表示资源为回帖
threads.id 回帖实体id
threads.floor 回帖楼层
threads.content 回帖内容
threads.summary 回帖概要
threads.created_at 回帖的创建时间
threads.updated_at 回帖的更新时间
threads.owner 回帖的创建人
threads.reference 回帖回复的被回帖,当帖子没有回帖回复时,响应document此字段不显示
threads.like_count 帖子的点赞数量

# 获取单条回帖

# 接口调用说明:

GET https://lxapi.lexiangla.com/cgi-bin/v1/threads/{thread_id}/posts/{post_id}

# 参数说明:

参数 是否必须 默认值 说明
thread_id 表示论坛帖子的id
post_id 表示论坛的回帖的id

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->get('threads/' . $thread_id . '/posts/' . $post_id);

# 响应document

# 200 Get 状态码
{
    "data": {
        "type": "post",
        "id": "455a3d9ce58a11ecb58f022d02573c69",
        "attributes": {
            "floor": 8,
            "content": "<p>张三的对4楼的回帖回复</p>",
            "summary": "张三的对4楼的回帖回复",
            "like_count": 0,
            "created_at": "2022-06-06 19:17:37",
            "updated_at": "2022-06-06 19:17:37"
        },
        "relationships": {
            "owner": {
                "data": {
                    "type": "staff",
                    "id": "zhangsan"
                }
            },
            "reference": {
                "data": {
                    "type": "post",
                    "id": "c4d87d9ada7211ecb5dce2e548dfe09a"
                }
            }
        }
    },
    "included": [
        {
            "type": "staff",
            "id": "zhangsan",
            "attributes": {
                "name": "张三",
                "english_name": null,
                "organization": "2 "
            }
        },
        {
            "type": "post",
            "id": "c4d87d9ada7211ecb5dce2e548dfe09a",
            "attributes": {
                "floor": 4,
                "summary": "4楼的回帖",
                "created_at": "2022-05-23 16:31:40"
            }
        }
    ]
}

# 参数说明

参数 说明
threads.type 资源对象类型,为post,表示资源为回帖
threads.id 回帖实体id
threads.floor 回帖楼层
threads.content 回帖内容
threads.summary 回帖概要
threads.created_at 回帖的创建时间
threads.updated_at 回帖的更新时间
threads.owner 回帖的创建人
threads.reference 回帖回复的被回帖,当帖子没有回帖回复时,响应document此字段不显示
threads.like_count 帖子的点赞数量