Tutorials
How to implement the LoyaltySurf REST API in common use-case scenarios.
Last updated
Was this helpful?
How to implement the LoyaltySurf REST API in common use-case scenarios.
Last updated
Was this helpful?
The following examples use NodeJS.
Trigger a loyalty action by calling the endpoint .
Let's imagine that you want to reward a user with a free trial day if they use a feature in your product for uploading a file. This allows the user to get acquainted with your product and you can reward them for the interaction.
You can accomplish this by triggering a loyalty action for your user. The example below is what that code could look like when using NodeJS.
Code Example
At line 5, replace 4pdlhb
with your LoyaltySurf campaign ID. This can be found within the browser's URL bar of any webpage that you are viewing your LoyaltySurf campaign from.
At line 16, set participantEmail
with your user's email address (the person who just completed the loyalty action).
At line 17, set rewardId
with the Reward ID that you want to trigger a loyalty action for. You can find this value in the Rewards tab or the Installation tab of the LoyaltySurf campaign editor.
Once you trigger a loyalty action, your user will get added to your LoyaltySurf campaign if they do not already exist. Any future loyalty actions that are triggered by the same email address will increment the existing participant's loyalty action count.
The example below is what that code could look like in NodeJS.
Code Example
At line 5:
Replace 4pdlhb
with your LoyaltySurf campaign ID. This can be found within the browser's URL bar of any webpage that you are viewing your LoyaltySurf campaign from.
Replace gavin@hooli.com
with your user's email address (the person you want to retrieve loyalty program details for).
At line 21, the console.log(body)
will output a response that looks like the below example:
At line 7, replace <YOUR_API_KEY>
with your API key, which you can get from your .
Once the loyalty action is triggered, and if the campaign reward's loyalty action conversion threshold is 1, then a reward will be generated for the participant. You can set up to automate the reward of giving out the free trial day.
Alternatively, you may also use , , , , , or to automate rewards.
With the REST API, you can retrieve a participant's LoyaltySurf rewards or loyalty action count to display on your website or mobile app using the or endpoints.
At line 7, replace <YOUR_API_KEY>
with your API key, which you can get from your .