Use Postman to make POST requests
Before you proceed, make sure you have set up your development environment and forked Klaviyo's Postman collection. If you have not completed these steps, return to the previous lessons before continuing.
For these exercises, you are working for Beantown Coffee. Beantown just launched a series of educational coffee seminars, and your goal is to track how many customers sign up for each seminar and how much revenue you are generating from the seminars.
You want to automate the process of adding profiles to a list to maintain a group of all profiles who signed up for a seminar. Then, you want to set up a custom "Booked seminar" event that fires when a customer books the educational coffee seminar.
Based on Beantown's setup, this will require 3 steps:
- Create a list to contain people who sign up for seminars
- Create a flow triggered by this list.
- Configure a webhook in this flow that creates an event.
Ready to get started? Open up Postman and your Klaviyo test account, then click the arrow on each dropdown to work through the exercises below. You will also need your private API key handy in order to set up a webhook.
Create a list
In Postman, use the Create List endpoint to create a new list titled Seminar attendees.
The payload for this API request should be:
{
"data": {
"type": "list",
"attributes": {
"name": "Seminar attendees"
}
}
} After making your API request, you can check the Lists & segments tab to make sure a list titled Seminar attendees was successfully created:
Get the list ID
The list you just created prior to starting this exercise will contain all customers who signed up for a coffee seminar.
Your goal is to set up a way to quickly check how many customers have signed up for a seminar.
To do so, first use the Get Lists endpoint to return all lists in your account.
Use these results to determine the list ID of the Seminar attendees list. This is the 6-digit id that is associated with the list name:
Create a flow
Send a POST request to the Create Flow endpoint.
Use this as the body of the API request:
{
"data": {
"type": "flow",
"attributes": {
"name": "Create Booked seminar events",
"definition": {
"triggers": [
{
"type": "list",
"id": "RcFaQ5"
}
],
"profile_filter": {
"condition_groups": [
{
"conditions": []
}
]
},
"actions": [
{
"type": "send-webhook",
"temporary_id": "test"
}
],
"entry_action_id": "test"
}
}
}
} The only change you will need to make is replacing RcFaQ5 with the ID of the list you found in the previous step.
If the request went through successfully, you should see a 201 Created status in Postman:
In addition, if you navigate to Klaviyo, you should see your new flow titled Create Booked seminar events in the Flows tab. This flow should look like:
Configure your webhook destination URL
Beantown's ultimate goal is to send a custom "Booked seminar" event into their Klaviyo account after customers book.
The webhook automatically fires when the flow is triggered, aka when customers book. Now, your job is to set up the webhook to make a POST request to the Create Event endpoint.
Let's start by setting up the destination URL. In Klaviyo, click on the webhook in your new Create Booked seminar event flow so that Webhook details pops up on the right. Then, set the Destination URL to https://a.klaviyo.com/api/events.
This is the URL that is listed in the Create Event endpoint documentation.
Configure webhook headers
Next, add 2 headers to the webhook: Authorization and revision. The value of the revision header is listed at the bottom of the endpoint's documentation:
At the time of this writing, the most recent revision is 2025-01-15, so this is what I'll include in the revision header.
The value of the Authorization header should be Klaviyo-API-Key followed by your private API key. If you did not save your private API key, you can create a new one.
Configure webhook payload
The last step is to set up the body or payload of the webhook. Copy the payload below into your webhook:
{
"data": {
"type": "event",
"attributes": {
"properties": {},
"metric": {
"data": {
"type": "metric",
"attributes": {
"name": "Booked seminar"
}
}
},
"profile": {
"data": {
"type": "profile",
"attributes": {
"email": "{{ person.email }}"
}
}
}
}
}
} This will create an event named Booked seminar. You may notice that the email in the above body is "{{ person.email }}". This will pull the email address of the profile that triggered the flow.
The entire webhook should look like:
Test your webhook
To test your webhook, add your profile to the Seminar attendees list.
Then, you can test your webhook by clicking Preview then Send Test Request.
After sending a test request, you should see a Booked seminar event on the profile you added to the list.
Congratulations! You just used Klaviyo's APIs to automatically create a custom event every time a customer is added to a list.
Webhooks allow you to make an API call to any endpoint within a flow, so that when a flow is triggered, an API call is made.