Skip to content
Get started
Print & Mail
Integrations

Customer.io

Learn how to send physical mail through PostGrid using Customer.io Campaigns and webhook actions.

When your business requires sending mail in an effective in scalable manner, PostGrid has your solution. In this guide, we will examine how to send Print & Mail using Customer.io’s Campaigns feature. In particular, this guide will demonstrate how to send a test letter through Customer.io.

There are four stages in the process of sending mail with PostGrid

  • Creating a Campaign
  • Creating a Trigger for the Campaign
  • Adding Webhooks to the Workflow
  • Sending and Receiving the Necessary Information

After entering the Customer.io dashboard, you’ll need to ensure that you have both a verified email and account in order to successfully create and use campaigns. Refer to these docs for more information.

Moving back to the Customer.io dashboard, click the Campaigns button found on the left sidebar menu.

Customer.io dashboard left sidebar with the Campaigns button highlighted

To create a new campaign, we want to select the Create Campaign button found on the top right hand corner of the Campaigns page.

Customer.io Campaigns page with the Create Campaign button in the top-right corner

After naming your campaign, select the Create button to proceed to the campaign options.

Customer.io new campaign dialog with a name field and the Create button

A trigger is an event that initiates the campaign to proceed with the actions that it has been set up with. You will need to add an appropriate trigger that you want to use PostGrid’s Print & Mail services for.

For this guide, we will be using the When a person moves in or out of a segment trigger, which activates whenever someone enters or leaves a segment that you have created on Customer.io.

Customer.io trigger selection screen showing the 'When a person moves in or out of a segment' option

Proceed to the trigger configuration, by pressing the Next: Trigger Configuration button as shown in the image. The following settings will be dependent on what you would like to trigger the campaign. For this guide, we will be selecting the Signed Up trigger condition. Read more about Customer.io triggers here.

Customer.io trigger configuration page with the Signed Up condition selected and Next Trigger Configuration button

After selecting the desired trigger conditions, proceed to the next page with the Save & Next button on the top right hand corner of the page.

Customer.io campaign trigger setup page with the Save & Next button in the top-right corner

This guide will use the default settings provided for the campaign. Once you are satisfied with the settings, please continue to the Goals & Exit step by clicking on the Next button once again.

Customer.io campaign settings page with default configuration and the Next button to continue

For this guide, we will be using the No Goals option. Read Customer.io’s documentation on goals here.

Customer.io Goals and Exit step with the No Goals option selected

Once again, proceed to the next step of the campaign creation process and here you will find that we can define actions to be run after our trigger is set off.

An action is an event that the flow will run after the trigger is set off.

In order to access PostGrid’s Print & Mail services, we will need to use a webhook to send information to PostGrid. As such, we will need to find the Send and Receive Data option from the left-hand side menu and drag it onto the workflow.

Customer.io workflow editor with the Send and Receive Data action being dragged onto the canvas

Next, we will want to setup the webhook to communicate with PostGrid’s Print & Mail services. Select the webhook that was just dragged onto the workflow, and you should find a Add Request button that has appeared on the left side panel.

Customer.io webhook configuration panel showing the Add Request button on the left side

Depending on whether or not you want the webhook to automatically send a request to PostGrid, you may want to change the SENDING BEHAVIOR to Send Automatically, rather than Queue Draft.

Customer.io webhook sending behavior setting changed to Send Automatically

Sending and Receiving the Necessary Information

Section titled “Sending and Receiving the Necessary Information”

In the configuration window of the webhook, we will need to fill out 4 fields.

  • Request type
  • Request URL
  • Headers
  • Request Body

The value of these two fields depend on the PostGrid Print & Mail endpoint that you want to be triggered. For this guide we will be using the Create Letter endpoint, which is:

https://api.postgrid.com/print-mail/v1/letters

This is a POST endpoint, which means that it is creating new data, as opposed to deleting or retrieving data.

Customer.io webhook configuration showing the POST request type and PostGrid Create Letter endpoint URL

You can find the corresponding type and URL for other actions such as creating a contact, under our API Guide. To find the URL for the API endpoint simply navigate to the desired feature, and copy the URL found under the main header for that page. You can also find the request type beside the request URL.

PostGrid API guide showing the Create Contact endpoint with its POST request type and URL

From this image, you will notice that creating a contact uses a POST request, while getting and listing contacts use a GET request type.

Apart from the default headers provided, the only headers required for this guide will be a key, value pair labeled x-api-key. This will be your API key provided PostGrid, which can be found under Settings in the PostGrid dashboard. Click on the Add header button in order to add your API key.

Customer.io webhook headers section with the x-api-key header being added

This is a unique key used by PostGrid to associate and authenticate a given request with your account.
Note: Please be sure to enter the Test API Key if you wish to test orders and the Live API Key only if you are sure about your order.

The data in the request body is what allows PostGrid’s Print & Mail services to know the specific details of the mail you are sending, such as the recipient, the sender, and even the contents of the mail itself. For the purposes of sending a letter, we will need to provide the required fields as defined in the Body Params of the letter section of the API guide.

Note: Instead of providing HTML for the letter, you can simply provide a template_id for the desired template. Learn more about creating templates here.

Here is an example of the possible data you may want to fill in as the JSON body:

{
"to": {
"firstName": "{{customer.firstName}}",
"lastName": "{{customer.lastName}}",
"addressLine1": "{{customer.addressLine1}}",
"city": "{{customer.city}}",
"provinceOrState": "{{customer.provinceOrState}}",
"postalOrZip": "{{customer.postalOrZip}}",
"countryCode": "{{customer.countryCode}}"
},
"from": {
"firstName": "Jane",
"lastName": "Doe",
"addressLine1": "20 Bay Street",
"city": "Toronto",
"provinceOrState": "ON",
"postalOrZip": "M5J 2N8",
"countryCode": "CA"
},
"template": "template_3etohcSS7EiBxKNNKMwZFF"
}

Instead of specifying the specific contact details, another option is to simply provide a contact_id. As a result, the from field may instead look like.

"from":"contact_avPKdFJpXUxjFnnvccKzYR",

You have have also noticed that the to contact may use some rather unconventional notation. The to contact uses some custom Customer.io attribute fields. For example, by creating a customer with the following attribute fields, the previous request will actually become:

Customer.io customer profile showing custom attribute fields like firstName, addressLine1, and city

Read more about Customer.io’s attribute fields here.

If you’ve created your template using HTML, you can use that directly in the html field and replace the template field. If you’ve used our template editor to create your template, you can copy its HTML for use on Customer.io via the Raw Data section

PostGrid template editor showing the Raw Data section with copyable HTML for use in Customer.io

To test the flow, simply click on the Send test... button.

Customer.io workflow test panel with the Send test button visible

Then on the Send Test Request button.

Customer.io Send Test Request button for triggering a test webhook call

Note: Using the Live API Key will send a real order.

If the webhook is setup correctly, you will notice a notification that the request has been sent correctly. You should also notice that a letter has been created on your dashboard with the same details that you have provided in the request body.

Customer.io success notification confirming the webhook request was sent and a new letter order created

After verifying that everything is setup correctly, you can set the launch the campaign. Now you can access your desired PostGrid Print & Mail service through Customer.io!