Discourse API Documentation

api

(cpradio) #201

Admin Area, Users, generate API key


(SMHassanAlavi) #203

Is there anyway to sort categories by their last_post date and time?
I find a way:

  • List all categories

  • Get each categories latest.json

  • Compare the last_posted_at and sort the categories

but I got some problems:

  1. this is very long and took times and reduce speed
  2. while getting last_post_at I got a problem:

I have tested :
http://localhost:3000/c/50/l/latest.json
and I get a json:


I have checked each topic’s last_post_at but they are not sorted and if I want to sort these again it would be very bad.
first topic:

second topic:

third topic:

4th topic:

if you see the last_post_at (at each photo at bottom right) you can see they are not sorted.
what should I do to sort categories?


(Jay Pfaffman) #204

As I understand the JSON specs, sort order isn’t ever guaranteed. Arguably Discourse could spit them out in some particular order, but it’s probably safest for your code to sort whatever JSON it gets anyway.


(Blake Erickson) #205

Okay, we finally have updated API Docs! Also, contributions are welcome.


(SMHassanAlavi) #206

Is there anyway to find the topic_count number of a subcategory?
For example category 38 is subcategory of 30 but I don’t know how to get topic_count of 38?
OR Is there any way to find a category topic_count number including subcategory topics?


#207

Speaking of subcategory, is there a API of it like /categories.json but with sub categories, as it only show sub id like this

"subcategory_ids": [
    7
    ],

I have search for few hours to see if i can find subcategory to get a name of it, No luck, I might have be blind and miss somewhere…Checking new doc that wasn’t there last time I came…

I need a name of sub category for few thing I can use.

Please do let me know about it


#208

Glad to finally see real API docs, thanks for that.

I have been having issues importing the Swagger/OpenAPI definition into Postman. I’ve also asked the Postman community about this. Has anyone done this successfully?


(Blake Erickson) #209

I’m not sure about importing the swagger files, but you should be able to import the postman environment and collection json files into postman.


#210

Wow, right in front of me :slight_smile:

Thanks!


#211

Come to think of it, might be good to put those Postman links at the top of the docs page, too.


(Simon Cossar) #212

You can get the full list of categories, including subcategories, from /site.json.


#213

While I’m making requests, it would be great to get some documentation on the track_visit query parameter. I’ve seen that used from the API but it isn’t in the docs.


(Roman Hotsiy) #214

Hey, @oblakeerickson. ReDoc author is here.
You have a really huuuge spec. You event beat our record - your spec is 119 meters tall when rendered by ReDoc :slight_smile:

I’ve found a few ReDoc bugs reproducible on your spec. Will try to fix for the next release.

I’ve also noticed you didn’t add your logo to ReDoc. To add it use x-logo vendor extension.

Maybe you would be interested in our other project GitHub - Rebilly/generator-openapi-repo: 🤖 Yeoman generator for OpenAPI/Swagger repo to help you share spec for your API. It is a tool that helps setting up a repository for OpenAPI spec with a bunch of useful features like validation, splitting spec into smaller manageable chunks and auto-bundling as a CI step.

Let me know if you need any assistance/help with ReDoc. Would be glad to help out :slight_smile:


(Blake Erickson) #215

@RomanHotsiy thank you for the work you do on ReDoc and for the tips! I’ll work on those :wink:


(Erlend Sogge Heggen) #216

(Blake Erickson) #217

I fixed most of the type: null statements and added the discourse logo.


(Manzarul Haque) #218

Hi i am able to run the discourse on my local windows system. How can i generate api key


(Blake Erickson) #219

You can generate an API key by going to Admin → API → Generate API Key


#220

Hi! Is there a way to get uncategorized topics? I’m trying to get all topics by passing the category id (:/c/id.json) but in this way I’m missing the uncategorized topics.


(Vinoth Kannan) #221

In site.json you can find uncategorized_category_id field (mostly it will be 1). Then you can get all uncategorized topics by calling /c/id.json itself.