--- title: Customer.io | PostGrid description: 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. ## Overview 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 ## Customer.io Setup After entering the [Customer.io dashboard](https://fly.customer.io/), 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](https://www.customer.io/docs/account-verification/) for more information. ## Creating a Campaign 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](/_astro/01-image.45AtfjH4_1kDQhB.webp) 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](/_astro/02-image.DPe7K9a6_2rSWrI.webp) 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](/_astro/03-image.B3yiyOse_Z10t0I5.webp) ## Creating a Trigger 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](/_astro/04-image.gyDLny0v_1dSlaJ.webp) 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](https://customer.io/docs/campaign-triggers/). ![Customer.io trigger configuration page with the Signed Up condition selected and Next Trigger Configuration button](/_astro/05-image.D0WMryE4_ZJz54L.webp) 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](/_astro/06-image.D_PEeVGk_noIl0.webp) 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](/_astro/07-image.IBj5HGwD_1F3RKs.webp) For this guide, we will be using the `No Goals` option. Read Customer.io’s documentation on goals [here](https://www.customer.io/docs/campaign-conversions/). ![Customer.io Goals and Exit step with the No Goals option selected](/_astro/08-image.4495D80g_Z1ftHV1.webp) 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. ## Adding Webhooks to the Workflow 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](/_astro/09-image.ByYJ-myF_2sQiFu.webp) 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](/_astro/10-image.DvCHIOpb_2iYiuN.webp) 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](/_astro/11-image.BYcpqer6_ZN57m0.webp) ## 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 ## Filling in the Request Type and URL 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](/_astro/12-image.BtM2jxd2_1Vg3a8.webp) You can find the corresponding type and URL for other actions such as creating a contact, under our [API Guide](/api/index.md). 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](/_astro/13-image.Cf9GVcz0_Z79nBH.webp) From this image, you will notice that creating a contact uses a `POST` request, while getting and listing contacts use a `GET` request type. ## Filling in the Headers 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](https://dashboard.postgrid.com/dashboard/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](/_astro/14-image.Bzvrjb4M_8m3qU.webp) 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. ## Filling in the Request Body 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](/api/index.md) 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](/api/index.md). 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" } ``` ## Getting the contact information 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](/_astro/15-image.C3Y4C73V_ZFxzgG.webp) Read more about Customer.io’s attribute fields [here](https://www.customer.io/docs/attributes/). ## Getting the HTML and Template 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](/_astro/16-image.DvPI9gjo_fgdWk.webp) ## Wrapping Up To test the flow, simply click on the `Send test...` button. ![Customer.io workflow test panel with the Send test button visible](/_astro/17-image.C2Q-46Ji_2iQWA5.webp) Then on the Send Test Request button. ![Customer.io Send Test Request button for triggering a test webhook call](/_astro/18-image.DRXhA6g1_1Mqzny.webp) **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](/_astro/19-image.CtfIw7Oe_2iGc8L.webp) 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!