Add new subscriber in a Klaviyo list API
In this article, I will explain you that, how we can insert a new record in klaviyo list using V2, for this I'm going to use CURL request. This API is used for creating profiles and managing list memberships and subscriptions. We will use below API to create a new subscriber in a list:
https://a.klaviyo.com/api/v2/list/LIST_ID/members?api_key=API KEY
My form has only 1 field email because I will created a simple html form for newsletter. You can include more fields in your form based on your requirements.
To add subscriber in a list you will need API_KEY and LIST_ID. I'm using the following code to add subscriber in klaviyo list.
<?php
$apiKey = 'API KEY HERE';
$data = array (
'api_key' => $apiKey,
'profiles' => array ('0' => array ( 'email' => 'EMAIL ADDRESS HERE' )),
);
$list_id = 'LIST ID HERE';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://a.klaviyo.com/api/v2/list/".$list_id."/members?api_key=".$apiKey,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
?>
In this article, I will explain you that, how we can insert a new record in klaviyo list using V2, for this I'm going to use CURL request. This API is used for creating profiles and managing list memberships and subscriptions. We will use below API to create a new subscriber in a list:
https://a.klaviyo.com/api/v2/list/LIST_ID/members?api_key=API KEY
My form has only 1 field email because I will created a simple html form for newsletter. You can include more fields in your form based on your requirements.
To add subscriber in a list you will need API_KEY and LIST_ID. I'm using the following code to add subscriber in klaviyo list.
<?php
$apiKey = 'API KEY HERE';
$data = array (
'api_key' => $apiKey,
'profiles' => array ('0' => array ( 'email' => 'EMAIL ADDRESS HERE' )),
);
$list_id = 'LIST ID HERE';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://a.klaviyo.com/api/v2/list/".$list_id."/members?api_key=".$apiKey,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
?>
How to get API Key & List ID in Klaviyo
Get Api Key
1. Go to account page after login from top right corner under your user name
2. After that click on API Keys under Settings
3. Copy and use API key in your code
Get List ID
1. Go to lists & segments and after that click on list setting of any list which you want to select
2. And after that, you will see a unique klaviyo list id
Recommanded Articles
- Get Facebook long live access token in AWS Lambda function
- How to make image background transparent using PHP
- Paypal credit card payment on website in PHP
- Capture page screenshot by URL PHP script
- How to get all UK addresses by postal code
- API versioning in Laravel App
- Get all the lists from Mailchimp account using CURL
- Create a LEAD in ZOHO CRM using Node JS
- Create a LEAD in ZOHO CRM using API
- Add new subscriber in a Klaviyo list API
Latest Comments
Thorsten Haug
18 Apr 2021Admin
27 Apr 2021shah
22 Sep 2021