API v1.0

Powerful Newsletter API Built for Nigerian Developers

A robust, secure, and flexible API for managing newsletter subscriptions with advanced bot protection, rate limiting, and seamless user experience.

2
API Endpoints
99.9%
Uptime
2/min
Rate Limit
MIT
License

Powerful Features

Everything you need to manage newsletter subscriptions effectively and securely

Email Management

Subscribe, unsubscribe, and resubscribe users with automatic welcome email handling and token-based unsubscription.

SMTP Mailgun

Advanced Security

Built-in bot detection with honeypot fields, IP blocklist protection, and comprehensive rate limiting.

Honeypot IP Blocklist

Rate Limiting

Intelligent throttling with 2 requests per minute per user to prevent abuse while maintaining smooth user experience.

2 req/min

Flexible Integration

Easy-to-use REST API with comprehensive Laravel integration and platform tracking capabilities.

REST JSON

Comprehensive Logging

Track subscription sources, manage user status, and monitor API usage with detailed analytics.

Analytics

Error Handling

Robust error handling with descriptive messages and appropriate HTTP status codes for better debugging.

400 403 500

API Documentation

Complete reference for integrating with the Essential Nigeria Newsletter API

Base URL

https://news-letter.essentialnews.ng/api
Production HTTPS
POST

/subscribe

Subscribe a user to the newsletter. Handles new subscriptions and re-subscriptions automatically.

Request Body

Field Type Required Description
email string Yes The subscriber's email address
platform string Yes Source platform or website
honeypot string No Bot detection field (leave empty)

Headers

Content-Type: application/json

Response Examples

Status: 201 Created
{
    "message": "Successfully subscribed!"
}
GET

/unsubscribe/{token}

Unsubscribe a user using their unique token.

Path Parameters

Parameter Type Description
token string Unique unsubscribe token

Response Examples

Status: 200 OK
{
    "message": "You have been successfully unsubscribed."
}

Try It Out

Test the API endpoints directly from your browser

POST /subscribe

Subscribe to the newsletter by filling the form below:

GET /unsubscribe/{token}

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.

Code Examples

Ready-to-use examples for quick integration

Laravel/PHP Example

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
    }
}

JavaScript Example

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 Example

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!"}

Laravel Blade Form

<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>

Quick Installation

Get started with the Essential Nigeria Newsletter API in minutes

1. Prerequisites

  • PHP >= 8.0
  • Laravel >= 8.x
  • Composer
  • MySQL or other database systems supported by Laravel
  • Mailer setup (e.g., SMTP, Mailgun, etc.)

2. Clone the Repository

git clone https://github.com/hardeex/newsletter

3. Install Dependencies

composer install

4. Configure Environment

cp .env.example .env
php artisan key:generate
php artisan migrate

5. Configure Mail Settings

.env file configuration
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

6. Run the Application

php artisan serve

For production, configure a proper web server like Nginx or Apache

Additional Resources

Learn more and get help with the Essential Nigeria Newsletter API

Full Documentation

Explore the complete API documentation with detailed examples and use cases.

GitHub Repository

Access the source code, report issues, or contribute to the project.

Support

Need help? Contact our support team for assistance with integration.