Welcome to the GrowSumo Integration Docs

Here you can find guides, documentation, support and FAQs to get you setup on GrowSumo.

Chat with us by clicking the message bubble in the bottom right if you are having any trouble!

Get Started

Salesforce (APEX)

DEPRICATED

This Salesforce integration method is no longer supported. Our team may not be able to support with any issue you run into.

Please use our native Salesforce Integration.

Introduction

For this integration you must be using GrowSumoJS to track customer signups and wish to reward your influencers based on some action occurring in Salesforce. The following guide will show you how to communicate with GrowSumo through Salesforce, and give an example of how this could be implemented. However, the details will be specific to how your Salesforce instance has been configured.

Setup

To develop on Salesforce you must have a Developer Edition account and a recently created sandbox that you can title something related to the integration (e.g. GrowSumo). Once the sandbox is created login to it to begin development.

Allow GrowSumo as a Remote Site

Next we need to allow Salesforce to communicate with the GrowSumo API by creating a Salesforce remote site. To do so navigate to Setup > Security > Remote Site Settings and click New Remote Site. Set Remote Site Name to GrowSumo and Remote Site URL to https://api.growsumo.com/ and hit save.

Setting Company API Keys

For GrowSumo to know, which company in our system your Salesforce belongs to we need to access your API keys. To do this we will be creating Salesforce global custom labels. First, in a new tab, go to your GrowSumo integrations API keys and copy the production live public key.

Once the key is copied, within Salesforce navigate to Setup > Build > Create > Custom Labels and click on Create New Label. Once on the new custom label screen, add Name and Short Description as what ever you wish, making sure that the Value is your production live key pasted from the clipboard. Repeat this process with your live secret key.

Salesforce sObject Fields

To track customers on GrowSumo we must reference the unique customer_key used in GrowSumoJS. For this to be tracked on Leads in Salesforce, you must either create a new custom Lead field or use a pre-existing custom Lead field that is unique to each Lead.

Make sure that this custom Lead field is being populated with the same value used for customer_key in GrowSumoJS signup capture. Information on how to create custom fields in Salesforce can be found here.

Apex Trigger

Triggers in Salesforce determine when custom actions are preformed. If you are unfamiliar with what triggers are in Salesforce, read up on them here.

The following example will create a Trigger that is run when a Lead is converted to an Opportunity, and that Opportunity has the "Status" of "Closed/Won". Note that Salesforce Triggers can be created to run for any number of reasons, the syntax on Trigger creation can be found here.

Click on your name in the top right corner of Salesforce and select Developer Console. Once in the console select File > New > Apex Trigger. Here we set the name to GrowSumo Trigger and the sObject to Opportunity.

The following code snippet will run the GrowSumoTrigger when an Opportunity is created or updated and has the status of Won/Closed. GrowSumoCallout.makeCallout(json_op) calls a Salesforce Apex Class using the new Opportunity.

trigger GrowSumoTrigger on Opportunity (after insert, after update) {
        List<Opportunity> opportunity_records = Trigger.new;
        // only make callout if opportunity is both closed and won 
    	if (opportunity_records[0].IsWon && opportunity_records[0].IsClosed) {
            String json_op = JSON.serialize(opportunity_records[0]);
            GrowSumoCallout.makeCallout(json_op);
        } else {
            return;
        }
}

Apex Class

Classes in Salesforce can be public and are called on via Triggers. If you are unfamiliar with what classes are in Salesforce, read up on them here.

The following example Class will make a Salesforce Callout to GrowSumo and create a transaction equal to the Opportunity Amount for the customer based on unique customer_key. Note that for this to occur the custom Lead field created to represent GrowSumo customer_key must be mapped to a custom Opportunity field.

From the Developers Console select File > New > Apex Class and name the class GrowSumoCallout.

The following code snippet parses an incoming Opportunity and makes a request to GrowSumo based on the unique customer_key and the company API keys.

public class GrowSumoCallout {
    @future(callout=true)
    // take in json serialized opportunity from trigger
    public static void makeCallout(String json_op) {
        // deserialize incoming data
        Map<String, Object> data =
   			(Map<String, Object>)
      			JSON.deserializeUntyped(json_op);
        // convert amount value to value in cents
       	// create post data map
        Map<String, Object> post_data = new Map<String, Object>{
         'currency' => data.get('CurrencyIsoCode'), 
         'amount' => Integer.valueOf(String.valueOf(data.get('Amount'))) * 100
        };

        // open new http request, set content header
    	HttpRequest grsmo = new HttpRequest();        
        grsmo.setHeader('Content-Type', 'application/json');
        // set authorization header
        String login = System.Label.public_key + ':' + System.Label.secret_key;
        String API_key = EncodingUtil.base64Encode(Blob.valueof(login));
        grsmo.setHeader('Authorization', 'Basic ' + API_key);
        // format GrowSumo endpoint with customer_key
        List<String> customer_key = new String[]{String.valueof(data.get('unique_customer_id_field'))}; 
        String endpoint = 'https://api.growsumo.com/v1/customers/{0}/transactions';
        String customer_endpoint = String.format(endpoint, customer_key);
        System.debug(customer_endpoint);
        // set method, body, endpoint and send request
        grsmo.setEndpoint(customer_endpoint);
        grsmo.setMethod('POST');
        grsmo.setBody(JSON.serialize(post_data));
        HttpResponse resp = new Http().send(grsmo);
    }
}

Salesforce + GrowSumo Testing

Finally we will be testing that your integration with GrowSumo is working with the Salesforce trigger and class you have created.

  • First go to your Integrations Testing Suite and follow the on page guide for the Customer created test. After you sign up, the Request Log will show any traffic being sent to your program. Click "Test" when a successful signup event occurs.

  • How Leads are created and how you want to trigger GrowSumo influencer rewards will be specific to your Salesforce instance. To test that your created apex Trigger and Class are working properly run your Trigger on the Lead that was created from the customer in the above step. If things are working properly the Request Log will show the transaction event being sent to the correct customer with whatever amount (in cents) you have specified.