Send attribute updates to Salesforce

PremiumThis feature is available on our Premium and Enterprise plans. Updated

While you can send data directly to Salesforce, you can also update Salesforce records based on any logic in Customer.io—people belonging to a particular segment, performing a specific event, responding to a particular message, and so on. This is a more advanced use case, but it’s a powerful way to keep your Salesforce data up-to-date with your Customer.io data.

For example, you might capture web forms in Customer.io and use this data to add leads or contacts to Salesforce automatically from Customer.io. This is a much more advanced use case, and requires some understanding of APIs. But, we can show you how it works and give you some examples to get you started.

How it works

Imagine that you want to update contacts in Salesforce when they agree to join your beta program. We’ll capture this information in Salesforce using a custom field called Beta Program Participant.

Now, there are two ways to send beta participant responses to Salesforce from Customer.io:

  1. You can call the Salesforce API directly using webhooks.
  2. Use the Customer.io API to send data to your Salesforce Destination, which sends data to Salesforce.

There are a couple of differences between the two options. In general, the first option is easier to setup but requires an understanding of Salesforce’s APIs, and you’ll need an API key from your Salesforce environment. Also, if Salesforce ever changes their APIs, your webhooks will break. The second option is harder to set up, but is more durable and would potentially let you send data to Salesforce and other destinations.

flowchart LR a(Contact opts
into beta) a-->|Send event to
Customer.io|b(Trigger campaign
containing a webhook) b-->d{Using Data Pipelines?} d-..->|no|e(Option 1: Update Salesforce
using Salesforce API) d-->|yes|f(Option 2: Send track
call to Data Pipelines) f-->g(Update Salesforce
via Data Pipelines) f-.->|optional|h(Update other destinations
via Data Pipelines)

Option 1: Use Salesforce’s API directly

This example uses Salesforce’s REST API to update contacts, but you could recreate these steps for any other Salesforce objects you want to create or update (like accounts, relationships, etc). Before you use the Salesforce API, you’ll need Salesforce API credentials—this is a bearer token that you’ll get from the Salesforce UI.

For this example, imagine you have a campaignCampaigns are automated workflows that send people messages and perform other actions when people meet certain criteria. that triggers when someone responds to a request to participate in your beta program and you want to pass your contact’s beta response to Salesforce. In the Workflow step of this example campaign, you will:

  1. Drag the Send and Receive Data block into your workflow.
    A send or receive data action added to a workflow. In the workflow, it's called a webhook.
    A send or receive data action added to a workflow. In the workflow, it's called a webhook.
  2. Select the new Webhook block, give it a Name, and click Add Request.
  3. Change Post to Patch and enter your URL for contacts. It looks like https://<YourDomainName>.my.salesforce.com/services/data/v61.0/sobjects/Contact/{{customer.id}} where YourDomainName is your Salesforce domain. Our example uses Salesforce API version v61.0, but you may want to update this depending on changes to the Salesforce API.
  4. Click Add Header. Set the Name to Authorization and the Value to Bearer <your-api-key>. If you don’t have your API key handy, you’ll need to get it from the Salesforce UI.
    set up your webhook to send data to Salesforce
    set up your webhook to send data to Salesforce
  5. In the payload, we need to match the person in Salesforce and update their betaProgramParticipant field.
    {
       "betaProgramParticipant": "{{event.beta_participant}}"
    }
    

Now, when you save and activate your campaign, Customer.io will send a PATCH request to Salesforce’s Contacts API to update the contact’s record as a part of your workflow.

Option 2: Use Customer.io’s APIs and a Salesforce Destination

This process is a bit more complex but provides more flexibility; you can use a webhook to send data to Salesforce and other destinations. To do this, you’ll need to set up a new source in Customer.io and make sure that you have a Salesforce destination to receive your data.

1. Set up your HTTP source

The HTTP source is how you’ll send data from your campaigns to Salesforce. To set up your source:

  1. In the Data Pipelines tab, click Sources.
  2. Click Add Source and select HTTP under the General category.
  3. Give your source a Name and copy API key. Keep it handy because we’ll use it in future steps!
  4. Click Complete Setup.

You’ll notice that we didn’t test your connection. We don’t have a connection to test because we haven’t set up our webhook yet!

2. Set up a destination action to update people

The action tells Customer.io what to do with your webhook. Don’t worry if you haven’t set up your webhook first. We’ll show you how to do that later and we’ll try to explain some of the steps. Essentially, we’re mapping the Customer.io data to Salesforce.

This process assumes you’ve already set up your Salesforce destination. If you haven’t, you’ll need to do that first.

  1. Now go to your Salesforce destination on the right of the Connections page, and go to the Actions tab. Click Add Action.

  2. For the Action, select Contact—this is who or what you want to update in Salesforce when you send message metrics (or webhooks) to Salesforce.

  3. For the Trigger, set Type is Track.

    A track call represents an event—something a contact did. Message metrics, and much of the data you can send with webhooks, are track events.

  4. Under Data Structure, set the first box to Update. This tells Salesforce to update a record when a contact does something in a campaign.

    You might use the Create operation if you use webhooks or you use a form integration to capture leads from a website. But those are both much more advanced use cases!

  5. In the Record Matchers field: click Add Key/Value, type in contact_id on the left and select $.userId on the right.

    This tells Salesforce to match a person’s id in Customer.io to the contact ID in Salesforce. You can also match on things like the email address. But, if you want to match on other values, you’ll want to take a look at Salesforce’s API docs first.

    Set contact_id to $.userId
    Set contact_id to $.userId

     Use $.userId not $.user.id

    If you map data to $.user.id, you’ll get an error: Undefined Traits when using update operation.

  6. At the bottom of the page, click Add Key/Value. Enter your field on the left and $.properties.betaParticipant on the right. This tells Salesforce to update the Beta Participant field with the value from your event (and webhook). You can pass additional fields here as well.

    An action showing the timestamp and beta participant fields that Customer.io will send to Salesforce.
    An action showing the timestamp and beta participant fields that Customer.io will send to Salesforce.

  7. Leave the remaining fields as their defaults and click Save Action.

3. Set up your webhook

Now we’re ready to set up your webhook. When someone agrees to join your beta program, you’ll use a webhook to update the contact’s record in Salesforce. If you use custom fields, like our betaProgramParticipant field below, you’ll need the Field Name from Salesforce, not the field label. You’ll find field names in Salesforce under Settings > Object Manager.

Imagine you have a campaignCampaigns are automated workflows that send people messages and perform other actions when people meet certain criteria. that triggers when someone responds to a request to participate in your beta program. In the Workflow step of that campaign:

  1. Drag the Send and Receive Data block into your workflow.

    drag a webhook into your workflow
    drag a webhook into your workflow

  2. Select the new Webhook block, give it a Name, and click Add Request.

  3. Set the URL to https://cdp.customer.io/v1/track and make sure Post is selected.

  4. Click Add Header. Set the Name to Authorization and the Value to Basic {{ "<your-api-key>:" | base64 }} , where the API key is the one you copied when you set up your HTTP source. The colon after the write key is significant; it is not a typo!

  5. In the payload, we need to match the person in Salesforce and update their betaProgramParticipant field.

    {
       "userId": "{{customer.id}}",
       "traits": {
          "betaProgramParticipant": "{{event.beta_participant}}",
          "signupDate": "{{event.signup_date | date: '%Y-%m-%d'}}"
       }
    }
    
    set up your webhook to send a track call to the data pipelines API. We'll forward this data to your Salesforce destination.
    set up your webhook to send a track call to the data pipelines API. We'll forward this data to your Salesforce destination.

     You need to convert dates!

    Customer.io stores dates as Unix timestamps. You need to convert them to ISO 8601 formatted dates and times for Salesforce. You can do this with liquidA syntax that supports variables, letting you personalize messages for your audience. For example, if you want to reference a person’s first name, you might use the variable {{customer.first_name}}. using the date filter in the example above. See dates and times for more information.

Now, when you save and activate your campaign, Customer.io will send a PATCH request to Salesforce’s Contacts API to update the contact’s record as a part of your workflow.

Copied to clipboard!
  Contents
Is this page helpful?