Forum Discussion

MLachapelle's avatar
11 years ago

RESTAPI sort by last_edit_time

Hi,

 

Is it possible to retreive threads(forum, blog, idea, tkp and Q&A) from restapi sorted by last_edit_time?

 

Thank you.

6 Replies

  • JakeS's avatar
    JakeS
    Lithium Alumni (Retired)
    11 years ago

    Unfortunately, I don't belive that sort field is supported for search or using any threads endpoint; there's the recent threads call, but that sorts by the original post date.

  • irach15's avatar
    irach15
    Maven
    8 years ago

    Is it any updates on this?

    I need to sort API call from a specific board by last_time_edit?

    Is it any way around to make it work?

    It should be just the original tkb post that edited, not comments.

    SuzieH,

    any suggestions on this?

    Thank you.

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    8 years ago

    HI irach15,

    TariqHussain is correct in that we don't have a way to support this at this time. We don't have a good workaround for you, unfortunately.

  • irach15's avatar
    irach15
    Maven
    8 years ago

    SuzieHTariqHussain,

    this is what I've coded, the way around

    • API call to get the latest tkb from a specific board
    • create an object of the data you need to show
    • push data to the object
    • sort the data by using FreeMarker sort_by
    • reverse to be decending

    it works for the task I've been working on

     

     

    <#attempt>
    <#assign apiVersion = "2.0"/>
    <#assign messages = rest(apiVersion,"/search?q=" + "SELECT id, body, subject, view_href, post_time, post_time_friendly, board.id, board.view_href, board.title, board, images, images.count(*), videos.count(*), attachments.count(*), current_revision.last_edit_time FROM messages WHERE board.id = '${boardID}' AND depth=0 ORDER BY post_time DESC LIMIT 5"?url) />
    <#recover>
    <p>Woops...</p>
    </#attempt> 
    
    <#assign sortedMessagesList = [] />
    
    <#if messages.data.items ?? >
    <#list messages.data.items as message > 
     <#assign sortedMessagesList = sortedMessagesList + [{'message_subject': message.subject , 'message_revision_time':message.current_revision.last_edit_time}] />
    </#list>
    
     
    <#list sortedMessagesList?sort_by("message_revision_time")?reverse as mes > 
     <p>- ${mes.message_subject}: ${mes.message_revision_time}</p>
    </#list>
    
    
    </#if>

     

  • irach15- Thanks for sharing this code. However, this will for specific range e.g latest or oldest or for specific limit e.g 1000 messages.

    Example someone has edited a message which was posted 3 years ago. There is no way to get it unless we store all the messages in the object.