What type of API does MailerLite provide?
MailerLite has a RESTful API. It is built on HTTP and follows REST principles. The API is fully-featured and easy to integrate, allowing you to use your favorite HTTP/REST library in your programming language to make API calls. It uses JSON for request payloads and responses.
Authentication is done using API keys, which need to be included in the Authorization header of requests. There is a global rate limit of 120 requests per minute, and exceeding this limit will result in a 429 error response.
MailerLite provides official SDKs for several programming languages including PHP, Go, Node.js, Python, and Ruby. It is recommended to always use HTTPS for requests, follow MailerLite's terms of service, and consider using batch endpoints and implementing backoff strategies if you expect to hit rate limits.
Comprehensive API documentation is available, including an API reference, webhooks information, and code examples.
Does the MailerLite API have webhooks?
Yes, the official MailerLite API does have webhooks. Here are the key points about MailerLite's webhook functionality:
Available Events
MailerLite offers webhooks for the following events:
- subscriber.created: Fires when a new subscriber is added
- subscriber.updated: Fires when a subscriber's fields are updated or they confirm subscription
- subscriber.unsubscribed: Fires when a subscriber unsubscribes
- subscriber.added_to_group: Fires when a subscriber is added to a group
- subscriber.removed_from_group: Fires when a subscriber is removed from a group
- subscriber.bounced: Fires when an email address bounces
- subscriber.automation_triggered: Fires when a subscriber starts an automation
- subscriber.automation_completed: Fires when a subscriber finishes an automation
- subscriber.spam_reported: Fires when a subscriber marks a campaign as spam
- campaign.sent: Fires when a campaign is sent
- campaign.open: Fires when a subscriber opens a campaign (requires batching)
- campaign.click: Fires when a subscriber clicks a link in a campaign (requires batching)
- subscriber.deleted: Fires when a subscriber is deleted or forgotten (requires batching)
Key Points
- Webhooks allow you to receive real-time notifications about events in your MailerLite account
- Events are sent as HTTP POST requests to your specified URL
- Some events (like opens and clicks) require batching to be enabled
- Webhooks include security measures like signatures to verify authenticity
- Failed webhook deliveries are retried up to 3 times
- You can manage webhooks via the API or MailerLite dashboard
Best Practices
- Respond to webhook requests within 3 seconds to avoid timeouts
- Use batching for high-volume events to reduce the number of requests
- Verify webhook signatures to ensure requests are from MailerLite
- Offload heavy processing to background jobs to keep webhook handlers fast
In summary, MailerLite's webhook system provides comprehensive event coverage for subscriber and campaign activities, allowing you to build real-time integrations with your MailerLite account.
Rate Limits and other limitations
Here are the key points about the API Rate Limits for the MailerLite API:
Global Rate Limit
-
MailerLite API has a global rate limit of 120 requests per minute.
-
If you exceed this limit, you will receive a 429 error response with a "Too Many Attempts" message.
Each API request returns the following rate limit headers:
- X-RateLimit-Limit: The maximum number of API requests that can be made per minute (120)
- X-RateLimit-Remaining: The remaining number of API requests that can be made in the current minute
- X-RateLimit-Reset: A date and time value indicating when the remaining limit resets
- X-RateLimit-Retry-After: Indicates the seconds remaining before you can make a new request
Exceeding the Rate Limit
If you exceed the rate limit:
- You'll receive a 429 Too Many Attempts response
- The response will include the headers above, with X-RateLimit-Remaining set to 0
- The Retry-After header will indicate how many seconds to wait before retrying
Best Practices
-
If you think you'll hit the rate limits, use the batch endpoint and/or implement a backoff strategy to spread out requests over time.
-
Be aware that some endpoints may have individual rate limits in addition to the global limit.
-
Monitor the rate limit headers to track your usage and avoid hitting the limits.
Key Considerations
-
The rate limit is per minute, so you can make up to 120 requests in a 60 second period.
-
Even if your daily volume is low, you can still hit rate limits if you make too many requests in a short time.
-
Using the official MailerLite SDKs can help manage rate limiting automatically.
By understanding and working within these rate limits, you can ensure smooth integration with the MailerLite API. If you consistently need higher limits, you may need to contact MailerLite support to discuss options.
Latest API Version
The most recent version of the MailerLite API is the version released on March 22nd, 2022 alongside the new version of MailerLite [1]. This API follows date-based versioning and is considered the latest and improved API for MailerLite [1].
Key points to consider:
- This API is intended for use with the new MailerLite accounts created after March 22nd, 2022 [1].
- MailerLite Classic account users should continue using API V1 or V2, but should consider migrating to the new MailerLite eventually [1].
- The new API is RESTful and fully-featured, making it easy to integrate with various programming languages [3].
To use the latest MailerLite API:
- Ensure you have a new MailerLite account (created after March 22nd, 2022) [1].
- Generate an API key from the Integrations section of your MailerLite account [3].
- Use the base URL:
https://connect.mailerlite.com/api
[3].
- Include the following headers in your requests [3]:
Content-Type: application/json
Accept: application/json
Authorization: Bearer YOUR_API_KEY
Best practices:
- Use official SDK libraries for easier integration with your preferred programming language [3].
- Implement proper authentication using API keys [3].
- Be aware of and respect the rate limit of 120 requests per minute [3].
- Consider using the batch endpoint for bulk operations to optimize API usage [3].
- Familiarize yourself with MailerLite's terms of service before implementing any integration [3].
By using the latest version of the MailerLite API, you'll have access to the most up-to-date features and improvements for your email marketing needs.
How to get a MailerLite developer account and API Keys?
To get a developer account for MailerLite and create an API integration, follow these steps:
1. Create a MailerLite account
If you don't already have one, sign up for a MailerLite account at mailerlite.com.
2. Generate an API key
- Log in to your MailerLite account
- Navigate to the Integrations page from the left sidebar menu
- Click on "MailerLite API"
- Click "Generate new token"
- Name your token (e.g. "My API Integration")
- Choose IP restrictions if desired
- Copy the generated API key or download it as a TXT file
3. Use the API key in your integration
- Include the API key in the Authorization header of your API requests:
Authorization: Bearer YOUR_API_KEY
- Use the API base URL: https://connect.mailerlite.com/api
What can you do with the MailerLite API?
Based on the information provided in the search results, here is a list of data models you can interact with using the MailerLite API, along with what is possible for each:
Subscribers
- Create new subscribers
- Update existing subscribers
- Retrieve subscriber information
- Add subscribers to groups
- Assign custom field values to subscribers [1]
Groups
- Create new groups
- Retrieve group information
- List all groups
- Add subscribers to groups
- Filter groups by name [4]
Segments
- Create and manage segments (specific details not provided in the search results)
Fields
- Create and manage custom fields for subscribers [1]
Automations
- Interact with automation workflows (specific details not provided in the search results)
Campaigns
- Create and manage email campaigns (specific details not provided in the search results)
Forms
- Interact with signup forms (specific details not provided in the search results)
Webhooks
- Set up and manage webhooks for real-time event notifications [5]
E-commerce
- Interact with e-commerce data, including:
- Carts
- Cart items
- Categories
- Products
- Customers
- Orders
- Import e-commerce data [1]
Key points to consider:
- The API is RESTful and uses JSON for request payloads and responses [1].
- Authentication is required using an API key in the Authorization header [1].
- There is a rate limit of 120 requests per minute [1].
- The API supports various programming languages through official SDKs [1].
- For more complex operations, you can use the batching endpoint to optimize requests [1].
Best practices:
- Use the appropriate SDK for your programming language when available [1].
- Implement a backoff strategy to handle rate limiting [1].
- Store the MailerLite subscriber ID in your system for easier future API calls [4].
- Use webhooks for real-time updates to reduce the need for frequent API polling [5].
- Familiarize yourself with the API conventions, limits, and terms of service before integrating [4].