Forum Discussion

dustin's avatar
dustin
Expert
8 years ago

V2 API: How do I get author's kudo count for past month?

In the following code, I can retrieve the list of users who have kudos in the last month, then for each user I get their details to display them.

 

I wish to get the kudo count for each author, however the API doesn't seem to allow a comparison with the KUDO table's TIME attribute.

Any ideas?

 

<#assign lastMonth = dateToday - (30 * 24 * 60 * 60 * 1000) />
<#assign oneMonthAgo = lastMonth?number_to_datetime?iso_local />

<#assign top_users = rest("/kudos/authors/leaderboard?max_age=one_month").users /> <#list top_users.user as user> <div>User ID: ${user.id}</div> <#assign userAvatar = rest("/users/id/${user.id}/profiles/avatar/url").value /> <#assign userKudos = rest("2.0","/search?q=" + "SELECT * FROM kudos WHERE time > ${oneMonthAgo} AND message.author.id = '${user.id}'"?url).data.size /> <#assign userInfo = rest("2.0","/search?q=" + "SELECT * FROM users WHERE id = '${user.id}'"?url).data.items /> <a id="user_${user.id}" class="dk-component-item member" href="${userInfo[0].view_href}"> <div class="member-icon" style="background-image: url('${userAvatar}');"></div> <div class="member-name">${userInfo[0].login}</div> <div class="member-badge">[badge]</div> <div class="member-kudos">${userKudos} <span class="label">kudo<#if userKudos gt 1>s</#if></span></div> <div class="member-rank">${userInfo[0].rank.name}</div> </a> </#list>
  • You currently can't filter by time on the REST V2 kudos collection, however the REST V1 /kudos/authors/leaderboard call includes a kudos count that should be scoped to the time range you specified (in this case, the last month), and you could display that by adding this:

     

    <#assign userKudos = user.mixin.kudos.weight />

    -Doug

     

     

  • DougS's avatar
    DougS
    Khoros Oracle

    You currently can't filter by time on the REST V2 kudos collection, however the REST V1 /kudos/authors/leaderboard call includes a kudos count that should be scoped to the time range you specified (in this case, the last month), and you could display that by adding this:

     

    <#assign userKudos = user.mixin.kudos.weight />

    -Doug