# Customer.io

Before integrating and sending tests with Customer.io, make sure you've completed the following:

1. Create a campaign in Poplar
2. Upload creative (can be a placeholder creative for testing purposes - [Poplar Creative Templates](https://docs.heypoplar.com/triggered-mailing-api/using-the-tool/creative/templates))
3. Locate both your **Production Access Token** and **Test Access Token** on the [**API**](https://app.heypoplar.com/credentials) page of your Poplar Account

For the webhook request to hit our API and be accepted, there must be an **active campaign with creative uploaded** - otherwise a `400 error` will be sent back.

***

## Step 1: Campaigns

Log in to Customer.io and **click the Campaign tab** on the left. If creating a new campaign, give your campaign a name, then click **Create Campaign.**

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a7c6aea04c55712556537/file-tQZQi8IO4d.png)

## Step 2: Trigger & Workflow

Select the criteria for a customer to enter the campaign flow, then when ready click **Next.**

On the Workflow Step, **drag and drop the Send and Receive Data** action into the flow where you'd like to send your Poplar Mailer.

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a7d6bee46f05d48ed03cf/file-FvzfrskYNn.png)

## Step 3: Webhook

Click the webhook, name it, and select the **Add Request**.

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a7da6641a5b210cd26296/file-qvHb5ylfT3.png)

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a7db7ee46f05d48ed03d0/file-bjrrnv9rzM.png)

Set the URL to: `https://api.heypoplar.com/v1/mailing/`

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a7f31641a5b210cd26297/file-iNZ9GmxRn1.png)

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a7f3c641a5b210cd26298/file-iIrut9ipHa.png)

Add an HTTP Header and configure an `Authorization` key and set the `Bearer <Your API Key>` (*make sure to also delete the <>*)

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a7f9b38e94c7683947011/file-Pt0sw3mFx7.png)

Log into Poplar and setup a new test API Key for Customer.io. You can get the key at <https://app.heypoplar.com/credentials>. Copy the test API token and head back to the webhook configuration in customer.io

{% hint style="info" %}
We strongly recommend you **use a test API key** to start. Once your workflow is set up successfully and running in test mode, go back into the webhook and swap it out for a production API key to begin mailing.
{% endhint %}

## Step 4: Webhook Contents

If you're doing address enrichment you just need to pass the email in the recipient block, the campaign\_id, and any other variable data (Merge Tags). If mailing existing customer addresses, you'll pass in the full address. Note the double brackets surrounding the variable data being passed.

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a817e38e94c7683947014/file-7HnjAUYAg0.png)

**For an email append:** *the customer attribute names you have in your account may differ and need to be modified.*

```
{
  "recipient": {
    "email": "{{ customer.email }}"
  },
  "campaign_id": "REPLACE-WITH-YOUR-CAMPAIGN-ID"
}
```

**For a full address mailing:**

```
{
  "recipient": {
    "first_name" : "{{ customer.first_name }}",
    "last_name" : "{{ customer.last_name }}",
    "address_1": "{{ customer.address_1 }}",
    "address_2": "{{ customer.address_2 | default: "" }}",
    "city": "{{ customer.city }}",
    "state": "{{ customer.state }}",
    "postal_code": "{{ customer.postal_code }}"
  },
  "campaign_id": "REPLACE-WITH-YOUR-CAMPAIGN-ID"
}
	
```

| **Key**      | **Value**                                                                                                          |
| ------------ | ------------------------------------------------------------------------------------------------------------------ |
| campaign\_id | copy from the right side of the campaign page on Poplar                                                            |
| full\_name   | Optional, you can also replace with a fixed string like 'Current Resident' for use on the address block            |
| first\_name  | When using **first & last name** instead of **full name** in your webhook, you must use BOTH or it will error out. |
| last\_name   |                                                                                                                    |
| address\_1   |                                                                                                                    |
| address\_2   |                                                                                                                    |
| city         |                                                                                                                    |
| state        |                                                                                                                    |
| postal\_code |                                                                                                                    |
| email        |                                                                                                                    |

You can also add merge tags with your own variable data at the end. When using first & last name options instead of full name you need to include both or it will error.

## Step 5: Test & Go Live!

Test your webhook by sending a test, then head to your **Campaign Overview** in Poplar and scroll down to the **History** section to see successful tests come through.

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a81e25beb1700e035e2ba/file-zJVgBUURjU.png)

![](https://d33v4339jhl8k0.cloudfront.net/docs/assets/5f340c51042863444aa03abf/images/669a82127f20d506b173071c/file-u36OeYUdFe.png)

{% hint style="info" %}
We recommend leaving the webhook live with your test key for a period of time to get a sense for your volume. Once it looks like it's working well, go back in and replace the API key with a production key to begin mailing.
{% endhint %}

### **Troubleshooting**

You may see an exception when you don't have a `name` or `address_2` or other metadata you are referencing on every recipient record. It's easy to solve this using an if statement in the webhook.

{% if customer.address\_2 != blank %}

&#x20;   {{ customer.address\_2 }}

{% else %}

{% endif %}
