Forum Discussion

Elixor's avatar
15 years ago

[REST API] Problem to sort messages

Hi all,

 

I hope you will be able to help as I'm out of ideas :)

 

I'm starting to look at the REST API for some work and I might have missed something from the documentation.

 

I'm simply trying to pull authors ID from our community forums but my query with the REST API doesn't seem to return what I would like to.

 

The query is:

restapi/vc/threads/id/xxxxxxxx/messages/threaded?page_size=10&page=8&message_viewer.message_sort_order=thread_ascending

 

According to this the xml should return 10 blocs (per page) ordered by the oldest first where I'll pull the author name, message ID, date etc...

The query seems to work fine but doesn't pull out some of the data in the right order.

 

for example:

ID 10817595 - 2010-05-25T21:45:20+00:00

ID 10817608 - 2010-05-25T21:46:50+00:00

ID 10817616 - 2010-05-25T21:47:26+00:00

ID 10817567 - 2010-05-25T21:41:42+00:00

ID 10817568 - 2010-05-25T21:41:43+00:00

ID 10817528 - 2010-05-25T21:37:27+00:00

ID 10817543 - 2010-05-25T21:38:55+00:00

ID 10817515 - 2010-05-25T21:36:06+00:00

ID 10817520 - 2010-05-25T21:36:48+00:00

ID 10817523 - 2010-05-25T21:36:58+00:00

 

I'm quite happy to sort it out in an array in my script, but I was wondering why this part wasn't working the way I thought it would directly in the xml: "message_viewer.message_sort_order=thread_ascending"

 

Thanks in advance for the help.

  • Looks like you want "/messages/linear" instead of "/messages/threaded". So, for your original example:

     

    restapi/vc/threads/id/xxxxxxxx/messages/linear?page_size=10&page=8&message_viewer.message_sort_order=thread_ascending

     

    The short answer:

    If the board is being displayed in the UI as "Linear Format" (the default, and depending on setup, potentially the only view), linear would be the corresponding REST parameter. If it's "List by Topics", it's threaded.

     

    The longer winded one:

    Basically, linear mode displays a forum's replies in the order in which they were posted. In effect, all messages appear as replies to the one prior. Threaded mode displays them maintaining the hierarchy in which responses were made. For a smaller example, imagine a thread is started, message 2 and 3 are initiated as replies to the root, and message 4 is added as a reply to 2. The hierarchy would be:

     

     

    1
    |-2
    |--4
    |-3

     

    Admittedly, in a Forum only shown in the UI in linear mode, this REST result could be confusing.

     

    Note that the sort order still applies, but the different views change the meaning of ascending/descending.

     

     

6 Replies

  • Here is an example with the Lithosphere that might be simpler to explain my problem this way:

     

    Topic:

    https://lithosphere.lithium.com/t5/Growing-Successful-Communities/Who-runs-your-forum/td-p/4885/page/2

    Message 11 - ID: 4935 - Author: spike

    Message 12 - ID: 4953 - Author: Jason

    Message 13 - ID: 4962 - Author: Rho

    Message 14 - ID: 4971 - Author:  jloyless

    Message 15 - ID: 4975 - Author: PaulGi

    Message 16 - ID: 6244 - Author: JuhisH

     

    Query which should get the same result: (as far as I understood)

    http://lithosphere.lithium.com/restapi/vc/threads/id/4885/messages/threaded?page_size=10&page=2&message_viewer.message_sort_order=thread_ascending

    Message 11 - ID: 4962 - Author: Rho

    Message 12 - ID: 4971 - Author: jloyless

    Message 13 - ID: 4975 - Author: PaulGi

    Message 14 - ID: 6244 - Author:  jloyless

    Message 15 - ID: 4935 - Author: spike

    Message 16 - ID: 4953 - Author: Jason

     

  • Elixor's avatar
    Elixor
    Ace
    15 years ago

    Hi,

     

    Sorry to up this topic, anyone would have an idea?

  • LyleF's avatar
    LyleF
    Lithium Alumni (Retired)
    15 years ago

    I'm not the API expert, but it seems like the call you want is /messages/linear, which returns messages in chronological order vs /messages/threaded which returns messages in the order of nested replies (used to build a tree).

     

    Hope that helps..

     

     

  • EricH's avatar
    EricH
    Lithium Alumni (Retired)
    15 years ago

    Looks like you want "/messages/linear" instead of "/messages/threaded". So, for your original example:

     

    restapi/vc/threads/id/xxxxxxxx/messages/linear?page_size=10&page=8&message_viewer.message_sort_order=thread_ascending

     

    The short answer:

    If the board is being displayed in the UI as "Linear Format" (the default, and depending on setup, potentially the only view), linear would be the corresponding REST parameter. If it's "List by Topics", it's threaded.

     

    The longer winded one:

    Basically, linear mode displays a forum's replies in the order in which they were posted. In effect, all messages appear as replies to the one prior. Threaded mode displays them maintaining the hierarchy in which responses were made. For a smaller example, imagine a thread is started, message 2 and 3 are initiated as replies to the root, and message 4 is added as a reply to 2. The hierarchy would be:

     

     

    1
    |-2
    |--4
    |-3

     

    Admittedly, in a Forum only shown in the UI in linear mode, this REST result could be confusing.

     

    Note that the sort order still applies, but the different views change the meaning of ascending/descending.

     

     

  • Elixor's avatar
    Elixor
    Ace
    15 years ago

    This is great thank you very much.

    I tried it as linear and it does work as I wanted it to work.

     

    Thanks you very much for the answers and the explanations, it actually makes a lot of sense now.

  • Inactive User's avatar
    Inactive User
    5 years ago

    EricH What If I want to sort by other values other than the thread date? Say, title, or number of comments? How would we do that, and as always, where is the documentation for that? Thanks!