Overview
TheGET /api/loyalty/accounts endpoint enables you to fetch loyalty points balances for your users, which can be used to build features like a leaderboard in your application. With sorting and pagination options, the endpoint allows you to manage large datasets and customize the display order, making it easy to highlight the top users based on their points. Below is an example and detailed instructions for constructing a leaderboard.
Steps to Build a Leaderboard
Fetching the data
TheGET /api/loyalty/accounts endpoint allows for fetching of loyalty points balances for your users. This endpoints provides various filters to allow sorting, pagination and other filters.
- Note: if your loyalty program contains multiple loyalty currencies then use the
loyaltyCurrencyIdfilter to query for the specific currency you wish to target.
Sorting & pagination
TheGET /api/loyalty/accounts endpoint supports various query parameters that allow you to retrieve and manage data efficiently:
- Sorting: Use the orderBy filter to sort users by their points. For example, setting orderBy[amount]=desc ensures users with the highest point balances appear at the top of your leaderboard.
- Pagination:
- The limit filter determines how many entries are fetched per request. The default value is 10, but it supports up to 1,000 entries per call.
- If your dataset contains more than the specified limit (e.g., over 1,000 users), the API response will include a hasNextPage boolean property. When this is true, you’ll need to fetch additional pages.
- To fetch the next set of data, take the id of the last entry in your previous result and pass it to the startingAfter query filter in your next request.
Example Request
Request- Note: for paginated requests be sure to add the
startingAfterproperty to subsequent requests.
Example Response
Example Usage
With the above data, you can construct a leaderboard that highlights your top users. The amount field provides the points total, while the userMetadata object contains user details like their display name, social media profiles, and profile picture. Displaying these details can make the leaderboard more engaging and personalized.Accessing Full Leaderboard
If your organization has Looker Studio access enabled through Snag, you can view the full leaderboard, including all users and their loyalty point balances, directly within your Looker Studio dashboard. If Looker Studio is not yet set up for your organization, contact us to request access or an extension of your existing Looker Studio dashboard. The Snag team can help you enable the integration and ensure your leaderboard data is automatically synced for full visibility.Summary
By leveraging the /api/loyalty/accounts endpoint, you can create a dynamic points leaderboard for your application. Sorting and pagination options ensure scalability, even with large datasets, while additional user metadata allows you to create a rich and engaging user experience.Related pages
Snag Reporting
Access Looker dashboards for detailed loyalty analytics.
Badges
Create achievement badges based on points and rule completion.
User Profiles
Configure user profile fields displayed on leaderboards.
API Reference
Full REST API documentation for loyalty endpoints.