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.