Forum Discussion

jaread83's avatar
jaread83
Champion
6 years ago

Online users API V2 call brings back duplicates

I am trying to bring back a list of all online users using the V2 api but when trying it out on the live environment, it shows a lot of duplicates - possibly other browser sessions? Not sure.

Is it possible to remove these duplicates in the API call?

Here is my code:

<#assign query = "SELECT id, login, avatar, view_href, rank.id, rank.name FROM users WHERE online_status = 'online' LIMIT 100" />
<#assign res = restadmin("2.0", "/search?q=${query?url}?").data.items />

Any help would be greatly appreciated!

Thanks,

Jack

  • We had a similar problem when retrieving all users. It was resolved by specifying an ORDER BY. It seems that's the only way to avoid duplicates.

  • jaread83,

    If you are facing issue with V2, you can use V1 API with below code to fetch online users count and user data.

    For online users count:

    <#assign OnlineUsersCount = restadmin('/users/online/registered/count').value />

    For online users information:

     

    <#assign OnlineUsers = restadmin('/users/online/registered').users />

    and you can use "OnlineUsers" in list loop to get all the users related data.

    Hope this helps.

     

    • jaread83's avatar
      jaread83
      Champion

      The V1 api does not have all the information i need such as the rankname or avatar. In my previous version of my component it was performing a request on each item to get this information and and it would have too many requests and slow the pages down. V2 api has all the information i need without needing to do more requests within the loop.