If it must be done through the API, you could set up a Data Explorer query and use the methods outlined in Run Data Explorer queries with the Discourse API
If it must be done through the API, you could set up a Data Explorer query and use the methods outlined in Run Data Explorer queries with the Discourse API