A robust, secure, and flexible API for managing newsletter subscriptions with advanced bot protection, rate limiting, and seamless user experience.
Everything you need to manage newsletter subscriptions effectively and securely
Complete reference for integrating with the Essential Nigeria Newsletter API
https://news-letter.essentialnews.ng/api
Subscribe a user to the newsletter. Handles new subscriptions and re-subscriptions automatically.
| Field | Type | Required | Description |
|---|---|---|---|
| string | Yes | The subscriber's email address | |
| platform | string | Yes | Source platform or website |
| honeypot | string | No | Bot detection field (leave empty) |
Content-Type: application/json
{
"message": "Successfully subscribed!"
}
Unsubscribe a user using their unique token.
| Parameter | Type | Description |
|---|---|---|
| token | string | Unique unsubscribe token |
{
"message": "You have been successfully unsubscribed."
}
Test the API endpoints directly from your browser
Subscribe to the newsletter by filling the form below:
To test the unsubscribe endpoint, you'll need a valid token from a subscription email.
Note: You need to subscribe first to get a valid unsubscribe token.
Ready-to-use examples for quick integration
use Illuminate\Support\Facades\Http;
$response = Http::post('https://news-letter.essentialnews.ng/api/subscribe', [
'email' => 'user@example.com',
'platform' => 'My Website',
'honeypot' => '' // Leave empty
]);
if ($response->successful()) {
$data = $response->json();
echo $data['message'];
} else {
$error = $response->json();
echo 'Error: ' . $error['message'];
// Handle specific error cases
if ($response->status() === 403) {
// IP blocked or bot detected
}
}
const subscribeUser = async (email, platform) => {
try {
const response = await fetch('https://news-letter.essentialnews.ng/api/subscribe', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: email,
platform: platform,
honeypot: ''
})
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || 'Subscription failed');
}
console.log('Success:', data.message);
return data;
} catch (error) {
console.error('Error:', error);
// Show error to user
alert(error.message);
throw error;
}
};
// Usage
subscribeUser('user@example.com', 'My Website')
.then(data => {
// Handle success
})
.catch(error => {
// Handle error
});
curl -X POST https://news-letter.essentialnews.ng/api/subscribe \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"platform": "My Website",
"honeypot": ""
}'
# Example response:
# {"message":"Successfully subscribed!"}
<form id="newsletter-form" class="max-w-md mx-auto">
<div class="mb-4">
<label for="email" class="block text-gray-700 mb-2">Email Address</label>
<input type="email" name="email" id="email" required
class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-nigeria-green focus:border-nigeria-green">
</div>
<input type="hidden" name="platform" value="Essential-Nigeria">
<!-- Honeypot field -->
<input type="text" name="honeypot" style="display:none">
<button type="submit" class="w-full bg-nigeria-green text-white py-2 px-4 rounded-lg hover:bg-green-700 transition">
Subscribe
</button>
<div id="form-message" class="mt-3 text-sm hidden"></div>
</form>
<script>
document.getElementById('newsletter-form').addEventListener('submit', async (e) => {
e.preventDefault();
const form = e.target;
const messageEl = document.getElementById('form-message');
messageEl.classList.add('hidden');
try {
const response = await fetch('https://news-letter.essentialnews.ng/api/subscribe', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
},
body: JSON.stringify({
email: form.email.value,
platform: form.platform.value,
honeypot: form.honeypot.value
})
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || 'Subscription failed');
}
messageEl.textContent = data.message;
messageEl.classList.remove('hidden', 'text-red-600');
messageEl.classList.add('text-green-600');
form.reset();
} catch (error) {
messageEl.textContent = error.message;
messageEl.classList.remove('hidden', 'text-green-600');
messageEl.classList.add('text-red-600');
}
});
</script>
Get started with the Essential Nigeria Newsletter API in minutes
git clone https://github.com/hardeex/newsletter
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate
MAIL_MAILER=smtp
MAIL_HOST=your-smtp-host
MAIL_PORT=587
MAIL_USERNAME=your-username
MAIL_PASSWORD=your-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="no-reply@essentialnews.ng"
MAIL_FROM_NAME="Essential Nigeria"
Supported mailers: SMTP, Mailgun, Postmark, Amazon SES, Sendmail
php artisan serve
For production, configure a proper web server like Nginx or Apache
Learn more and get help with the Essential Nigeria Newsletter API
Explore the complete API documentation with detailed examples and use cases.
Access the source code, report issues, or contribute to the project.