Solution Recipe 9: Use Klaviyo Flow Webhooks to Automate Suppressions Using Segments and Klaviyo’s APIs

Rob
7 min read
For developers
June 6, 2022

Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers & technically-advanced users.

Note: We do our best to make sure any code and API references are accurate and current when this is published, but you might need to update code and it’s always a best practice to leverage our latest API versions. If you have questions, feel free to hop over to our Developer Community.

What you’ll learn

How to use webhooks to automatically suppress certain Klaviyo profiles using a segment-triggered flow and Klaviyo’s APIs.

Why it matters

Some organizations sync profiles into Klaviyo that do not have marketing consent, or are otherwise not contactable and should be suppressed. For example, merchants that sell on third-party marketplaces like eBay, Walmart, or Amazon may push order data into Klaviyo, but with obfuscated email addresses that should be excluded. By creating a segment with all qualifying profiles, this type of suppression can be automated.

Level of sophistication

Moderate

Introduction

Klaviyo flows has a webhook flow action which allow you to send customizable and dynamic HTTP POST requests with a JSON payload to a destination of your choosing within a Klaviyo flow. The most commonly discussed use cases for webhook actions involve sending data to third-party APIs or also to Klaviyo’s own APIs.

In this example we will use a webhook action to send a request to Klaviyo’s own APIs, however you can also build your own API endpoint too.

Challenge

Acme Corp is a (fictional) omni-channel clothing retailer that sells direct to consumer through an online store and various online marketplaces. They have connected an ordering system to Klaviyo, meaning all their order events are successfully syncing into Klaviyo and a Klaviyo profile is being generated for every customer.

It’s working great, except for one thing: this merchant sells through various marketplaces like eBay, Walmart, and Amazon and all order records originating in these marketplaces contain email addresses that are deliberately obfuscated.

As eBay describes it:

In the majority of cases, we don’t share buyers’ personal email addresses. We replace email addresses with aliases for buyers and sellers to hide personal contact information. When you communicate, your email appears like 63ae59ac280fe0fa69@members.ebay.com and is sent through our secure platform.
Ebay

This can create some noisy profile data in the Klaviyo account — e.g. because an obfuscated email alias by design can’t be matched up with the customer’s true email. Additionally, these marketplaces have policies that restrict the types of communications that are permitted, meaning it may not be appropriate to communicate with these email aliases. So, Acme Corp wants to just suppress these profiles from their Klaviyo account.

There are a couple potential ways to achieve this:

  1. Acme Corp could alter the integration with their eCommerce backend to avoid syncing these orders into Klaviyo in the first place, but would miss out on important revenue reporting
  2. Acme Corp could upload suppressions into Klaviyo manually via CSV files, but that doesn’t scale

By using webhooks, Acme Corp can achieve a fully automated solution.

Ingredients

  • 1 Klaviyo segment defining profiles to suppress
  • 1 Klaviyo Flow containing a webhook action
  • 1 Klaviyo API endpoint

Instructions

Step 1: Create a segment in Klaviyo

The first step is to create a segment in Klaviyo containing profiles that we want to suppress. In this example, we’re going to include any profiles where the email address contains a text string that we only see from aliases originating from Amazon, Walmart, and eBay.

Defining a segment in Klaviyo

Step 2: Create a flow triggered on segment membership

Next, we’re going to create a flow in Klaviyo that is triggered on segment membership. This means that when someone first enters the segment, they will automatically enter the flow. Keep in mind that, by design, Profiles may only enter a segment-triggered flow once.

It is pretty easy to set up. Just click into Flows and then Create From Scratch. Then select the segment you just defined as the trigger.

A flow in Klaviyo triggered on segment membership

Step 3: Choose your Klaviyo API endpoint for suppression or deletion

You can choose to either Suppress a profile, or Delete a profile from your Klaviyo account.

Suppressing a profile means the profile can no longer receive messages except for transactional messages. The profile will remain in your Klaviyo account but will be marked as suppressed. Events will still be recorded on this profile, which can be useful to have as the profile may subscribe in the future.

How a profile appears when suppressed

Deleting a profile means the profile is completely removed from your Klaviyo account, along with any event history and cannot be restored.

Step 4: Setup the webhook with the relevant Klaviyo API endpoint

Suppressing a profile

Configure the webhook as below. You will need to enter your private key in the [YOUR-PRIVATE-API-KEY] section

URL: https://a.klaviyo.com/api/profile-suppression-bulk-create-jobs/
Header 1 = accept: application/json
Header 2 = content-type: application/json
Header 3 = revision: 2024-07-15
Header 4 = Authorization: Klaviyo-API-Key [your-private-api-key]

JSON BODY
{
  "data": {
    "type": "profile-suppression-bulk-create-job",
    "attributes": {
      "profiles": {
        "data": [
          {
            "type": "profile",
            "attributes": {
              "email": "{{person.email}}"
            }
          }
        ]
      }
    }
  }
}

It should look like this when you have configured it

The configured webhook to suppress a profile

Deleting a profile

Configure the webhook as below. You will need to enter your private key in the [YOUR-PRIVATE-API-KEY] section

URL: https://a.klaviyo.com/api/data-privacy-deletion-jobs/
Header 1 = accept: application/json
Header 2 = content-type: application/json
Header 3 = revision: 2024-07-15
Header 4 = Authorization: Klaviyo-API-Key [your-private-api-key]
JSON BODY
{
  "data": {
    "type": "data-privacy-deletion-job",
    "attributes": {
      "profile": {
        "data": {
          "type": "profile",
          "attributes": {
            "email": "{{person.email}}"
          }
        }
      }
    }
  }
}

It should look like this when you have configured it

The configured webhook to delete a profile

Step 4: Test and set the flow live

Once you have your webhook configured, you can preview and test the webhook works by clicking the “Preview Webhook” button

Verify an email address has populated from your segment and click “Send Test Request”

Make sure the placeholder text has rendered an email address

If everythings works then you will get a green success bar

Successfully sent webhook indicator

Verify the profile is now suppressed/deleted and then you can set your flow live!

After you’ve confirmed that everything works well, you can set the webhook action to “live” and optionally, you can back-populate the flow to process any existing segment members. From this point, any time a profile originates in Klaviyo that qualifies into the segment, it will be automatically suppressed.

Impact

In this Solution Recipe, we look at using the Klaviyo flow webhook action to send profile data triggered on segment membership to a custom API endpoint which then sends data back to Klaviyo. This illustrates a few useful patterns that can be extended to cover much more advanced use cases, such as sending webhooks to a custom API and round-tripping data back into Klaviyo after transforming it. Sending webhooks enables wide-ranging functionality, and can greatly enhance what’s possible with Klaviyo.

Learn more!

If you’re interested in learning more about Klaviyo’s developer experience and capabilities, please visit developers.klaviyo.com!

Rob
Rob Boland

Related content

For developers
Dec 22, 2023
Account Subscription History Solution Recipe

This Solution Recipe goes over how to extract historical data regarding a profile’s subscription timeline.

For developers
Dec 4, 2023
Solution Recipe: Using AI and APIs to create and upload images to your Klaviyo account

Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers and technically-advanced users. Note: We do our best to make sure any code and API references are accurate and current when this […]

For developers
Oct 24, 2023
Solution Recipe: Append, unappend, and unset custom properties programmatically with Klaviyo

Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers and technically-advanced users. Note: We do our best to make sure any code and API references are accurate and current when this […]