Tutorials
How to implement the GrowSurf REST API in common use-case scenarios.
Customer Example: How Bolt.new Powered Their Viral Referral Program with GrowSurf’s API
See our in-depth technical blog post on how a GrowSurf customer implemented the API, webhooks, and reward metadata to scale their referral program to millions of users.
Table of contents
The following examples use the built-in fetch available in Node.js 18 or newer.
Example 1: Trigger a referral on qualifying action (e.g, on conversion, purchase or upgrade)
This requires two API calls to GrowSurf.
Step 1: Make sure you have authentication set up
Step 2: Add the participant
Important Note: If your program is configured to add participants automatically through a form on your website (see image), skip this step.
First, in the code where you capture the new user's email, add them to your GrowSurf program as a participant with the POST Add participant method. Alternatively, you can use the JavaScript method growsurf.addParticipant() instead to add participants.
The example below is what that code could look like when using the REST API.
Code Example
The response's id is saved as growsurfId.
saveUser(user, growsurfId) is an example function for saving the GrowSurf participant ID with the new user in your database. We use this growsurfId later to trigger a referral.
The user argument passed into signUp(user) is an object that looks like this:
firstNameandlastNameidentify the participant and appear in referred friend motivator elements, if enabled.ipAddressrecords the participant IP address when available.fingerprintrecords a browser identifier when available. You can use a library like FingerprintJS to get this value.referredByassociates the new user with a referrer. It can be the referrer's email address or unique GrowSurf ID. You can usegrowsurf.getReferrerId()to retrieve the referrer ID.metadatasaves a shallow object to the Participant. This is optional, but is useful for viewing specific participant information in your GrowSurf dashboard (see image).
Step 3: Trigger the referral
Important Note: Make sure your program's referral trigger is set to Sign Up + Qualifying Action (see image). If the referral trigger is set to Sign Up, triggering referrals will not work since referral credit has already been provided.
Now at any future date within the referral credit window, if this new participant performs the goal event, then referral credit will be awarded to their referrer. To trigger the referral, use the POST Trigger referral by participant ID method.
The example below is what that code could look like.
Code Example
The growsurfId argument is the participant's unique ID. You can use the participant's email instead.
Want to honor a refund or cancellation window?
You can hold the referral credit for a set number of days before it is awarded by including an optional delayInDays value (an integer between 1 and 90) in the request body of the POST Trigger referral call. If the purchase is refunded during that window, cancel the pending trigger with the DELETE Cancel delayed referral trigger method before the credit is awarded.
Example 2: Trigger a referral on signup event
This requires just one API call to GrowSurf.
Step 1: Make sure you have authentication set up
Step 2: Add the participant (and trigger the referral at the same time)
In the code where you capture the new user's email, add them to your GrowSurf program as a participant with the POST Add participant method.
The example below is what that code could look like.
Code Example
The user argument passed into signUp(user) is an object that looks like this:
firstNameandlastNameidentify the participant and appear in referred friend motivator elements, if enabled.ipAddressrecords the participant IP address when available.fingerprintrecords a browser identifier when available. You can use a library like FingerprintJS to get this value.referredByassociates the new user with a referrer. It can be the referrer's email address or unique GrowSurf ID. You can usegrowsurf.getReferrerId()to retrieve the referrer ID.referralStatus: "CREDIT_AWARDED"awards referral credit when the participant is added and overrides the program's configured referral trigger. It is ignored unlessreferredByis also provided.metadatasaves a shallow object to the Participant. This is optional, but is useful for viewing specific participant information in your GrowSurf dashboard (see image).
Example 3: Get a participant's details
Let's say you want to display a participant's referral progress, stats, or rewards on your website or mobile app. Fetch a Participant; earned rewards are returned in its rewards array.
Step 1: Make sure you have authentication set up
Step 2: Retrieve a participant by email
Let's say your server calls your database to retrieve user details and in that same call you want to send their participant information by using their unique email.
The example below is what that code could look like.
Code Example
console.log would print something like this:
shareUrl is omitted for affiliate program participants who are not approved affiliates.
Example 4: Delete a list of participants
To remove many participants at once, send them to the POST Bulk delete participants endpoint. One request deletes up to 200 participants, and each entry can be a participant ID or an email address. The response returns a per-row status for every entry, so you can see exactly which ones were removed.
Deleting a participant is permanent. It also removes that participant's referrals, rewards, commissions, and payout records.
Code Example (Node.js)
This example reads emails from a CSV, splits them into batches of 200, and deletes each batch. Follow the steps below:
Replace
API_KEYandCAMPAIGN_IDat lines 1 and 2 in thescript.jsfile.Replace the email addresses in the
emails.csvfile with your own list of participants to delete (keep the column header labeledEmail).Run
npm install csv-parserto install the one dependency. The script uses the built-infetch, so you need Node.js 18 or newer.Run
node script.jsto run the script.
Some other notes:
Each request replaces up to
200individual delete calls, so you are far less likely to hit the rate limit. For very large lists, add a short pause between batches.A
200response does not mean every row was deleted. Check each row'sstatus:DELETED,NOT_FOUND(no participant matched the ID or email),DUPLICATE(the entry resolves to the same participant as an earlier one in the batch), orERROR(the lookup or deletion failed). Thesummaryobject totals each outcome.A single request can mix participant IDs and email addresses.
Last updated
Was this helpful?