Forum Discussion

Suchith's avatar
7 years ago

How to fetch Users Data based on Sort or Order by id Using V2 API.

Hi, 

I have couple of question regarding Fetching User Data using V2 API.

In my use case. I want to fetch all the registered user from community. For this, I am getting total count of user and later am using limit and offset to get the actual data.

Total count of users rows:
https://api.lithium.com/community/2.0/<Tenant_Id>/search?q=select+count(*)+from+users

Fetching User Data:
https://api.lithium.com/community/2.0/<Tenant_Id>/search?
q=select+*+from+users+limit+25+offset+0

Note: I will be incrementing offset by 25 each iteration.

Question 1: When I increment the offset each time, will there be any possibility to get the same row?  (Reference: https://lithosphere.lithium.com/t5/Li-Discussions/Boards-and-Users-order-by-ID/m-p/486509)
Question 2: Is it possible to Sort or Order by  User ID?
Question 3: Is it possible  to fetch the User data based of ID range?

Looking forward to hear about this


  • Suchith

     Most of the user's field does not exist for object 'users' as a sort constraint, not even id. But you can sort it by registration time. It would work in an expected way. 

    select * from users order by registration_data.registration_time desc

    When you increment the offset each time, it would not fetch the same result again. 

3 Replies

  • Suchith

     Most of the user's field does not exist for object 'users' as a sort constraint, not even id. But you can sort it by registration time. It would work in an expected way. 

    select * from users order by registration_data.registration_time desc

    When you increment the offset each time, it would not fetch the same result again. 

  • VikasB's avatar
    VikasB
    Boss
    7 years ago

    Suchith

    Yes, login constraint will also work here with user API.  Both the APIs will resolve your duplicate entry problem.

     

    1. Order By login ascending 
      It will sort the results alphabetically.  i.e. Alan, Bob, Caty etc

    2. Order by registration_time ascending
      It will sort the results by ids i.e.  1,2,3,4