1. US Knowledge base
  2. API
  3. Third Party Intergration

How to Set Up a Webhook in Klaviyo to Create a Postcard Using Stannp API

This guide explains how to configure a webhook in Klaviyo to automate the creation of postcards using the Stannp API.

Prerequisites

  1. API Key: Obtain your Stannp API key from your Stannp account.
  2. API Endpoint: Use the following endpoint for the webhook:
    https://api-us1.stannp.com/v1/postcards/create
  3. A Flow in Klaviyo: Create or open a flow in your Klaviyo account to integrate the webhook.
  4. Recipient Data: Ensure that the necessary data (e.g., recipient name, address) is available in Klaviyo profiles or event properties.

Steps to Create the Webhook

Step 1: Create or Open a Flow in Klaviyo

  1. Log in to your Klaviyo account.
  2. Navigate to Flows in the left-hand sidebar.
  3. Select an existing flow or click Create Flow to build a new one:
    • Add a trigger, such as "Placing an Order" or a custom event, depending on when you want the webhook to be sent.

Step 2: Add a Webhook Action

  1. Within the flow editor, click + Add Action.
  2. Select Webhook from the action list.

Step 3: Configure the Webhook

URL and Method

  1. Set the Request URL to the following:
    https://api-us1.stannp.com/v1/postcards/create?api_key=YOUR_API_KEY
    Replace YOUR_API_KEY with your Stannp API key.
  2. Select POST as the HTTP method.

Step 4: Construct the Request Body

Add the parameters in JSON format. Depending on your use case, you must include either the template or both the front and back parameters in the body. Use Klaviyo’s dynamic tags to populate recipient data from profiles or event properties.

Example Body with Template:

{
"test": true,
"template": 67890,
"size": "6x9",
"recipient": {
"title": "Mr.",
"firstname": "John",
"lastname": "Doe",
"address1": "123 Main Street",
"address2": "Apt 4B",
"city": "Springfield",
"postcode": "12345",
"country": "US"
},
"tags": "promotion, offer",
"addons": "FIRST_CLASS",
"post_unverified": false
}

Example Body with Front and Back Parameters:

{
"test": false,
"size": "4x6",
"front": "https://example.com/front_image.jpg",
"back": "https://example.com/back_image.jpg",
"recipient": {
"firstname": "Jane",
"lastname": "Smith",
"address1": "456 Elm Street",
"city": "Metropolis",
"postcode": "54321",
"country": "US"
},
"tags": "event, invitation",
"addons": "FIRST_CLASS",
"post_unverified": true
}

Step 5: Test the Webhook

  1. Save the webhook action.
  2. Manually trigger the flow using a test profile or event to send the webhook.
  3. Verify that the Stannp API responds successfully by reviewing logs in the Stannp platform.

Step 6: Activate the Flow

  1. Once you’ve tested and confirmed that the webhook works correctly, activate the flow in Klaviyo.
  2. Monitor the flow to ensure that the webhook is sending data as expected.

Additional Notes

  • Testing Mode: Use the test parameter set to true to produce a sample PDF without dispatching the postcard.
  • Error Handling: If the webhook fails, check the webhook log in Klaviyo or review the Stannp API error response.

By following these steps, you can seamlessly integrate postcard creation with Stannp into your Klaviyo flows, enabling automated and personalized direct mail campaigns.