-
Notifications
You must be signed in to change notification settings - Fork 3
/
curl_subscribe.php
35 lines (28 loc) · 964 Bytes
/
curl_subscribe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$key = 'your_api_key_goes_here';
$listId = 123; //replace with your list ID
$fields = array(
'email'=>'[email protected]',
'first_name'=>'Nick', // optional
'last_name'=>'Sample' // optional
);
// if you want the request to fail for duplicate contacts, uncomment this:
// $fields['failOnDuplicate'] = true;
$url = 'https://campayn.com/api/v1/lists/' . $listId . '/contacts.json';
$curl = curl_init($url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
$json = json_encode($fields);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
'Authorization: TRUEREST apikey=' . $key
));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, count($fields));
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
$result = json_decode(curl_exec($curl));
curl_close($curl);
if ($result['success'] == true) {
// it worked
} else {
// it failed (maybe the contact is already on the list)
}