In this project we are going to learn step by step how to interact with the API of a tool like Klaviyo so you can connect it with 3rd parties. Since Klaviyo has no native integration with Zapier, this is the perfect excuse to deep in the webhooks feature provided by Zapier
Klaviyo is a tool that not only allows you to set email marketing tools, but also pulls data from your ecommerce platform, point-of-sale software, and other marketing tools.
Zapier is a tool that allows you to connect apps you use every day to automate tasks and save time. You can connect any of our 750+ integrated apps together to make your own automations. If it’s the first time you are checking Zapier, perhaps this is a good starting point to understand how it works.
Klaviyo API docs and setting up our zap trigger
First things first: if you want to follow all the steps we will do in the project, you would need to create a trial account (if you don’t have already a paid account) in each one of the platforms:
First thing we are going to create is a Zap. A Zap is a blueprint for a task you want to do over and over. In words, a Zap looks like this: “When I get a new thing in A, do this other thing in B.” The first part is the Trigger and the second part is the Action.
In our first example we are going to make something simple, without using Klaviyo nor API connections. Our zap would have as trigger ‘Any new row created in a Google sheets document’ > and as action that would be ‘Create a new contact in Klaviyo with the data coming from Google Sheets’
It would look like something like:
Either you can select one of the Google Sheets samples you might have in your own account, or you can create a new sheet similar to the one I create, making sure that you include an email column with some sample email addresses
Once you have synced the Google Sheets account, click in the the Edit options step in your trigger, select the sheet that you have just created and make sure to select the page / tab where is located the sheet.
Follow the instructions set by Zapier to run an initial test. Zapier needs this first test to verify that the connection is correctly set. If all goes as expected, you would see a ‘Test successful’ message that would indicate you are receiving correct data in your zap from Google Sheets.
The second part of your Zap is our trigger – In our case, we are going to send that information coming from Google Sheets to a Webhook.
A webhook (also called a web callback or HTTP push API) is a way for an app to provide other applications with real-time information. A webhook delivers data to other applications as it happens, meaning you get data immediately. Unlike typical APIs where you would need to poll for data very frequently in order to get it real-time. This makes webhooks much more efficient for both provider and consumer. The only drawback to webhooks is the difficulty of initially setting them up.
The idea of sending that data to a Webhook is that the webhook would be linked to the Klaviyo API: it will be our way of adding data in Klaviyo without the need of logging in our account.
More data about webhooks: https://zapier.com/blog/how-use-zapier-webhooks/
If we check Klaviyo documentation, in their API they have an endpoint to add new contacts, specifically is this one https://www.klaviyo.com/docs/api/lists
In an API, we will find different types of actions/orders we can send:
- PUT calls, whenever we need to edit something, we would use this one
- GET calls, whenever we have to pull any record already present in our account, we would use this one
- POST calls, whenever we have to add a new record in our database, we would use this one
Depending on the endpoint that we might work with, we might have to work with one of those orders, and if you check the Zapier webhook step, you can see those actions are the exact options we have:
For our sample, we would need to create a new record in our Klaviyo account, so we would need to work with a POST request.
Once we have that, let’s go back to the Klaviyo docs, and find a POST request that would allows to take contacts in our mailing list, if we type ‘Adding someone to a list’ it would take us directly to the paragraph in the docs where we can see that action
With that information in the docs, we just need to map it against the input fields that Zapier provides us through its interface.
Setting up our zap action and mapping Klaviyo API
First thing we would need to include in Zapier would be the URL or endpoint where we are going to send the orders.
If you check the endpoint URL, we would need a list ID that is not automatically included. We can grab it from our account, once we enter in one of our lists.
Besides that URL, we will append the API key which will allow us to verify that we are the owners of the account. You can find such API key here https://www.klaviyo.com/account#api-keys-tab
The complete URL should have a structure similar to:
In Payload type, we are going to mimic that the data is coming from a form, so we would select ‘form’.
The rest of data that is required for the API call will be included as ‘data’ in this way:
In our example we are only working with an email column in our Google Sheets, but if we would like to add additional attributes to pass them as ‘properties’ in the API call, we could just map those columns and add them also as additional ‘data’ fields.
Rest of options we would not cover them in this video, so we can leave them like that.
Testing the integration
Once we have completed all these steps, our webhook integration would be ready to send data to Klaviyo via its API without any additional code.