Klayvio
Last updated
Last updated
Klaviyo is a popular marketing automation software tool. It frequently uses integrations like Shopify to external systems like Lob. In early 2022, Klaviyo added webhook functionality, enabling a direct connection to Lob (prior to this, data had to be extracted from Klaviyo and passed to Lob via a separate system). Klaviyo’s webhooks can be used to automatically trigger a mailpiece to be sent, via Lob, within a user Flow.
Klaviyo’s webhook functionality within their flows interface provides an easy connection point to trigger automated, personalized Direct Mail.
We’ll assume you have a account and you have already registered with (for your API Keys and the like) to follow along.
In order to send mail from Klaviyo, Lob requires a mailing address to be stored for each profile. Klaviyo does not require mailing addresses by default, so before attempting to send mail, ensure that your recipient profiles contain properties for:
Address
City
State
Zip Code
If you are importing new profiles to Klaviyo, simply ensure that you have CSV columns for each of those properties. An example CSV to import Profiles is .
In the Klaviyo dashboard’s left-hand panel, click on Flows. Then click to Create Flow, then select a predefined goal, or click Create From Scratch and give your flow a name. Then choose a Trigger Setup option in the left panel.
For this example, we will be selecting List, and choosing a list from the resulting drop-down to trigger the flow.
Once you have configured your trigger, an actions menu will appear on the left panel. Select Webhook, and drag it into your flow beneath the trigger.
Select the Webhook in your Flow, and the configuration panel will appear on the left side. You can configure it as follows:
This is where you will enter the Lob API URL for the mail format you would like to trigger.
Example: https://api.lob.com/v1/postcards
. Note that Lob has separate endpoints for various mail formats.
This is where you will enter the headers Lob requires in order to correctly process and authenticate the incoming requests.
You will be required to enter at least two headers: Content-Type and Authorization. Click Add Header.
For the Content-Type header, enter the following:
Key: Content-Type
Value: application/json
For the Authorization header, you will need your API keys.
Ensure you are using your Test API key, not Live API key.
For example, if your API key was test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc
, you would enter test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc:
into a Base64 Encoder tool, the result of which would be something like dGVzdF8wZGM4ZDUxZTBhY2ZmY2IxODgwZTBmMTljNzliMmY1YjBjYzo=
.
Note that we added a colon (:
) to the end of the API key before encoding it, you are recommended to do the same.
Once you’ve encoded your API key, add the Authorization Header and use the encoded key as the value. For example:
Key: Authorization
Value: Basic dGVzdF8wZGM4ZDUxZTBhY2ZmY2IxODgwZTBmMTljNzliMmY1YjBjYzo=
This is where you will pass Lob the information that informs the mailpiece. The field names (name
, address_line1
, etc) represent the information that Lob’s API will require. The values on the right represent what you will pass to Lob to populate the given field.
The values can be mapped to attributes from Klaviyo profiles by using Klaviyo’s Profile Variables. You can find the Profile variables for each attribute by taking the following steps:
Note that if you are copying the below example, you will want to replace the values being passed for ‘front’ and ‘back’ with your own Lob template IDs or linked creative.
You will want to replace the values being passed for ‘front’ and ‘back’ with your own Lob template IDs or linked creative. For example:
You can test that your webhook is configured correctly by clicking on ‘Preview Webhook’.
The resulting panel will show an example of the data being passed to Lob for a specific Profile. You can look at the JSON to verify that the Klaviyo Profile Variables are being correctly replaced. For example, instead of {{ person|lookup:'$address1'|default:'' }}
you will see an address, such as ‘185 Berry St.’
If this all looks correct, double-check that you used your Test API Key (rather than your Live API Key), then click on Send Test Request. If it was configured correctly, you will see the message: "Successfully sent webhook."
You can then log into your Lob account to verify that your postcard was generated. (The below is the result of the example creative.)
You will need to add payment information to your Lob account should you actually wish to print and send mailpieces. When you are ready, you can replace your Test API key with your Live API key. If you are using other test resources like address IDs or template IDs, those will also need to be transferred to your live environment.
Note: the "testing" functionality in Klayvio is sending a one-off request to Lob, this means if you have your LIVE API key in the template, it will create mail and if you have your TEST key it will not.
401 Unauthorized
If you receive this error message, your API key is incorrect.
Make sure you have the header Authorization and that you are encoding your secret API key as explained above
422 Unprocessable Entity (Invalid request payload JSON format)
If you receive this error, it is likely that your payload is not formatted correctly. It needs to match JSON formatting.
Generally speaking, the rules that are often broken are:
All keys and values are enclosed in double quotes (").
Commas after every key-value pair except for the last one.
No newline characters in any values and no extra spaces between fields.
422 Unprocessable Entity (Other)
Other than JSON errors, you can receive 422
errors in the payload sent to Lob does not match our requirements.
For example, if you are missing address_line1
in the payload you will get an error saying that is needed. For these errors, you can make the appropriate adjustments and retry your requests.
For the Authorization header, you will need to have your Base64-encoded Lob API key ready to enter, so Lob can associate the request with your account. You can find your in your Lob account settings, and you can use a to encode it.
An example of a populated JSON body could look something like the following. You can find more information on each of these fields in our .
"front": “"
"back": ""
For more about designing/formatting creative for Lob, .
Make sure when you are testing that your are set to an ample time (2 hours is recommended) to make sure you can always cancel mail if you make a mistake.