Example PHP API Code
Using our API is easy with PHP, just take a look at the sample code below which shows you how to form, post and catch a JSON response, using CURL with PHP.
Adding a User to a Group
// Set the Query POST parameters
$query_vals = array(
'api_key' => 'your_api_key',
'format' => 'json',
'client_id' => 'your_client_id',
'client_group_id' => 'your_group_id',
'email' => 'email@email.com',
'title' => 'Mr',
'first_name' => 'James',
'last_name' => 'Smith',
'date_of_birth' => '04/07/1986',
'address1' => 'Address Line 1',
'address2' => 'Address Line 2',
'city' => 'City',
'county' => 'County',
'country' => 'England'
);
// Generate the POST string
foreach($query_vals as $key => $value) {
$ret .= $key.'='.urlencode($value).'&';
}
// Chop of the trailing ampersand
$ret = rtrim($ret, '&');
// Send the request using curl
$ch = curl_init("http://api.18amail.co.uk/add.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ret);
$response = curl_exec($ch);
curl_close ($ch);
// dump out the response
var_dump(json_decode($response, true));
Deleting a User from a Group
// Set the Query POST parameters
$query_vals = array(
'api_key' => 'your_api_key',
'format' => 'json',
'client_id' => 'your_client_id',
'client_group_id' => 'your_group_id',
'email' => 'email@email.com'
);
// Generate the POST string
foreach($query_vals as $key => $value) {
$ret .= $key.'='.urlencode($value).'&';
}
// Chop of the trailing ampersand
$ret = rtrim($ret, '&');
// Send the request using curl
$ch = curl_init("http://api.18amail.co.uk/delete.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ret);
$response = curl_exec($ch);
curl_close ($ch);
// dump out the response
var_dump(json_decode($response, true));
Creating and Scheduling an Email
// Set the Query POST parameters
$query_vals = array(
'api_key' => 'your_api_key',
'format' => 'json',
'client_id' => 'your_client_id',
'client_group_id' => 'your_group_id',
'message' => 'message content',
'subject' => 'subject line',
);
// Generate the POST string
foreach($query_vals as $key => $value) {
$ret .= $key.'='.urlencode($value).'&';
}
// Chop of the trailing ampersand
$ret = rtrim($ret, '&');
// Send the request using curl
$ch = curl_init("http://api.18amail.co.uk/create.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ret);
$response = curl_exec($ch);
curl_close ($ch);
// dump out the response
var_dump(json_decode($response, true));