Skip to content
Get started
Print & Mail
Integrations

Klaviyo

Send physical mail through PostGrid using Klaviyo Flows — covers flow setup, triggers, and webhook configuration.

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 Klaviyo’s Flows feature. In particular, this guide will demonstrate how to send a test letter using Klaviyo.

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

  • Creating a Flow
  • Creating a Trigger for the Flow
  • Adding an Action for the Flow
  • Filling in the Required Fields

After entering the Klaviyo dashboard, you’ll need to enable multifactor authentication in order to proceed. Refer to the Multifactor Authentication instructions under the profile tab.

Moving back to the Klaviyo dashboard, click the Flows button on the left sidebar menu.

Klaviyo dashboard left sidebar with the Flows button highlighted

From here, click on the ‘Create flow` button, found on the top right corner of the page.

Klaviyo Flows page with the Create Flow button in the top-right corner

Next we will want to click on the Create From Scratch button, which is also found on the top right corner of the page.

Klaviyo flow template selection page with the Create From Scratch button in the top-right corner

Finally, give the flow a name, and finish with the creation process by clicking the ‘Create flow’ button.

Klaviyo Create Flow dialog box with a name field and the Create Flow button

A trigger is an event that prompts the Flow to proceed with whatever action it is setup with. You will want to add an appropriate trigger to prompt the start of your desired PostGrid Print & Mail action.

For this guide, we will be using the Newsletter trigger, which activates whenever someone subscribes to a newsletter.

Klaviyo flow trigger setup panel with the Newsletter subscription trigger selected

Confirm the trigger, by pressing the Done button on the bottom left-hand corner.

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

Search for the Webhook action on the left-hand side panel, and drag it onto the trigger on the center of the screen.

Klaviyo flow builder with the Webhook action being dragged onto the trigger in the canvas

In the configuration window of the webhook, we will need to fill in the URL, Headers, and JSON Body fields in order to call the correct PostGrid Print & Mail API endpoint.

The URL chosen here will depend on the desired action to be performed. Since this guide is for sending letters, we will use the Letters endpoint from the PostGrid Print & Mail API, which is:

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

Klaviyo webhook URL field filled with the PostGrid Create Letter endpoint

You can find the corresponding 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.

However, due to certain limitations only API endpoints labelled, Post will be valid.

PostGrid API guide showing a POST endpoint label, indicating only POST endpoints are valid in Klaviyo

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.

Klaviyo webhook headers section showing the x-api-key field with a PostGrid API key value

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.

JSON stands for JavaScript Object Notation. The JSON body data 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": "{{ person.first_name|default:'' }}",
"lastName": "{{ person.last_name|default:'' }}",
"addressLine1": "{{ person|lookup:'$address1'|default:'' }}",
"city": "{{ person.City|default:'' }}",
"postalOrZip": "{{ person.Zipcode|default:'' }}",
"countryCode": "US"
},
"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 Klaviyo profile properties. You can learn more from their guide 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 Klaviyo via the Raw Data section:

PostGrid template editor Raw Data section with copyable HTML for use in the Klaviyo webhook body

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

Klaviyo flow builder showing the Preview button to test the webhook action

Then on the Send Test Request button.

Klaviyo webhook Send Test Request button for submitting a test API call

If the flow 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 JSON body.

Klaviyo success notification confirming the test webhook request was sent correctly

After setting everything up correctly, you can set the flow to be live. Now you can access your desired PostGrid Print & Mail service through Klaviyo!