Skip to Content
MailerLite

Getting started

Conventions, authentication, errors, and rate limits for integrating with the MailerLite REST API.

MailerLite API

MailerLite API is RESTful, fully-featured, and easy to integrate with.

You can use your favorite HTTP/REST library that is available for your programming language to make HTTP calls.

You must send JSON payloads in your requests and expect to get JSON responses. Don't forget to add these headers to each and every request.

Content-Type: application/json
Accept: application/json

Use the following base URL for all API endpoints:

https://connect.mailerlite.com/api

SDK

MailerLite supports this list of official libraries for your favorite programming languages. This is the easiest way to integrate MailerLite with your application.

Authentication

API keys

API keys are a quick way to implement machine-to-machine authentication without any direct inputs from a human beyond initial setup.

For example, you might want to run a scheduled job to sync your CRM data to your MailerLite account.

You can generate an API key by opening MailerLite, navigating to Integrations and choosing MailerLite API. Then click "Generate new token". Give it a name to help you identify where it's used in the future, e.g. "CRM sync job - production".

Once the key is generated, please copy and store it immediately. We will not be able to show this API key again in the future, as we don't store API keys in plain text for security reasons. If you lose it, you will have to replace it with a new API key.

Once you have your API key, provide it in an Authorization header together with your request payload, where XXX is your token:

Authorization: Bearer XXX

If you fail to provide a valid token, you'll get this response on all requests.

Response Code: 401 Unauthorized
{
  "message": "Unauthenticated."
}

API keys lifecycle & user deletion

API keys are permanently bound to the user who created them. If the user is removed from the account or the user account is deleted, the API key will stop working and will no longer authenticate any requests.

Versioning

All requests use the latest version, unless you override the API version. To lock down the API version, provide the current date at the time of implementation through X-Version header.

X-Version: 2038-01-19

Validation errors

You might encounter validation errors when sending requests to API endpoints. They will come in the following format

Response Code: 422 Unprocessable Entity
Content-Type: application/json
{
  "message": "The given data was invalid.",
  "errors": {
    "email": ["The email must be a valid email address."]
  }
}

Rate limits

MailerLite API has a global rate limit of 120 requests per minute. If you exceed that rate limit you will receive a 429 error response with a “Too Many Attempts” message. If you think you will be hitting these limits, please use batch endpoint and/or implement backoff strategy that would even out the requests over time.

Response Code: 429 Too Many Attempts
Content-Type: application/json
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 0
Retry-After: 119
{
  "message": "Too Many Attempts."
}

Import rate limits

Import creation endpoints have a separate rate limit of 5 requests per minute. This applies to:

  • POST /api/subscribers/import
  • POST /api/groups/{group_id}/import-subscribers
  • Batch requests where all items are POST api/subscribers (subscriber upserts)

If you exceed this limit you will receive a 429 response. Use the Retry-After header value to know when you can retry.

Response Code: 429 Too Many Requests
Content-Type: application/json
Retry-After: 60
{
  "message": "You're being rate limited on import creation."
}

Idempotency

A write can time out or lose its connection after the change has already been made, leaving you no way to tell whether retrying would repeat it. Send an Idempotency-Key header — any unique value you choose, such as a UUID, up to 255 printable ASCII characters — and the retry is safe:

POST /emails/123/blocks
Idempotency-Key: your-unique-request-key

Repeat the request with the same key, method, path and body, and you get the original response back with the change made only once. A replayed response carries this header:

Idempotent-Replayed: true

Only successful responses are stored, so a request that failed can be retried with the same key. Stored keys expire 24 hours after the request that created them.

CodeWhen
400The key is empty, longer than 255 characters, or contains anything other than printable ASCII.
409A request with the same key is still running. Wait for it to finish, then retry. If the first request was cut off on our side, the key can stay locked for up to 10 minutes.
422The key has already been used with a different method, path or body. If you are retrying, send the original body with it — a new key would apply the change a second time.

Keys belong to the account, the user and the API token that sent them, so the same value used elsewhere is a different request. Endpoints that support idempotency list the Idempotency-Key header among their parameters; anywhere else it is ignored.

HTTP status codes

MailerLite returns standard HTTP response codes.

CodeNameExplanation
200OKThe request was accepted.
201CreatedResource was created.
202AcceptedThe request was accepted and further actions are taken in the background.
204No ContentThe request was accepted and there is nothing to return.
400Bad RequestThere was an error when processing your request. Please adjust your request based on the endpoint requirements and try again.
401UnauthorizedThe provided API token is invalid.
403ForbiddenThe action is denied for that account or a particular API token.
404Not FoundThe requested resource does not exist on the system.
405Method Not AllowedHTTP method is not supported by the requested endpoint.
408Request TimeoutThere is an error on our system. Please contact support
409ConflictThe request conflicts with the current state of the resource, or a request with the same idempotency key is still running. When code is version_conflict, the resource changed since you read it: fetch it again, then retry with its new etag.
422Unprocessable EntityThere was a validation error found when processing the request. Please adjust it based on the endpoint requirements and try again.
429Too Many RequestsThere were too many requests made to the API.
500Internal Server ErrorThere was an error on our system. Please contact support
502Bad GatewayThere was an error on our system. Please contact support
503Service UnavailableThere was an error on our system. Please contact support
504Gateway TimeoutThere was an error on our system. Please contact support

More info on HTTP response codes can be found on Mozilla Developer Network.

Terms of service

Before implementing any integration, please make sure you're familiar with MailerLite's terms of service.

As stated in the ToC, if you collect subscribers on your own (as opposed to using MailerLite forms), you must accept responsibility for abuse prevention:

<..>you must ensure that the subscribers are collected in accordance with the industry best practice and requirements set out in these Terms and Anti-Spam Policy. You are responsible for preventing any type of abuse when collecting new subscribers through your own generated API key.

Branding

You can use our brand assets within these guidelines.

On this page