Discourse API Documentation

api

#223

I just realized that by passing the category id I only get 30 topics per category. How can I get the list of all the topics (or topic id’s) in a category? Can I paginate the results somehow?


(Blake Erickson) #224

Yep, just add &page=2 to the url like:

https://meta.discourse.org/c/uncategorized/l/latest?no_subcategories=false&page=2

#225

Thanks! I noticed that the last result of ‘/c/id.json?no_subcategories=false&page=0’ is the same as the first result in ‘/c/id.json?no_subcategories=false&page=1’ in case of multiple categories. The last result of page=1 is not duplicated on page=2 though. Is there a reason for this or is this a bug?


(Blake Erickson) #226

Yes, I think when the last result of page 0 shows up as the first result of page 1 but not on subsequent pages is a bug. A also think this may have come up before somewhere else on meta.


(Dylan Hunt) #227

What’s with the unset {{$guid}} {{$guid}} 's? I can’t seem where to find this in the Postman tutorial above.

Also, why doesn’t Postman contain all the required fields? Seems that half the stuff is left out (strange to add only some of the required fields).

Then category id (int)? not name (str)? How can I find this? it’s not in the url

Where do i post the body of the message? replace the random guid’s unset vars?

Overall, pretty confused with intro docs when trying to test by posting a new topic :confused:


(Ryan Odening) #228

thanks for sharing! the line I pasted above doesn’t work for me, though. It’s a very important one.

EDIT: ok. actually like I see some stuff. but any chance we can get a json version of this?
that would be tiiiiiiiiiiiight.


(Ryan Odening) #229

also, i noticed that badges in user is not up to date


(Frank Bailey) #230

Is there an API call I can make to retrieve a simple count of all users registered on my Discourse site?


#231

You could do a get call on about.json and pull the user_count out of that.

For example: https://meta.discourse.org/about.json

{"stats":{"topic_count":23313,"post_count":353404,"user_count":32523,"topics_7_days":171,"topics_30_days":538,"posts_7_days":3053,"posts_30_days":9901,"users_7_days":280,"users_30_days":978,"active_users_7_days":795,"active_users_30_days":1733,"like_count":328467,"likes_7_days":4433,"likes_30_days":12497}


(Frank Bailey) #232

Haha, that’s awesome. Give exactly what I need. Thanks a ton Mike!


#233

Under the current build 2.0.0.beta1, badges are not working at all via API (curl). I’m getting a 400 error or this:
The requested URL or resource could not be found.

Is anyone else having issues with badge requests via the API? Categories, etc. seem to work fine.


#234

UPDATE: it turns out there are some minor type-os in the API Documentation. Specifically, the call for assigning a badge to a user needs to updated to reflect “user-badges” instead of a “user_badges”:
example.com/user-badges/[user].json?api_key=[apikey]&api_username=[api_username]

As I sift through additional calls, I’ll update as things come up. Is there anther channel to commit updates to the documentation or is this thread the best place to do so?


(Jeff Atwood) #235

Sure let @oblakeerickson know.


(Blake Erickson) #236

I’ve updated the user-badges.json route in the documentation. Thank you for lettings us know about it :slight_smile:.

If you find any more updates that need to be made just let me know or you can always submit a PR to the api docs repo.


(Erlend Sogge Heggen) #237

Updating the API with missing or outdated API calls is something that frequently comes up as a contributor-friendly task. Would be great to have a #howto that covers the most common API contributions,


#238

I found one today that was missing - how to pin a topic via the api

full post url / status

Shall I add a PR for it?

Would be good however to have that PUT Request as just domain.com/t/id/status rather than domain.com/t/post-slug/id but that is prob more of a feature request more than anything. Thoughts?

Ignore me - you dont need the slug you can just use the /t/id/status


(Blake Erickson) #239

Yes please! That would be awesome. There are instructions in the README, but I will work on a #howto later, please reach out if you need any help though.

I think this has been brought up before somewhere, but there is a little “hack” you can do: just replace the slug with a dash - (any character actually) and the rails router will still find the topic by just the ‘id’.


(Tomasz Lotocki) #240

@oblakeerickson I had an issue with the latest postman relese, it looks like you need to set up enviroment by hand and then importing collection will work.

Otherwise Postman will complain about invalid file format.


(Blake Erickson) #241

Thanks for letting me know, but I’m not totally sure what you mean

However, this is why I specified this in the instructions:

Could you not import the environment file and had to manually create it?


#242

I have found had to import via settings section rather than main import option before as wouldnt work. Might be worth trying it that way. Think there was an issue with postman itself