Discourse API Documentation

api

(Blake Erickson) #136

@jdorweiler Yea give it a shot.


(Jared Needell) #139

How do I pick the category to post in? I get a 301 Error when I try this


(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:
/t/id.json

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:

/t/#{topic_id}/posts.json?

like:

http://localhost:3000/t/26/posts.json?post_ids%5B%5D=212&post_ids%5B%5D=211&post_ids%5B%5D=210&post_ids%5B%5D=209&post_ids%5B%5D=208&post_ids%5B%5D=207&post_ids%5B%5D=206&post_ids%5B%5D=205&post_ids%5B%5D=204&post_ids%5B%5D=203&post_ids%5B%5D=202&post_ids%5B%5D=201&post_ids%5B%5D=200&post_ids%5B%5D=199&post_ids%5B%5D=198&post_ids%5B%5D=197&post_ids%5B%5D=196&post_ids%5B%5D=195&post_ids%5B%5D=194&post_ids%5B%5D=193&_=1462882841434

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:

"reply_count":0,
"reply_to_post_number":103,

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
[/quote]

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:

"tracked_category_ids":[],"watched_category_ids":[7]

(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:

http://localhost:3000/c/test-category/l/latest.json?_=1463724833156

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

topics":[{"id":26,"title":"Pvjqmdeaobtihrgzunklwyxsfc",