It doesn’t exactly reply to your question, but does this help?
Run Data Explorer queries with the Discourse API