jjyao
1
我知道每个管理员报告都有一个.json API 来获取数据。我感兴趣的报告是 topics_no_response,并且我能够通过 https://xxx.com/admin/reports/topics_with_no_response?end_date=2023-06-16&filters=%7B%22category%22%3A7%2C%22include_subcategories%22%3Atrue%7D&mode=table&start_date=2023-06-14 按类别进行过滤。但是,如果我通过 https://xxx.com/admin/reports/topics_with_no_response.json?end_date=2023-06-16&filters=%7B%22category%22%3A7%2C%22include_subcategories%22%3Atrue%7D&mode=table&start_date=2023-06-14 切换到 json 端点,它不会返回数据。
我们是否有不同的语法来查询这两个端点?
RGJ
(Richard - Communiteq)
2
由于某种奇怪的原因,您需要使用 POST 而不是 GET。
jjyao
3
您好 @RGJ,
您能给我一个 POST 请求的示例吗?请求体应该是什么样的?我尝试过将 GET 改为 POST,使用相同的 URL,但似乎不起作用。
RGJ
(Richard - Communiteq)
4
jjyao
5
当我切换到 POST 并将所有查询参数作为 POST 数据传递时,我收到了“未找到页面”。但是,我能够使用 POST 来运行数据浏览器查询。你有什么想法吗?谢谢!
simon
6
请查看 Reverse engineer the Discourse API。当我尝试使用这种方法处理“无回复主题”报告时,我看到它发出了类似以下的 GET 请求:
http://forum.example.com/admin/reports/bulk?reports%5Btopics_with_no_response%5D%5Bfacets%5D%5B%5D=prev_period&reports%5Btopics_with_no_response%5D%5Bstart_date%5D=2022-02-01&reports%5Btopics_with_no_response%5D%5Bend_date%5D=2023-06-17&reports%5Btopics_with_no_response%5D%5Blimit%5D=50
您可以在浏览器检查器的“网络”选项卡中找到编码的查询参数。使用该 URL,您可以执行类似以下操作:
curl -X GET "http://localhost:4200/admin/reports/bulk.json?reports%5Btopics_with_no_response%5D%5Bfacets%5D%5B%5D=prev_period&reports%5Btopics_with_no_response%5D%5Bstart_date%5D=2022-05-16&reports%5Btopics_with_no_response%5D%5Bend_date%5D=2022-09-10&reports%5Btopics_with_no_response%5D%5Blimit%5D=50" \
-H "Api-Key: $api_key" \
-H "Api-Username: system"
您需要将 api_key 设置为所有用户的全局 API 密钥 - 我认为没有特定的范围可以用于报告。
请注意,您需要将 json 扩展名添加到 URL (http://localhost:4200/admin/reports/bulk.json)
1 个赞
system
(system)
关闭
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.