PHP Example

ⓘ This example is purely and solely for example purposes and is by no mean production ready. If you have written a library based on our API please  keep in touch.

Find below an example of using PHP (cURL) to subscribe an email address.

// Set variables
$api_token = "YOUR_API_TOKEN";
$uuid = "YOUR_LIST_UUID";
$hosting_url = "YOUR_HOSTING_URL";
$email = "support@maitreapp.co";
$base_url = "https://maitreapp.co/api/v2/lists/". $uuid ."/subscribers";

// Initialize CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('api_token' => $api_token, 'hosting_url' => $hosting_url, 'email' => $email)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Store the data:
$json = curl_exec($ch);
$curl_close($ch);

// Decode JSON Response
$result = json_decode($json, true);

// Access data and create your logic
if ($result['status'] == "ok") {
 // Email successful subscribed
} else {
  // Error
}

Still need help? Contact Us Contact Us