Forum Discussion

Kev_B's avatar
Kev_B
Advisor
7 years ago

Do date constraints work with API v1?

Hi,

I'm using API v1 for the first time to pull up some user stats, and I'm trying to constrain these to a date range. I've tried using ?date_start-YYYY-MM-DD&date_end-YYYY-MM-DD at the end of the query URL, but this doesn't seem to work in sorting the results.

The one query I'm using is users/id/{user-id}/posts.

Just wondering if anybody has any experience, as the only stuff I can find about date_start / end is referring to using metrics.

5 Replies

  • Kev_B
    yes, start date and end date is not working here with this API. But you can do it with API V2 also. 

    Select * from messages where author.id = '123' and post_time > "date" and post_time < "date" 
  • Kev_B's avatar
    Kev_B
    Advisor
    7 years ago

    Thanks Vikas, 

    I'm most interested in using the count function on posts, is there an easy way to do this with API v2?

    Thanks

  • This is a starting point:

    <#assign user_id = 123/>
    <#assign board_id = 'help'/>
    <#assign date_start = "yyyy-MM-dd"/>
    <#assign date_end = "yyyy-MM-dd"/>
    <#assign timezone = "+01:00"/>
    <#assign query = rest("2.0","/search?q=" + "SELECT count(*) FROM messages WHERE board.id = '${board_id}' AND author.id = '${user_id}' AND post_time >= ${date_start}T00:00:00${timezone} AND post_time <= ${date_end}T00:00:00${timezone}"?url) />
    <#assign post_count = query.data.count!0/>
    ${post_count}
  • VikasB's avatar
    VikasB
    Boss
    7 years ago

    Kev_B

    a) Use the same API shared in the last comment. See here https://prnt.sc/kxz7je
    b) Use count specific API

    Select count(*) from messages where author.id = '3' and post_time > 2018-09-21T00:15:47.369-07:00