Tutorials
How to implement the GrowSurf REST API in common use-case scenarios.
Last updated
Was this helpful?
How to implement the GrowSurf REST API in common use-case scenarios.
Last updated
Was this helpful?
See our in-depth technical on how a GrowSurf customer implemented the API, webhooks, and reward metadata to scale their referral program to millions of users.
The following examples use Node.js.
Scenario
"Send a friend $40 in Airbnb credit. You’ll get $20 when they travel and $75 when they host."
Follow this tutorial if your campaign's is Qualifying Action, where a referrer only receives credit when the person they referred signs up AND performs a certain qualifying action.
This requires two API calls to GrowSurf.
The example below is what that code could look like when using the REST API.
Code Example
At line 21, we set the GrowSurf participant ID as a variable called growsurfId
.
At line 23, saveUser(user, growsurfId)
is an example function you would use to save the GrowSurf participant ID to the new user in your database. We will use this growsurfId
value later for triggering a referral.
growsurfId
to your database?The participant'semail
can be used instead of the growsurfId
to trigger a referral later. If you have access to the participant's email then there is no need to persist the growsurfId
into your database.
At line 11, the user
argument passed into signUp(user)
is an Object that looks like this:
At lines 2 and 3, we pass in firstName
and lastName
. These will be used for anti-fraud purposes, as well as in referred friend motivator elements, if enabled.
At line 4, we pass in the user's IP address, which will be used for anti-fraud purposes.
The example below is what that code could look like.
Code Example
At line 11, we passed a growsurfId
argument, which is the GrowSurf participant's unique ID and is required in the API call. If you do not have access to the growsurfId
of the participant, the participant email
can be used instead.
"For every friend you refer, you’ll both receive an extra 250MB in cloud storage."
This requires just one API call to GrowSurf.
The example below is what that code could look like.
Code Example
At line 12, the user
argument passed into signUp(user)
is an Object that looks like this:
At lines 2 and 3, we pass in firstName
and lastName
. These will be used for anti-fraud purposes, as well as in referred friend motivator elements, if enabled.
At line 4, we pass in the user's IP address, which will be used for anti-fraud purposes.
Note: referralStatus
must be used with referredBy
, or else it will be ignored.
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
At line 10, we passed userEmail
so we could set it in the GrowSurf API URL at line 16.
At line 20, console.log
would print something like this:
Code Example (Node.js)
In this example, we've provided two sample files you may download and use. Follow the instructions below:
Replace API_KEY
and CAMPAIGN_ID
at lines 1 and 2 in the script.js
file, respectfully.
Replace the email addresses in the emails.csv
file with your own list of participants that you want to delete (keep the column header labeled as "Email")
Run npm install request require csv-parser
to install dependencies
Run node script.js
to run the script
Some other notes:
The script will display progress and status updates for each deletion operation.
Depending on the number of participants, the deletion process may take some time. Please be patient.
Important Note: If your campaign is configured to add participants automatically through a form on your website (), skip this step.
First, in the code where you capture the new user's email, add them to your GrowSurf campaign as a participant with the method. Alternatively, you can use the JavaScript method instead to add participants.
At line 5, we pass in the user's browser fingerprint, which will be used for anti-fraud purposes. You can use a library like to get this value.
At line 6, we use referredBy
to associate this new user with a referrer. This value can be the referrer's email address or unique GrowSurf ID (you may want to use to retrieve the referrer ID).
At line 7, we save a shallow metadata
Object to the GrowSurf Participant. This is optional, but is useful for viewing specific participant information in your GrowSurf dashboard ().
Important Note: Make sure your campaign's referral trigger is set to Sign Up + Qualifying Action (). 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 , if this new participant performs the goal event, then referral credit will be awarded to their referrer. To trigger the referral, use the method.
Make sure you have or set up so that rewards automatically get fulfilled to the participant once they reach a reward goal.
Follow this tutorial if your campaign's is Signup Event, where a referrer receives credit when the person they referred signs up with their email address.
Important Note: If your campaign is configured to add participants automatically through a form on your website (), skip this step.
Important Note: Make sure your campaign's referral trigger is set to Signup Event ().
In the code where you capture the new user's email, add them to your GrowSurf campaign as a participant with the method.
At line 5, we pass in the user's browser fingerprint, which will be used for anti-fraud purposes. You can use a library like to get this value.
At line 6, we use referredBy
to associate this new user with a referrer. This value can be the referrer's email address or unique GrowSurf ID (you may want to use to retrieve the referrer ID)
At line 7, we set referralStatus
to be CREDIT_AWARDED
. This triggers the referral credit at the same time that this new participant is added (and it overrides the campaign referral trigger () that was set from the Installation step of the Campaign Editor ().
At line 8, we save a shallow metadata
Object to the GrowSurf Participant. This is optional, but is useful for viewing specific participant information in your GrowSurf dashboard ().
Make sure you have or set up so that rewards automatically get fulfilled to the participant once they reach a reward goal.
Let's say you want to display a participant's referral progress/stats/rewards in your website or mobile app. With the REST API, you can fetch s and s by using either of the following API methods:
Let's say you want to delete a list of participants in your GrowSurf Campaign. With the REST API, you can use the endpoint to loop through a CSV list of participants to accomplish this.
The script will begin deleting participants one by one, waiting 1 second between each request to comply with our .