Discourse API Documentation

api

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


(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]}


(Katie Jenkins) #171

I know this post is kind of old, but have you figured out a way to do this? I tried using per_page on the end of my json request with no luck.


(Jay Pfaffman) #173

I couldn’t figure it out. This (sanitized) curl command will get the json of the users, but I can’t convert it to a working API call from Python.

-H 'accept-language: en-US,en;q=0.8' -H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' \
-H 'authority: example.com' -H 'cookie:  _t=b7fe75f320f5f4f2a1f3b5e6b2166b0e;' --compressed

My guess is that the _t cookie contains some magic. If having it work from the command line will help you, you can right-click active.json in the developer’s view and copy as cURL. My version above strips out a few variables that seem not to be required for curl to work.

I just get a 404 when I try to do it from Python, though.


(Katie Jenkins) #174

I ended up just finding out from the Discourse team that there is an endpoint to get the 100 newest users on the site. It’s not necessarily the same thing you guys were looking for, but I found it to be somewhat helpful.

/admin/users/list/new.json


(Steinway Wu) #175

This is not official, but I looked at the XHR request, and it worked for me (I’m on their official hosted service).

Send Private Messages

POST discourse.ats-lang.org/posts

title=
raw=
api_key=
api_username=
archetype=private_message
target_usernames=name1,name2,name3

Example

This is using httpie

http -f -v --session=test \
    POST discourse.your.com/posts \
    title="test out an api private post" \
    raw="this is just to test weather this works at all" \
    api_key=... \
    api_username=... \
    archetype=private_message \
    target_usernames=user1,user2

#176

Try {"tags":["a","b"]}.

If you’re using the urlencoded/form API, that is when it accepts tags[] instead of tags.


(Bala V) #177

How do I mark a post (and/or) topic as “read” through the API?

I am consuming the topics and posts through the API and showing it in a mobile app and as well as through web. I would like to mark a post as “read” from the mobile app too.


(John ) #178

If this is what I am working with for external data:

is it possible to query the user via email address?

/users/by-external-email/5360f4b83cd5f77cd700001c.json works fine.


(Bernhard Posselt) #179

How do I create a sub category through the API, e.g. /c/apps/calendar. The API only lists a name for the POST request, do I just use apps/calendar as name?