---
title: "How to send consent to Klaviyo via Zapier"
description: "Learn how to create a custom Zapier webhook to send SMS consent to Klaviyo. You can easily modify the instructions in this guide to send email consent as well."
canonical_url: "https://help.klaviyo.com/hc/en-us/articles/4407486310683"
markdown_url: "https://help.klaviyo.com/hc/en-us/articles/4407486310683.md"
locale: "en-us"
category: "Integrations"
section: "Migrate from an SMS platform"
updated: "2026-10-30"
---

# How to send consent to Klaviyo via Zapier

## You will learn

Learn how to create a custom Zapier webhook to send SMS consent to Klaviyo. You can easily modify the instructions in this guide to send email consent as well. 

The steps below will help you create a Zap using a webhook (also called a catch hook) that triggers a Python script action. The sample updates SMS marketing consent. Including an email address in the request does not subscribe the profile to email marketing.

**📝 Note:** This setup requires a paid Zapier plan that includes [Webhooks by Zapier](https://help.zapier.com/hc/en-us/articles/8496288690317-Trigger-Zap-workflows-from-webhooks).

## About the integration

**📝 Note:** This integration is not fully supported by Klaviyo, but can be used as a workaround if needed. We recommend only using this integration if you have developers on your team who can support it.

This guide uses a Zapier code action that runs a Python script when the trigger is detected. With this solution, you can map fields to the data types that Klaviyo endpoints require; specifically, the [Subscribe Profiles](https://developers.klaviyo.com/en/reference/subscribe_profiles) and [Unsubscribe Profiles](https://developers.klaviyo.com/en/reference/unsubscribe_profiles) endpoints.

## Before you begin

Set up SMS in Klaviyo with a sending number for the country of your test recipient. Use a real mobile number and email address you control: testing the code action changes consent in your Klaviyo account.

Have a Klaviyo private API key with `lists:write`, `profiles:write`, and `subscriptions:write` permissions. See [how to manage your account’s API keys](https://help.klaviyo.com/hc/en-us/articles/115005062267.md).

If your account uses [SMS age-gating](https://help.klaviyo.com/hc/en-us/articles/17252552814875.md), extend the subscribe request to include `age_gated_date_of_birth` before using this sample. The example below does not collect or send a date of birth.

## Set up Zapier webhook

For Zapier’s current setup instructions, see its guides to [webhook triggers](https://help.zapier.com/hc/en-us/articles/8496288690317-Trigger-Zap-workflows-from-webhooks) and [Python code actions](https://help.zapier.com/hc/en-us/articles/8496326417549-Use-Python-code-in-Zap-workflows).

1. Log in to your Zapier account.

2. From the main page in Zapier, select **+Create**, then select **Zap**.

3. Enter a name for your new Zap (e.g., Klaviyo Webhook).

4. Click the **Trigger** step, then search for and select **Webhooks by Zapier**.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/f762f3a9b73e72ca3626d6b9f7efc82dc53e2e98-1806x1228.png?auto=format)

5. From the **Event** dropdown menu, select **Catch Hook**.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/ae12e29b08b6de7ecc008517b2df5b19382cb52f-1086x1252.png?auto=format)

6. Click **Continue**. For the flat test data used in this guide, leave **Pick Off A Child Key** blank, then click **Continue** again.

7. Select the **Test** tab.

8. Copy the webhook URL that Zapier provides for you to send your requests to.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/f5e504b2106a865c17ae9d685a1cbd3d6a43c0c6-1100x698.png?auto=format)

9. Configure the app that collects consent to send consent changes to this webhook URL, including the `email`, `phone_number`, and `sms_consent` fields used below. Follow that app’s documentation to set up its outgoing webhook.

10. Before testing, you’ll need to send test data to your webhook. See our guide on [How to send test data to Zapier](https://help.klaviyo.com/hc/en-us/articles/4407493023131.md) for more information. Make sure to [format phone numbers](https://help.klaviyo.com/hc/en-us/articles/360046055671.md) in E.164 format, including the + sign and country code, when sending test data.

11. Once you’ve sent the test data to the webhook, click **Test trigger** (on the **Test** tab).




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/19228e6bcf9bb4f046da01afceb16aac6531228f-1064x1260.png?auto=format)

12. If the request is successful, you’ll see a success message, and the test data will populate below the success message, similar to the example below:




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/6e14c061b5d2c3cee56dbaa6591132dbdf5ae784-1066x1242.png?auto=format)

13. Once your trigger is working, click **Continue with selected record**.



## Set up Zapier action

1. Add an action step, then search for and select **Code by Zapier**.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/21a5047e5770824eac7be6a7ee42642a9fc04ece-1022x566.png?auto=format)

2. From the **Event** dropdown menu, select **Run Python**.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/dd0326aa0f5cb3bcd3d1dd026c43dd4eef5666d5-1096x1258.png?auto=format)

3. Click **Continue**.



## Set up field mapping and create script logic

1. In **Input Data**, map `email`, `phone_number`, and `sms_consent` to the corresponding fields in your test data. Enter the keys exactly as shown. The `name` field in the example data is not used by this script.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/83fedb3a4fc09b24fde256ad8127191cfbeb2c5a-1066x820.png?auto=format)

| **Input data** | **Test data mapped** |
| --- | --- |
| `email` | 1. Email: <Test email> |
| `phone_number` | 1. Phone Number: <Test phone number> |
| `sms_consent` | 1. Sms_consent: true |
| `name` | 1. Name: <Test name> |

Send `true` only for an explicit SMS marketing opt-in. Send `false` only for an SMS unsubscribe request: it revokes SMS marketing consent across your account and removes the profile from the selected list. Do not use `false` for an empty or unknown consent value.

1. Add a script like the one below to the code box:




```python
import requests

sms_consent = str(input_data.get("sms_consent", "")).strip().lower()
if sms_consent not in ("true", "false"):
    raise ValueError("sms_consent must be true or false")

# Configure the SMS marketing subscribe or unsubscribe request.
if sms_consent == "true":
    url = "https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs/"
    payload = {
        "data": {
            "type": "profile-subscription-bulk-create-job",
            "attributes": {
                "profiles": {
                    "data": [{
                        "type": "profile",
                        "attributes": {
                            "email": input_data["email"],
                            "phone_number": input_data["phone_number"],
                            "subscriptions": {
                                "sms": {"marketing": {"consent": "SUBSCRIBED"}}
                            }
                        }
                    }]
                }
            },
            "relationships": {
                "list": {"data": {"type": "list", "id": "LIST_ID"}}
            }
        }
    }
else:
    url = "https://a.klaviyo.com/api/profile-subscription-bulk-delete-jobs/"
    payload = {
        "data": {
            "type": "profile-subscription-bulk-delete-job",
            "attributes": {
                "profiles": {
                    "data": [{
                        "type": "profile",
                        "attributes": {
                            "email": input_data["email"],
                            "phone_number": input_data["phone_number"],
                            "subscriptions": {
                                "sms": {"marketing": {"consent": "UNSUBSCRIBED"}}
                            }
                        }
                    }]
                }
            },
            "relationships": {
                "list": {"data": {"type": "list", "id": "LIST_ID"}}
            }
        }
    }

headers = {
    "accept": "application/json",
    "revision": "2026-07-15",
    "content-type": "application/json",
    "Authorization": "Klaviyo-API-Key your-private-api-key"
}

response = requests.post(url, json=payload, headers=headers, timeout=10)
response.raise_for_status()

# Zapier requires an output object.
output = {
    "status_code": response.status_code,
    "response text": response.text
}

```

1. Replace `your-private-api-key` with your Klaviyo private API key.




**📝 Note:** Treat private API keys like passwords - keep them in a safe place and never expose them to the public.

1. Replace `LIST_ID` in both locations with your Klaviyo list ID. In Klaviyo, go to **Audience > Lists & segments**, open the list, and select **Settings > Details** to copy the **List ID**.

2. Review **Settings > Consent > Opt-in process** for that list. To subscribe without a confirmation, select **Single opt-in** and click **Save**. With **Double opt-in**, complete any SMS confirmation sent to your test number before checking its subscription.

3. Click **Continue**, then click **Test step**.

4. Check that the output shows `status_code` `202`. This means Klaviyo accepted the request for processing; it does not confirm that consent has finished updating. An empty response body is expected.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/02f9d9fa36955153d6f77394f52ac9811e6182c1-1054x1070.png?auto=format)

5. In Klaviyo, check that your test profile was added to the selected list, then open the profile and confirm that it is subscribed to SMS marketing. If a confirmation message was sent, complete that confirmation first.




![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/ab9b076299fc57db83e0455862e7dad7ea562e01-1684x584.png?auto=format)

6. Test the unsubscribe path with the same test profile: send a new webhook request with `sms_consent` set to `false`, select that new trigger record in Zapier, and test the code step again. Confirm in Klaviyo that the profile is unsubscribed from SMS marketing and removed from the selected list.

7. Once both tests are successful, click **Publish** to publish your Zap. If a test isn’t successful, check out our [troubleshooting tips](#h_01HCJNFYSXVQ1AZ4RFWWBHB47E) for common issues.



## Adapt the example for email consent

For an email-only version of this Zap:

1. Map an `email_consent` input from your source, then replace `sms_consent` with `email_consent` throughout the script. Use `true` for an explicit email marketing opt-in and `false` for an email unsubscribe request.

2. In both request payloads, replace the `sms` key under `subscriptions` with `email`. Keep the recipient’s `email` field and remove the `phone_number` field from both payloads.

3. Test both email consent paths before publishing the email version of your Zap. Check email consent on the profile, and complete any email opt-in confirmation sent during the subscribe test.



## Troubleshooting tips

The following are common issues you may run into while setting up the Zapier webhook. If you encounter any other issues, you can reach out to the [Klaviyo Community](https://community.klaviyo.com/) for further guidance.

### EOL while scanning string literal

If you see this error, then you’re missing a quotation mark around one of your variables. Check the list ID and private API key to make sure they’re surrounded on both sides by quotation marks.

### SyntaxError: invalid syntax

If you see this error, check that the code’s line breaks, indentation, quotation marks, and brackets match the sample. In particular, the `url` and `payload` assignments must be on separate lines. Lines beginning with `#` are valid Python comments and do not need to be removed.

## Additional resources

- [How to manage your account's API keys](https://help.klaviyo.com/hc/en-us/articles/115005062267.md)
  Find out how to access and manage your API keys for your Klaviyo account. 
- [How to send test data to Zapier](https://help.klaviyo.com/hc/en-us/articles/4407493023131.md)
  Learn how to send test data to Zapier via a POST request when creating a webhook to send email and SMS consent to Klaviyo.
