What is the best way to get post data for a dashboard using the API?

api

(dirkcuys) #1

I want to create a dashboard that displays posts over time. Currently I’m pulling the data from discourse using the API:

  1. First I get all the topic using forum.example.net/latest.json
  2. Then I get post ids in the topic post_stream: forum.example.net/t/XX.json
  3. And finally I get all the posts: forum.example.net/posts/YY.json

But this is painfully slow - a request for every topic and a request for every post!

Is there a better way to get the data using the API?


(Khoa Nguyen) #2

There is no API end point for that. Hope there will be something like that soon.


(Kane York) #3

You could probably speed it up by requestiing /t/-/XX/last.json, which will include the post stream and the last 20 posts.


(dirkcuys) #4

Thanks! That will help, esp since most topics have less than 20 posts in them.


(Sam Saffron) #5

See:

https://github.com/discourse/discourse/pull/3126


(dirkcuys) #6

That will help a great deal! Esp once I automate pulling the data! Current proof of concept is here if anyone’s interested: http://dirkcuys.github.io/dash-example/


(Matias Furszyfer) #7

Hi guys,
what happen with this?. I’m looking for a way to get a single post by id without sweep the forum.


(Rafael dos Santos Silva) #8

You can try raw(open in new tab) or json


(Matias Furszyfer) #9

ok thanks for respond,
the problem there is that i’m sending special tags with my raw data and i’m not getting that.
For example this is my raw:

<h1>title</h1><p><special_tag>this is an special tag</p></special_tag>

and i’m getting:

<h1>title</h1><p>this is an special tag</p>   -> does not contains the <special_tag>.

(Rafael dos Santos Silva) #10

I don’t think the problem is actually getting this data. Discourse will stripe all non-whitelisted HTML tags by default.

So the problem is that your tags where stripped from the post.


(Matias Furszyfer) #11

mmm crap, do you have an advice to deal with that?.


(Rafael dos Santos Silva) #12

(Matias Furszyfer) #13

thanks!, i will be playing with that