Discourse API Documentation


(Blake Erickson) #140

Posts don’t have categories, but topics do. So if you create a post it will be in whatever category the topic is in. I’m not sure why you are getting that 301.

(Jared Needell) #141

Ok so topic, still I only see a title/body in the example and but not which category to put the new topic in

(Blake Erickson) #142

@Jared_Needell I’ve updated the documentation to include the category when creating a new topic

(Jared Needell) #143

Looks like its category id not category slug

(Mathias Källberg) #144

Hello everyone, my first post in this forum.

I’m trying to get all posts in a topic with:

This works fine, except for that I only recieve the first 20 posts. I see the info about the rest of the posts under “stream”, but the posts themselves are missing. I can’t find a setting for this anywhere either. Any idea what I’m doing wrong? :slight_smile:

Running v1.6.0.beta2 +78 btw.

(Blake Erickson) #145

You will need to pass in all the id’s from the “stream” as url parameters to this url:




I would still make sure you break them up in chunks of 20.

Also I recommend using the ruby discourse_api gem:

(Mathias Källberg) #146

Thank you!

So currently there’s no way to request a specific “page” not counting replies?

What I would like to do is get the last 5 posts, plus replies if there are any. But in “stream” i can’t see if a post is a reply or not, correct?

Can’t use the ruby gem I’m afraid, since our project is written in php. I’m stuck with curl. :slight_smile:

(Blake Erickson) #147

Nope. No paging, but the highest post_id’s on a topic should give you the latest ones (well I think there is a way to get paging, but it will return html, not json. Just browse your site with javascript disabled).

In the “stream” no, but in the json data for each post there are these fields:


which should help you get the reply info

(Mathias Källberg) #148

If we really would like to have native support for this in the api, is there someone we could convince? Or hire?

My problem with this, if I’ve got this right, is that I don’t know which posts that are replies until I’ve retrieved them fully. So if I have a topic with 2000 posts I would have to get all 2000 posts to look for replies to the first post. Well, there is a reply_count so I could be lucky and stop the search when all is found, but worst case scenario is that I have to look through all posts. So it would be really nice to have an api call for this instead, right? :slight_smile:

(Blake Erickson) #149

Maybe, but that isn’t a super expensive call to do. You could probably fetch posts in batches of 100+ (or 2000 :scream:)

but you could probably just [quote=“mathias.kallberg, post:146, topic:22706”]
get the last 5 posts

and still get what you are looking for.

You could post a topic in the marketplace category here on meta and see if someone is willing to do it.

(Mathias Källberg) #150

A quick question: Is there anything you’re not allowed to do via the Master API Key?

My college was trying to create users via the api, and didn’t succeed. After a bit if a struggle he’d created a second api key, for the system user, and got it working, but I wonder if that had anything to do with it? :slight_smile:

(Blake Erickson) #151

nope, the master API Key can do all the things.

What was the username he was using with the Master API Key? Even if you are using the Master API Key you still need to pass in a username with it.

(Mathias Källberg) #152

His own username I think. So maybe his user didn’t have enough power, could that be it?

(Blake Erickson) #153

If he was using the Master API key though I don’t think it would matter, but if he was using just the api key for his user it would matter.

(Zinda Xyz) #154

how can i get list of topic which user’s watch category using api ?

(Blake Erickson) #155

I’m not exactly sure what you are asking for, but to get the categories that a user is watching you can hit the user endpoint and look for these values:


(Zinda Xyz) #156

suppose my watched_category_ids 7,8,9
and i want those topic data which in cat_id 7,8,9 in api

(Blake Erickson) #157

Look up the category_slug by their id, and then go to each category and get the topics in them:


will return the topics and contain these fields (plus many more):


(Zinda Xyz) #158

so want to call x time api which i watched am i right?

is there any way to call signal api to get all watched category’s topic

(Blake Erickson) #159

No. Not that I’m aware of.