Updating Loyalty Balances
This recipe explains how to manually update user loyalty points balances (i.e. not as part of a rule completion or spend action; an example use-case is to reset all user point balances to 0).
Overview
In some cases, you may need to manually update loyalty point balances outside the context of automated rules or spend actions. For example:
- Resetting all user balances to zero.
- Crediting or debiting points manually for a specific promotion or adjustment.
Snag provides two approaches for handling this: a no-code solution via the admin dashboard and a programmatic solution using the API.
Approaches
Admin Dashboard (recommended)
We provide a no-code solution for this via the admin dashboard. Note: this approach supports up to 250,000 balance changes per CSV upload.
Steps:
- Go to the admin dashboard: https://admin.snagsolutions.io.
- Navigate to the
Loyalty
page from the left-side menu. - Click
Update Balances
(this opens the modal for updating user balances and provides a CSV template for uploading balance changes). - Download and fill out the CSV template with the relevant balance changes.
- Upload the completed CSV file in the modal.
- Click
Add
to queue the balance changes. A rule will be created to represent the queued changes. If it does not appear immediately, refresh the page. - Verify execution:
- Click the eye icon on the created rule.
- Compare the
Rewards
count to the number of rows in your CSV file. If they match, execution is complete.
API
For programmatic updates, use the POST /api/loyalty/transactions
endpoint to create a loyalty transaction and update balances.
Endpoint: POST /api/loyalty/transactions
Request Body:
description
: Explanation for the adjustment (e.g., “Reset balances to zero”).loyaltyCurrencyId
: The ID of the loyalty currency to update.entries
: A list of transactions specifying:walletAddress
: The wallet of the user whose balance is being adjusted.direction
: Either credit to add points or debit to remove points.amount
: The number of points to credit or debit.
Example Response:
Steps
- Prepare the JSON payload with your required adjustments.
- Send a POST request to the endpoint with your payload.
- Verify the response to ensure the transaction was processed successfully.
Summary
For flexibility and simplicity:
- Use the Admin Dashboard for batch updates and non-technical workflows.
- Use the API for programmatic and highly customized updates.
Both approaches ensure your loyalty balances are kept up to date with minimal effort.
Feedback
We value your feedback! Please share your thoughts below: