---
title: 'List loyalty rules and sections'
description: 'Render rule sections (rule groups) and their rules in your frontend using official APIs with pagination.'
keywords: ["list loyalty rules API", "get rules endpoint", "loyalty rules query", "Snag API rules"]
---

> **For AI agents:** the complete documentation index is at [llms.txt](https://docs.snagsolutions.io/llms.txt). Append `.md` to any page URL for its markdown version.

<Info>
  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: -{' '}
  <a
    href="/api-reference/loyalty/get-loyalty-rule-groups"
    target="_blank"
    rel="noopener"
  >
    Get Loyalty Rule Groups
  </a>
  -{' '}
  <a
    href="/api-reference/loyalty/get-loyalty-rules"
    target="_blank"
    rel="noopener"
  >
    Get Loyalty Rules
  </a>
</Info>

## Prerequisites

- You can make authenticated requests with the `X-API-KEY` header.
- 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 `startingAfter` and stop when `hasNextPage` is false.

<Steps>
<Step title="Fetch rule groups (sections)">
<RequestExample>
```bash cURL
curl -X GET "$BASE_URL/api/loyalty/rule-groups?limit=20" \
  -H "X-API-KEY: $API_KEY"
```
</RequestExample>

<Note>
See full request/response details: <a href="/api-reference/loyalty/get-loyalty-rule-groups" target="_blank" rel="noopener">Get Loyalty Rule Groups</a>.
</Note>
</Step>

<Step title="Fetch rules for a given section">
<RequestExample>
```bash cURL
curl -X GET "$BASE_URL/api/loyalty/rules?loyaltyRuleGroupId=<GROUP_ID>&limit=20" \
  -H "X-API-KEY: $API_KEY"
```
</RequestExample>

<Note>
See full request/response details: <a href="/api-reference/loyalty/get-loyalty-rules" target="_blank" rel="noopener">Get Loyalty Rules</a>.
</Note>
</Step>

<Step title="Render in your frontend with minimal fetchers">
<CodeGroup>
```typescript React
// 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)

````
</CodeGroup>
</Step>

</Steps>

<Check>
  You can see rule sections rendered and, on expanding a section, the rules
  under it. Additional pages load until `hasNextPage` is false.
</Check>

## Next Steps

Now that you can list loyalty rules and sections, you're ready to:

<Card
  title="Create Your First Rule"
  icon="star"
  href="/loyalty/create-your-first-rule"
>
  Learn how to create and configure loyalty rules for your program.
</Card>

<Card
  title="Rule Configuration"
  icon="gear"
  href="/loyalty/rules-configuration"
>
  Understand how to configure rule parameters and settings.
</Card>
