Overview
The Custom Rewards API feature allows you to define dynamic rewards for individual tokens instead of using fixed reward amounts. This feature is available for the following loyalty rule types: You can provide custom rewards through either:- API Endpoint: Real-time data from your external service
- CSV File: Static data uploaded to a publicly accessible URL
API Configuration
API Endpoint Setup
When using an API endpoint, you need to provide:- Custom Rewards URL: Your API endpoint URL
- API Key: Authentication key for your API
The API endpoint must be accessible from Snag’s servers and return data in the specified format. Ensure your API is reliable and has appropriate rate limiting.
API Response Format
Your API must return a paginated response with the following structure: Snag will make requests like this:Response Field Requirements
Total number of reward records available across all pages.
URL for the next page of results. Set to
null for the last page.URL for the previous page of results. Set to
null for the first page.Array of reward objects for the current page.
Pagination Support
The API supports pagination through thenext field. Snag will automatically fetch all pages until next is null.
Request Details
Snag’s servers will make the following requests to your API: Initial Request:x-api-key: The API key you provided during configurationUser-Agent:Snag-Loyalty-System/1.0
- Snag will make sequential requests to your API
- Each request has a 15-minute timeout
- Snag will follow the
nextURL from your response until it’snull - No query parameters are required for the initial request
- Your API should handle pagination through the
nextfield in responses
CSV File Configuration
As an alternative to API endpoints, you can provide custom rewards through a CSV file:CSV Format Requirements
The CSV file must have the following structure:CSV Field Requirements
Unique identifier for the token. Can be any string format.
Reward amount in points for this token. Must be a positive number.
Error Handling
API Errors
If the API is unavailable or returns an error:- The loyalty rule will continue to execute with default rewards
- An error will be logged for debugging
- Users will receive rewards based on the rule’s standard configuration
Data Validation
Invalid reward data is automatically filtered out:- Tokens with missing or invalid
tokenIdare skipped - Rewards with zero or negative values are ignored
- Malformed API responses are logged and skipped
Always test your API endpoint thoroughly before deploying to production. Ensure it returns valid data and handles edge cases properly.
Performance Considerations
API Rate Limits
- Snag will make sequential requests to your API
- Each request includes a 15-minute timeout
- Consider implementing appropriate rate limiting on your API
Data Size
- Large datasets are handled through pagination
- Consider caching frequently accessed data
- Optimize your database queries for better performance
Reliability
- Ensure your API has high uptime
- Implement proper error handling and logging
- Consider using a CDN for CSV files
Security Best Practices
API Authentication
- Use secure API keys with appropriate permissions
- Rotate keys regularly
- Implement IP whitelisting if possible
Data Validation
- Validate all input data on your API
- Sanitize token IDs and reward values
- Implement proper error responses
Your custom rewards API is ready when:
- API returns valid JSON with required fields
- Pagination works correctly
- Authentication is properly configured
- Error handling is implemented