I have never used the discourse API before. So I am unable to help you with API. But I hope the following links will help you get started.
https://meta.discourse.org/search?q=discourse%20api