How to query the topics_with_no_response.json API with filters

I know that for each admin report, there is a .json API to fetch the data. The report I’m interested in is topics_with_no_response and I was able to filter by category via 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. However if I switched to the json endpoint via 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, it doesn’t return the data.

Do we have different syntax to query these two endpoints?

You need to POST instead of GET for some weird reason.

Hi @RGJ,

Could you give me an example of the POST request? What should be the body? I tried to just change GET to POST with the same URL but it seems doesn’t work.

You will obviously need to pass the query parameters (i.e. everything after the ?) as the POST data.

See also Run Data Explorer queries with the Discourse API

When I switched to POST and pass all the query parameters as the POST data, I got “Page Not Found”. However I was able to use POST to run data explorer queries. Do you have any ideas? Thanks!

Have a look at Reverse engineer the Discourse API. When I try that approach for the Topics With no Response report, I’m seeing it make GET requests similar to:

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

You can get the encoded query params from the Network tab of your browser’s inspector. With that URL, you should be able to do something like:

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"

You will need to set api_key to an All Users Global API key - I don’t think there’s a specific scope that can be used for the reports.

Note that you need to add the json extension to the URL (http://localhost:4200/admin/reports/bulk.json)

1 Like

Thanks @simon, that works!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.