Forum Discussion

VarunGrazitti's avatar
9 years ago

Get the posts for specified time range in V1 or V2

As per this reply from NicoB,  we need to find the posts in the community created within the last 1 week.

Instead of the board, I am trying this call for category, but it is not working, though it is not working for board as well.

 

Category:

/restapi/vc/search/messages/count?q=category_id:CATEGORY_ID%20AND%20date:[1453870303%20TO%201454563405]&sort_by=date

 

Board:
/restapi/vc/search/messages/count?q=board_id:BOARD_ID%20AND%20date:[1453870303%20TO%201454563405]&sort_by=date

 

Unfortunately, there is no way in V2 to get the posts in a timerange as it needs depth=0, which means it only fetch the topics, is there any other way in V2 to fetch posts/replies in a time range?


Also, if I click the link in the screenshot below in NicoB’s post, it returns the result, but if I copy paste that in browser, it doesn’t, any reasons?

5 Replies

  • DougS's avatar
    DougS
    Khoros Oracle
    9 years ago

    Hi Varun,

     

    You should be able to get a count of messages (topics and replies together) via REST V2 if you exclude the depth parameter from your LiQL query -- a query like this should do the trick I believe:

     

    SELECT count(*) FROM messages WHERE board.id = 'technology' AND post_time > 1454348367000 AND post_time < 1454953167993 ORDER BY post_time DESC

    Probably what you are seeing with using the browser giving you no results is because we block authentication on the call (for security reasons). If you were to include a REST session key with your call in the browser, then you will most likely see the same results.

     

    -Doug

  • irach15's avatar
    irach15
    Maven
    9 years ago

    hi DougS,

    if I want to get the latest posts/or count  for the last week, not specifying a week, 

    Is it any way to get the results?

    I did try, not working:
    SELECT count(*) FROM messages WHERE board.id = 'topics' AND post_time < 604800 ORDER BY post_time DESC

     

    Any suggestions?

  • DougS's avatar
    DougS
    Khoros Oracle
    9 years ago

    You would have to specify a timerange in the query (you need a start time and an end time). If you were coding this in an endpoint, you could generate the query you need with something like this:

     

    <#assign now = dateSupport.now />
    <#assign nowMs = now.millisecondsAsString /> 
    <#assign weekBefore = now.addWeek(-1) />
    <#assign weekBeforeMs = weekBefore.millisecondsAsString />
    <#assign query = "SELECT count(*) FROM messages WHERE board.id = 'technology' AND post_time > " + weekBeforeMs + " AND post_time < " + nowMs + " ORDER BY post_time DESC" /> 

    -Doug

  • irach15's avatar
    irach15
    Maven
    9 years ago
    thank you, yes, I've done something like that too. I was thinking if any faster way around :-)
  • sam2's avatar
    sam2
    Guide
    9 years ago
    We can use "rangeTime" attribute for that in our endpoint call for V1.
    eg:- /restapi/vc/search/messages/count?q="anything u want to search"&rangeTime=1M