Website: https://www.salesforce.com/ API Docs: https://developer.salesforce.com/page/Salesforce_APIs
Salesforce is a customer relationship management (CRM) solution. In our example, we're going to show you how to configure Salesforce to send leads from Customer.io into Salesforce.
In this walkthrough, we'll first show you how to configure Salesforce to enables its API and connect Customer.io as a "Connected App". Then, we'll show you how to create a lead in Salesforce with Customer.io.
Let's make sure API access is enabled in Salesforce first. The easiest way to test this is by opening the “Developer Console” from the “Setup” menu and to open a resource.
This will open the Developer Console in a new window. Navigate to “Open Resource” in the “File” menu.
If API access is enabled, you should see another window with the available resources. If API access is disabled, you'll either see a message like "The REST API is not enabled for this Organization." or "API_DISABLED_FOR_ORG".
If your Salesforce API access is disabled, you'll have to contact your Account Manager and have them enable it for you.
Navigate to the “Setup Home”. Go to the “Apps” under “Platform Tools” and create a new “Connected App”.
For the Connected App check the “Enable OAuth Settings” checkbox and select “Full Access” scope.
Once created, you'll have access to the “Consumer Key” and “Consumer Secret” which will be used in the final request to get the access token.
By default, IP restrictions are enforced—so you can either add “Trusted IP Range for OAuth Web server flow” or change the settings to disable IP restrictions.
In order to disable the IP restrictions, click the “Manage” button for the app and then click the “Edit” button. Next, set the IP relaxation setting to “Relax IP restrictions”.
The final piece of information needed is your security token. Navigate to your personal settings, then to “Reset My Security Token”, and click the “Reset Security Token” button. Your token will be emailed to you.
Now you can generate access tokens to authorize web requests to update Salesforce.
Replace the [variables] in the curl request below and make the request:
curl -XPOST https://login.salesforce.com/services/oauth2/token \
-H "X-PrettyPrint: 1"
This will return a response like:
"access_token" : "00D50000000NGi2!AQQAQH9ob.5uh.QjYSmJ71mTxya8ziK.Y_Z7q8kNsTFJoF0jJEJEBLKo_zBNKMFbHx253rzrjk84WGHl4.YdSaxLsIqO2iA9",
"instance_url" : "https://na3.salesforce.com",
"id" : "https://login.salesforce.com/id/00D50000000NGi2EAG/00550000005pnXCAAY",
"token_type" : "Bearer",
"issued_at" : "1469540453130",
"signature" : "9vlwhHvRx+8N2QVbpDxsneQGGW7mNkYU+FGjLPB7ykQ="
We will be using the instance_url and the access_token for our web requests.
You can use either an event triggered or a segment triggered campaign depending on which best suits your use case. For this tutorial, we'll use a segment triggered campaign with the default “Signed Up” segment.
On the workflow page select “Webhook” from the “Add Action” dropdown. We'll call our webhook "Create Salesforce Lead"
Next, click "Add Request" button on the webhook to configure its details.
In the composer view, we'll set up the URL, authorization headers, and the request body to be able to generate leads in Salesforce. In this step, we'll use the instance_url and the access_token from the Salesforce call we made earlier.
The url for the request will be:
A few points to note about the URL:
So for our example, the URL looks like this:
Next, click “Add Header” and provide your access_token. The name of the header should be “Authorization” and the Value must be “Bearer [access_token]”.
In order to create a lead in Salesforce, you’ll likely want to send details like name, email address, and custom data. For our example, we'll send three attributes to Salesforce: first name, last name, and company name.
(Since we're passing the email address in the URL, we don't need to specify it in the body. Salesforce will automatically associate the email with the record.)
If you have customers in your account that match the trigger, you can use one of them to preview the request body as well to send a test request to ensure they end up in Salesforce.
Use the “Send Request” button to make the call and create the lead on Salesforce. You will be prompted to confirm that you wish to send the the web request, after which you should get the 201 Created response from the API call.
Salesforce uses the email as an unique id, so that if you send a request for an existing user, you should get back a 204 No Content response, where the existing record would be updated with any changes.
Finally we can confirm that everything works correctly by looking up the lead in Salesforce.
Note! The Salesforce access tokens expire frequently, and therefore need to be updated. Otherwise, requests will fail due to lack of authorization.
Also note: Salesforce limits the number of requests you can make in a 24-hour window. Exceeding it will cause all subsequent requests to fail. The limit is tied to number of account licenses.
Need a hand? Let us know! We're happy to help.