API Reference

Add participant

Adds a participant to the referral campaign.
Note: A 401 error will be returned if the following conditions are met: (1) the campaign has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser, (3) the given email is the same as an existing participant.
1
growsurf.addParticipant(data, callback);
Copied!
Parameter
Data Type
Description
data
String or Object
(Required) A String containing the participant email or an Object containing the participant email and any other data to include for the participant.
​
If providing an Object, any Object keys other than email, firstName, and lastName will be treated as metadata by GrowSurf. For more information about metadata please see our API Guidelines.
callback
Function
(Optional) A callback function that will be invoked with the added participant data if successful.
Returns a Promise that resolves with an Object containing limited participant data.

Example use

Using Callbacks
Using Promises
1
// Email only using a Callback
2
growsurf.addParticipant('[email protected]', (participant) => {
3
// handle participant
4
});
5
​
6
// Object using a Callback
7
growsurf.addParticipant({
8
email: '[email protected]',
9
firstName: 'Gavin',
10
lastName: 'Belson',
11
company: 'Hooli, Inc',
12
companySize: 10000
13
}, (participant) => {
14
// handle participant
15
});
Copied!
1
// Email only using a Promise
2
growsurf.addParticipant('[email protected]').then(participant => {
3
// handle participant
4
});
5
​
6
// Object using a Promise
7
growsurf.addParticipant({
8
email: '[email protected]',
9
firstName: 'Gavin',
10
lastName: 'Belson',
11
company: 'Hooli, Inc',
12
companySize: 10000
13
}).then(participant => {
14
// handle participant
15
});
Copied!

Example response

1
{
2
"id": "kafewp",
3
"firstName": "Gavin",
4
"lastName": "Belson",
5
"referralCount": 0,
6
"monthlyReferralCount": 0,
7
"shareUrl": "https://piedpiper.com?grsf=kafewp",
8
"rewards": []
9
}
Copied!

Trigger referral

Triggers a referral, awarding referral credit to the referrer of an existing or new participant. If the campaign participant does not exist, they will be newly added.
Note: A 401 error will be returned but the referral will still be triggered if the following conditions are met: (1) the campaign has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser, (3) the given email is the same as an existing participant.
1
growsurf.triggerReferral(data, callback);
Copied!
Parameter
Data Type
Description
data
String or Object
(Optional) A String containing the participant email or an Object containing the participant email and any other data to include for the participant.
​
If providing an Object, any Object keys other than email, firstName, and lastName will be treated as metadata by GrowSurf.
​
*This parameter is only optional if the participant has already signed up for the campaign and GrowSurf is able to determine they are a participant (does not include participants imported or manually added using the dashboard). For more information about metadata please see our API Guidelines.
callback
Function
(Optional) A callback function that will be invoked with the added or updated participant data if successful.
Returns a Promise that resolves with an Object containing limited participant data.

Example use

Using Callbacks
Using Promises
1
// Email only using a Callback
2
growsurf.triggerReferral('[email protected]', (participant) => {
3
// handle participant
4
});
5
​
6
// Object using a Callback
7
growsurf.triggerReferral({
8
email: '[email protected]',
9
firstName: 'Gavin',
10
lastName: 'Belson',
11
company: 'Hooli, Inc',
12
companySize: 10000
13
}, (participant) => {
14
// handle participant
15
});
Copied!
1
// Email only using a Promise
2
growsurf.triggerReferral('[email protected]').then(participant => {
3
// handle participant
4
});
5
​
6
// Object using a Promise
7
growsurf.triggerReferral({
8
email: '[email protected]',
9
firstName: 'Gavin',
10
lastName: 'Belson',
11
company: 'Hooli, Inc',
12
companySize: 10000
13
}).then(participant => {
14
// handle participant
15
});
Copied!

Example response

1
{
2
"id": "kafewp",
3
"firstName": "Gavin",
4
"lastName": "Belson",
5
"referralCount": 0,
6
"shareUrl": "https://piedpiper.com?grsf=kafewp",
7
"rewards": []
8
}
Copied!

Get campaign

Retrieves limited details of a campaign.
1
growsurf.getCampaign(callback);
Copied!
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked with the campaign data.
Returns a Promise that resolves with an Object containing limited campaign data.

Example use

Using Callbacks
Using Promises
1
// Using a Callback
2
growsurf.getCampaign((campaign) => {
3
// Handle Campaign
4
});
Copied!
1
// Using a Promise
2
growsurf.getCampaign().then(campaign => {
3
// Handle Campaign
4
});
Copied!

Example response

1
{
2
id: "bpsxg4"
3
}
Copied!

Get participant by email

Retrieves limited details of an existing participant. You will need to supply the unique email of the participant.
Note: A 403 error will be returned if the following conditions are met: (1) the campaign has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser.
1
growsurf.getParticipantByEmail(participantEmail, callback);
Copied!
Parameter
Data Type
Description
participantEmail
String
(Required) The email of the participant to retrieve.
callback
Function
(Optional) A callback function that will be invoked with the participant data if successful or undefined if the participant does not exist.
Returns a Promise that resolves with an Object containing the participant data. If the participant does not exist in the campaign, then undefined is returned.

Example use

Using Callbacks
Using Promises
1
// Using a callback
2
growsurf.getParticipantByEmail('[email protected]', (participant) => {
3
// Handle participant data
4
});
Copied!
1
// Using a promise
2
growsurf.getParticipantByEmail('[email protected]').then(participant => {
3
// Handle participant data
4
});
Copied!

Example response

1
{
2
"id": "kafewp",
3
"firstName": "Gavin",
4
"lastName": "Belson",
5
"referralCount": 0,
6
"monthlyReferralCount": 0,
7
"shareUrl": "https://piedpiper.com?grsf=kafewp",
8
"rewards": []
9
}
Copied!

Get participant by ID

Retrieves limited details of an existing participant. You will need to supply the GrowSurf unique identifier that was returned upon participant creation.
Note: A 403 error will be returned if the following conditions are met: (1) the campaign has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser.
1
growsurf.getParticipantById(participantId, callback);
Copied!
Parameter
Data Type
Description
participantId
String
(Required) The GrowSurf identifier of the participant to retrieve.
callback
Function
(Optional) A callback function that will be invoked with the participant data if successful or undefined if the participant does not exist.
Returns a Promise that resolves with an Object containing the participant data. If the participant does not exist in the campaign, then undefined is returned.

Example use

Using Callbacks
Using Promises
1
// Using a Callback
2
growsurf.getParticipantById('kafewp', (participant) => {
3
// Handle participant data
4
});
Copied!
1
// Using a promise
2
growsurf.getParticipantById('kafewp').then(participant => {
3
// Handle participant data
4
});
Copied!

Example response

1
{
2
"id": "kafewp",
3
"firstName": "Gavin",
4
"lastName": "Belson",
5
"referralCount": 0,
6
"monthlyReferralCount": 0,
7
"shareUrl": "https://piedpiper.com?grsf=kafewp",
8
"rewards": []
9
}
Copied!

Get referrer ID

Returns the ID of the participant that referred the visitor or null if the visitor was not referred. This method will first check to see if a grsf URL parameter exists, then will check for the presence of a referrer ID as a browser cookie (which was set from the initial visit).
Example: Someone refers their friend, and the friend visits http://yoursite.com?grsf=1h97da. Calling this method will return 1h97da (which is the referrer ID).
1
growsurf.getReferrerId();
Copied!

Example use

1
growsurf.getReferrerId();
Copied!

Example response

1
"1h97da"
Copied!

Get participant ID

Returns the ID of the authenticated participant or null if there is no participant authentication cookie present.
Example: Someone signed up as a participant in your referral program from your website. Calling this method will return aj7auu1 (which is the participant ID).
1
growsurf.getParticipantId();
Copied!

Example use

1
growsurf.getParticipantId();
Copied!
Example response
1
"aj7auu1"
Copied!

Update social share message

Updates the pre-populated social share message for the given share type (e.g, email, Facebook, Twitter). This method will update all social share buttons in GrowSurf embedded elements and the GrowSurf window.
Example: This method is useful for optimizing referral asks when your participants complete an "aha moment". You would present your participant with the GrowSurf Embedded Form element and then call this method to update social share message(s) to be specific to the "aha moment". See this tutorial for an example.
1
growsurf.updateSocialShareMessage(type, message, subjectLine);
Copied!
Parameter
Data Type
Description
type
String
(Required) The social share type to update.
These are the options:
    email
    facebook
    twitter
    pinterest
    sms
    whatsapp
message
String
(Required) The new pre-populated social share message.
Use {{shareUrl}} to reference the participant's referral link.
subjectLine
String
(Optional) The new pre-populated subject line (only applies when type is email).
Use {{shareUrl}} to reference the participant's referral link.

Example use

1
const message = "I have saved 1,540 hours using this service. Highly recommend! {{shareUrl}}";
2
const subjectLine = "Check this out!";
3
​
4
// Update the pre-populated email social share message
5
growsurf.updateSocialShareMessage('email', message, subjectLine);
6
​
7
// Update the pre-populated Facebook social share message
8
growsurf.updateSocialShareMessage('facebook', message);
9
​
10
// Update the pre-populated Twitter social share message
11
growsurf.updateSocialShareMessage('twitter', message);
12
​
13
// Update the pre-populated Pinterest social share message
14
growsurf.updateSocialShareMessage('pinterest', message);
15
​
16
// Update the pre-populated SMS social share message
17
growsurf.updateSocialShareMessage('sms', message);
18
​
19
// Update the pre-populated WhatsApp social share message
20
growsurf.updateSocialShareMessage('whatsapp', message);
Copied!

Update email invite message

Updates the pre-populated email invite message. This method will only apply updates to GrowSurf Embedded Invite elements (the email invite section within the GrowSurf window will not be updated).
Example: This method is useful for optimizing referral asks when your participants complete an "aha moment". You would present your participant with the GrowSurf Embedded Invite element and then call this method to update the email invite message to be specific to the "aha moment". See this tutorial for an example.
1
growsurf.updateEmailInviteMessage(message, subjectLine);
Copied!
Parameter
Data Type
Description
message
String
(Required) The new pre-populated email invite message.
Use {{shareUrl}} to reference the participant's referral link.
subjectLine
String
(Optional) The new pre-populated subject line.
Use {{shareUrl}} to reference the participant's referral link.

Example use

1
const message = "I have saved 1,540 hours using this service. Highly recommend! {{shareUrl}}";
2
const subjectLine = "Check this out!";
3
​
4
// Update the pre-populated email invite message and subject line
5
growsurf.updateEmailInviteMessage(message, subjectLine);
Copied!

Log out

Logs the participant out of the browser (clear's the participant's GrowSurf browser cookie and local storage).
1
growsurf.logout();
Copied!

Example use

1
growsurf.logout();
Copied!

Initialize / Reinitialize GrowSurf

Initializes or reinitializes the window.growsurf Object.
The method is useful if you have set participant authentication as required for your campaign and you would like to automatically authenticate your participants after they log in.
1
growsurf.init(settings);
Copied!
Example use
Using Callbacks
Using Promises
1
// Using a Callback
2
growsurf.init({ email: "[email protected]", hash: "HASH_VALUE" }, () => {
3
// GrowSurf is Ready
4
});
Copied!
1
// Using a promise
2
growsurf.init({ email: "[email protected]", hash: "HASH_VALUE" }).then(() => {
3
// GrowSurf is Ready
4
});
Copied!
Parameter
Data Type
Description
settings
Object
(Optional) The settings GrowSurf should use when initializing or reinitializing.
    campaignId- Provide this to initialize another campaign
    email- The email of the participant you wish to auto authenticate (only applies if authentication is enabled for your campaign).
    hash- The hash token generated by your server. Used to auto authenticate a participant (only applies if authentication is enabled for your campaign).

Open GrowSurf window

Opens the GrowSurf window.
1
growsurf.open(callback);
Copied!
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked once complete
Returns a Promise that resolves once complete.

Example use

Using Callbacks
Using Promises
1
// Using a Callback
2
growsurf.open(function() {
3
// Do something here
4
});
Copied!
1
// Using a Promise
2
growsurf.open().then(() => {
3
// Do something here
4
});
Copied!

Close GrowSurf window

Closes the GrowSurf window.
1
growsurf.close(callback);
Copied!
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked once complete
Returns a Promise that resolves once complete.

Example use

Using Callbacks
Using Promises
1
// Using a Callback
2
growsurf.close(() => {
3
// Do something here
4
});
Copied!
1
// Using a Promise
2
growsurf.close().then(() => {
3
// Do something here
4
});
Copied!

Subscribe to event

Adds an event subscription of the given event type. When an event of the given type occurs, the given callback will be invoked. Below are detailed descriptions of each event type.
1
growsurf.subscribe(eventType, callback);
Copied!
Parameter
Data Type
Description
eventType
String
(Required) The event type to subscribe to.
These are the options:
    signup
    share
    referral
    invite
callback
Function
The callback function that will be invoked when the event occurs.

Example use

1
// Subscribe to a `signup` event type
2
growsurf.subscribe('signup', (participant) => {
3
// A participant was added
4
});
5
​
6
// Subscribe to a `share` event type
7
growsurf.subscribe('share', (data) => {
8
// A participant shared their unique referral url
9
});
10
​
11
// Subscribe to a `referral` event type
12
growsurf.subscribe('referral', (participant) => {
13
// A participant was referred
14
});
15
​
16
// Subscribe to an `invite` event type
17
growsurf.subscribe('invite', (participant) => {
18
// A participant sent out an invite
19
});
Copied!

Example response

Dispatched anytime an event happens. The provided callback will be invoked with an Object containing data relevant to the event.
'signup' Event
'share' Event
'referral' Event
'invite' Event
The 'signup' Event returns limited data of the newly added participant.
1
{
2
"id": "kafewp",
3
"firstName": "Gavin",
4
"lastName": "Belson",
5
"referralCount": 0,
6
"shareUrl": "https://piedpiper.com?grsf=kafewp",
7
"rewards": []
8
}
Copied!
The 'share' Event returns limited data of the participant and the share type.
1
{
2
"participant": {
3
"id": "kafewp",
4
"firstName": "Gavin",
5
"lastName": "Belson",
6
"referralCount": 0,
7
"shareUrl": "https://piedpiper.com?grsf=kafewp",
8
"rewards": []
9
},
10
"type": "facebook"
11
}
Copied!
The 'referral' Event returns limited data of the newly referred participant.
1
{
2
"id": "kafewp",
3
"firstName": "Gavin",
4
"lastName": "Belson",
5
"referralCount": 0,
6
"shareUrl": "https://piedpiper.com?grsf=kafewp",
7
"rewards": []
8
}
Copied!
The 'invite' Event returns limited data of the participant and the number of invites sent.
1
{
2
"participant": {
3
"id": "kafewp",
4
"firstName": "Gavin",
5
"lastName": "Belson",
6
"referralCount": 0,
7
"shareUrl": "https://piedpiper.com?grsf=kafewp",
8
"rewards": []
9
},
10
"invitesSent": 3
11
}
Copied!
Last modified 2mo ago