List loyalty rules and sections
Render rule sections (rule groups) and their rules in your frontend using official APIs with pagination.
This guide shows you how to list loyalty rule sections (rule groups) and the rules under each section in your frontend. For all parameters, filters, and full response schemas, see the API references: -
Get Loyalty Rule Groups
-
Get Loyalty Rules
Prerequisites
- You can make authenticated requests with the
X-API-KEYheader. - You have your base URL (e.g.,
$BASE_URL).
How it works (at a glance)
- Fetch sections via Rule Groups.
- For each section, fetch its rules.
- Use cursor-style pagination with
startingAfterand stop whenhasNextPageis false.
1
Fetch rule groups (sections)curl -X GET "$BASE_URL/api/loyalty/rule-groups?limit=20" \
-H "X-API-KEY: $API_KEY"See full request/response details: Get Loyalty Rule Groups.
2
Fetch rules for a given sectioncurl -X GET "$BASE_URL/api/loyalty/rules?loyaltyRuleGroupId=<GROUP_ID>&limit=20" \
-H "X-API-KEY: $API_KEY"See full request/response details: Get Loyalty Rules.
3
Render in your frontend with minimal fetchersReact
// Minimal fetchers (client-side or server-side)
async function listRuleGroups(baseUrl: string, apiKey: string, startingAfter?: string) {
const url = new URL('/api/loyalty/rule-groups', baseUrl);
url.searchParams.set('limit', '20');
if (startingAfter) url.searchParams.set('startingAfter', startingAfter);
const res = await fetch(url.toString(), { headers: { 'X-API-KEY': apiKey } });
if (!res.ok) throw new Error(`rule-groups failed: ${res.status}`);
return res.json() as Promise<{ data: Array<{ id: string; name: string; slug?: string; description?: string }>; hasNextPage: boolean }>;
}
async function listRulesForGroup(baseUrl: string, apiKey: string, groupId: string, startingAfter?: string) {
const url = new URL('/api/loyalty/rules', baseUrl);
url.searchParams.set('limit', '20');
url.searchParams.set('loyaltyRuleGroupId', groupId);
if (startingAfter) url.searchParams.set('startingAfter', startingAfter);
const res = await fetch(url.toString(), { headers: { 'X-API-KEY': apiKey } });
if (!res.ok) throw new Error(`rules failed: ${res.status}`);
return res.json() as Promise<{ data: Array<{ id: string; name: string; description?: string }>; hasNextPage: boolean }>;
}
// Example usage:
// 1) const { data: groups, hasNextPage } = await listRuleGroups(BASE_URL, API_KEY);
// 2) For each group.id, call listRulesForGroup(BASE_URL, API_KEY, group.id)
// 3) Append results while hasNextPage is true (see next step)
You can see rule sections rendered and, on expanding a section, the rules
under it. Additional pages load until hasNextPage is false.
Next Steps
Now that you can list loyalty rules and sections, you're ready to: