Forum Discussion

jaread83's avatar
jaread83
Champion
7 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

8 Replies

  • 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.

     

  • 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's avatar
    jaread83
    Champion
    7 years ago

    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.

  • Parshant's avatar
    Parshant
    Boss
    7 years ago

    jperk, Unfortunately, Its not worked for me. I tried with "ORDER BY" for all of the sort fields. its still giving online_status of same user 16 times in request for one of the community.

  • Parshant's avatar
    Parshant
    Boss
    7 years ago

    We all know best way to do this by using V2 to avoid extra calls to get all information of users.

    And for removing duplicates that need to be fix in the API at Lithium end.

    For the time being we can use V1 as I mentioned in the reply, https://lithosphere.lithium.com/t5/Developer-Discussion/Online-users-API-V2-call-brings-back-duplicates/m-p/501434#M15164

    Opened the Idea here in the idea exchange for all who are facing this issue . Up-vote the idea to add this fix at API.