Discourse API Documentation

api

(Andre Kosak) #160

How can i get the original post? For example, its markdown version.
If i request https://meta.discourse.org/t/using-the-rest-api/21699.json i get only cooked versions of all posts.


(Mittineague) #161

Does adding ?include_raw=1 work for you? eg.

https://meta.discourse.org/t/discourse-api-documentation/22706/161.json?include_raw=1

Discourse API Documentation


(Zinda Xyz) #162

did you have any list of notification type list
in api notifications.json they have key like “notification_type”: 5, or “notification_type”: 12, or “notification_type”: 9,

9 means what?
5 means what?
12 means what?


(Mittineague) #163

From
app/models/notifications.rb

  def self.types
    @types ||= Enum.new(mentioned: 1,
                        replied: 2,
                        quoted: 3,
                        edited: 4,
                        liked: 5,
                        private_message: 6,
                        invited_to_private_message: 7,
                        invitee_accepted: 8,
                        posted: 9,
                        moved_post: 10,
                        linked: 11,
                        granted_badge: 12,
                        invited_to_topic: 13,
                        custom: 14,
                        group_mentioned: 15,
                        group_message_summary: 16
                       )
  end

(Mathias Källberg) #164

Hello again!

We’re now trying to import posts from our previous forum system. The only thing we haven’t got working so far is setting the correct timestamps on posts. We’ve found the api for setting timestamp on a whole topic, but how do you set it for the posts?


(Louis Rossouw) #165

There are import scripts that handle this sort of thing. Maybe you can ammend these to your needs.

Should also sit in the script/import_scripts of your install. They need tweaking though as they aren’t perfect (at least that is what I found with vbulletin one), but they basics work.


(Mathias Källberg) #166

Thanks for your response!

I don’t think any of the existing import scripts would work for us though, since we have a completely custom forum system. That’s why we’re writing our own import script. It’s working through the api and works great, except for posts timestamps…


(Dave McClure) #167

Still worth checking out the existing import scripts. Most, if not all of them use a base importer class and then add the source forum-specific functionality.

You should be able to do the same.


(Mathias Källberg) #168

Just found this: :slight_smile:


(Diana Naranjo) #169

I am trying to reverse engineer the way to add tags when creating a new topic via the api. In the development environment of chrome I can see you have a parameter “tags[]” in the post data. However, even when I add this parameter to the post data, no tag is created/linked to the new topic.
{"raw": [topic_content], "title": [topic_title], "category": [category_id], "tags[]":[some_tag_id]}


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