Checking Rule Completion Status
Learn how to verify/check if a user has completed specific loyalty rules and received rewards
Overview
When implementing loyalty rules in your application, you often need to know whether a user has already completed a rule and received rewards. This information is useful for:
- Displaying completed rules differently in your UI
- Preventing users from attempting to complete already-completed rules
- Building custom reward history displays
Snag provides a straightforward way to check rule completion and reward status using the transaction entries endpoint.
Using Transaction Entries to Verify Rule Completion
The transaction entries API endpoint allows you to check whether a user has completed specific rules by looking for reward transactions associated with those rules.
API Endpoint
GET /api/loyalty/transaction_entries
Required Parameters
Parameter | Type | Description |
---|---|---|
userCompletedLoyaltyRuleId | string[] | Array of loyalty rule IDs to check for completion |
userId | string | The ID of the user to check |
Key Behavior
Important: When using the userCompletedLoyaltyRuleId
parameter, the endpoint will return only the latest transaction entry for each specified rule ID. This optimized behavior makes it ideal for quickly checking completion status without filtering through multiple entries per rule.
Example Request
Interpreting Results
The response contains an array of transaction entries, each representing the most recent reward transaction for a completed rule:
-
Rule is completed: If a transaction entry exists for a specific rule ID, the user has completed that rule and received rewards.
-
Rule is not completed: If no transaction entry exists for a rule ID, the user has not completed that rule or has not received rewards for it.
-
Latest entries only: Since the
userCompletedLoyaltyRuleId
parameter is used, the endpoint returns only the latest entry per rule, you’ll always see the most recent completion status, which is particularly useful for rules that can be completed multiple times (like daily check-ins).
Implementation Example
Here’s a complete example showing how to check if a user has completed specific rules and display the appropriate UI:
Related Documentation
For more information on handling rule completion, refer to:
- Verifying Rule Completion - Details on the complete process for submitting and verifying rule completion
- API Reference: Get Loyalty Transaction Entries - Full API documentation for the transaction entries endpoint
Limitations and Considerations
- For some rule types (like cadence-based rules), completion status may update on a schedule rather than immediately
- Using the
userCompletedLoyaltyRuleId
parameter, the endpoint returns only the latest entry per rule, making it efficient for checking current completion status - Cache results where appropriate to reduce API calls in your application