Forum Discussion

octavian_krody's avatar
3 years ago

How to retrieve all user badges using LIQL search on the user collection?

Hello,

Do we need pagination for that field? or does it output all user_badges available for the user in one shot?

I'm aware that liql queries can add a limit / offset (up to 1000 entries), or use the next_cursor field but how do we do it for the nested user_badges entries?

As far as I can see the nested badge entries also have a size but no cursor attached to them. Didn't see a way to restrict limits / offsets for inner elements as most relationships that are available in the api and documentation are for top relationships only.

The /api/2.0/users/<id>/badges responds with 404.
The /restapi/vc/users/id/<id>/badges doesn't seem to show pagination as well.
The liql endpoint /api/2.0/search?q=select user_badges from users where id="<id>"  doesn't show a mean to paginate the inner relationship.

Any thoughts?

  • Hello:

    Unfortunately, in LiQL while it is possible to obtain all of the badges for a user with something like the below query, it won't allow the use of LIMIT for that field or ORDER BY.  

    select user_badges from users where login=<USER_LOGIN>

    You will get all the badges for a user, but you are correct that this particular nested field cannot be paginated.

    Thank you,

    Roger

  • RogerW's avatar
    RogerW
    Khoros Alumni (Retired)

    Hello:

    Have you tried using page_size via APIv1?  You can couple that with sorting similar to below and it will limit the returned results to the most recent earned <PAGE SIZE> badges.

    /restapi/vc/users/id/<USER-ID>/badges?page_size=<INTEGER>&user_badges.sort_order=earned_date_desc

    Here is a link to the badges API 

    https://devdocportal.khoros.com/t5/Community-API-v1-Reference/bd-p/restv1docs?section=commv1&leaf-id=User.badges#User.badges

    Hope that is helpful.

    Roger

     

    • Is there any way of doing this with liql or v2? as we would prefer not to enable v1 access just for this use case.

  • RogerW's avatar
    RogerW
    Khoros Alumni (Retired)

    Hello:

    Unfortunately, in LiQL while it is possible to obtain all of the badges for a user with something like the below query, it won't allow the use of LIMIT for that field or ORDER BY.  

    select user_badges from users where login=<USER_LOGIN>

    You will get all the badges for a user, but you are correct that this particular nested field cannot be paginated.

    Thank you,

    Roger

    • Thank you Roger!

      As long as we get them all pagination is of no concern, as we don't have that many to begin with.