Forum Discussion

iahiqosolutions's avatar
13 years ago

REST API. How to sort messages in a blog?

Hello folks,

 

I have a question:

Lets consider that we have a blog with articles.

How can we sort all these articles by views or publish date?

 

We have tried to use following REST API methods:

/restapi/vc/blogs/id/%ArticleName%/topics/messages?sort_by=-date

/restapi/vc/blogs/id/%ArticleName%/topics/messages?sort_by=views

/restapi/vc/blogs/id/%ArticleName%/topics/messages?sort_by=-views

/restapi/vc/blogs/id/%ArticleName%/topics/messages?sort_by=-topicViews

 

end etc.

 

But it looks like "sort_by" parameter doesn't work.

 

We have found that this parameter takes into account by the search method of the blog.

Here is example:

/restapi/vc/blogs/id/%ArticleName%/search/messages?sort_by=views&q=know

But in this case not all blog articles can be included in the search results(Because we have to use something for value of the "q" parameter).

 

  • AdamN's avatar
    AdamN
    13 years ago

    Hello,

     

    If you want to go the search route, you can use "is_root:true" as the value of the q parameter, and then sort as needed. This will return "root" messages, which is the first message in a thread. For example:
    http://lithosphere.lithium.com/restapi/vc/blogs/id/lithiumblog/search/messages?q=is_root:true&sort_by=-topicViews


    There's a message_viewer.topic_sort_order parameter that can be used with the threads methods; however, the only available values are last_post_date and topic_start_date, which doesn't sound like it will help you with your particular use case. I'd suggest giving the search option a try.

     

    I hope this helps!

     

    -Adam

2 Replies

  • AdamN's avatar
    AdamN
    Khoros Oracle
    13 years ago

    Hello,

     

    If you want to go the search route, you can use "is_root:true" as the value of the q parameter, and then sort as needed. This will return "root" messages, which is the first message in a thread. For example:
    http://lithosphere.lithium.com/restapi/vc/blogs/id/lithiumblog/search/messages?q=is_root:true&sort_by=-topicViews


    There's a message_viewer.topic_sort_order parameter that can be used with the threads methods; however, the only available values are last_post_date and topic_start_date, which doesn't sound like it will help you with your particular use case. I'd suggest giving the search option a try.

     

    I hope this helps!

     

    -Adam