Add new subscriber in a Klaviyo List API

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); ?>

 

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

Klaviyo account

2. After that click on API Keys under Settings

Klaviyo under extras

3. Copy and use API key in your code

Klaviyo API key

Get List ID

1. Go to lists & segments and after that click on list setting of any list which you want to select

Klaviyo List Select

2. And after that, you will see a unique klaviyo list id

Klaviyo List ID

Hi, I'm Saurav, the developer behind usingphp. Donate to help me keep usingphp free and maintained.

Please let me know what your thoughts or comments are on this article. If you have any suggestion or found any mistake in this article then please let us know.

Latest Comments

Thorsten Haug
Thorsten Haug
17 Apr 2021

Hello, currently i´m working on a project with klaviyo and was struggling on my code. Your Post rescued me - thank you for this! Best regards, Thorsten

Admin
Admin
26 Apr 2021

Glad to hear

Add your comment