mailerlite / mailerlite-php
MailerLite PHP SDK
Requires
- php: ^7.4|^8.0
- ext-json: *
- php-http/client-common: ^2.2
- php-http/discovery: ^1.9
- php-http/httplug: ^2.1
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.18
- guzzlehttp/psr7: ^2.6.1
- http-interop/http-factory-guzzle: ^1.0
- mockery/mockery: ^0.9.4
- nyholm/psr7: ^1.8
- php-http/guzzle7-adapter: ^0.1
- php-http/message: ^1.0
- php-http/mock-client: ^1.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^7.5.15 || ^8.4 || ^9.0
Suggests
- guzzlehttp/guzzle: ^7.8 || ^8.0
- nyholm/psr7: ^1.8
- php-http/curl-client: ^2.0
- symfony/http-client: ^7.0
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v1.2.0
- v1.1.0
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-feature/cmac-1012-add-the-simple-editor-email-endpoints-to-the-php-sdk
- dev-feature/keep-empty-objects-in-editor-content
- dev-feature/engl-663-catch-up-the-ml-sdks-with-the-public-api-subscribers-groups
- dev-feature/pla-655-php-fatal-error-sendrequest
- dev-feature/issue-11195/create-shared-lefthook-repository-and-roll-out-hooks
- dev-feat/ecommerce-core
- dev-support-php-84
- dev-feature/mld-42879/fix-wrong-url-in-campaign-report
- dev-feature/sre-7625/github-deprecations
- dev-feature/issue-13/params-on-group-subscribers-call
- dev-issue-9983
- dev-feature/webhooks
- dev-issues-8700-8699
- dev-boilerplate
This package is auto-updated.
Last update: 2026-11-12 11:40:06 UTC
README
Table of Contents
- Installation
- Usage
- Optional PSR transport (no BC break)
- E-commerce
- Testing
- License
Installation
Requirements
- PHP 7.4
- An API Key from MailerLite
- PSR-7 and PSR-18 based HTTP adapter
Setup
composer require mailerlite/mailerlite-php
If you get an error saying “Could not find resource using any discovery strategy.” it means that all the discovery strategies have failed. Most likely, your project is missing the message factories and/or a PRS-7 implementation. To resolve this you may run
$ composer require php-http/curl-client:^2.0 guzzlehttp/psr7 php-http/message
If you get a fatal error saying Declaration of Http\Client\Curl\Client::sendRequest(...) must be compatible with Psr\Http\Client\ClientInterface::sendRequest(...),
an old php-http/curl-client 1.x is being loaded. Version 1.x does not implement PSR-18, so upgrade it to ^2.0
and make sure only one Composer autoloader (vendor/autoload.php) is loaded in your project.
Usage
Subscriber
More information on request parameters: https://developers.mailerlite.com/docs/subscribers.html
Create
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ 'email' => 'subscriber@example.com', ]; $response = $mailerLite->subscribers->create($data);
Read
Single record
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $subscriberId = '123'; $response = $mailerLite->subscribers->find($subscriberId);
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->subscribers->get();
Update
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $subscriberId = '123', $data = [ 'fields' => [ 'name' => 'Example', ], ]; $response = $mailerLite->subscribers->update($subscriberId, $data);
Delete
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $subscriberId = '123'; $response = $mailerLite->subscribers->delete($subscriberId);
Forget
Removes the subscriber and permanently deletes their personal data within 30 days (GDPR). The subscriber can be identified by ID or email. More information: https://developers.mailerlite.com/docs/subscribers.html#forget-a-subscriber
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $subscriberId = '123'; $response = $mailerLite->subscribers->forget($subscriberId);
Activity log
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $subscriberId = '123'; $data = [ 'filter' => [ 'log_name' => 'campaign_send', ], 'limit' => 10, 'page' => 1, ]; $response = $mailerLite->subscribers->getActivityLog($subscriberId, $data);
Import status
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $importId = '123'; $response = $mailerLite->subscribers->findImport($importId);
Campaign
More information on request parameters: https://developers.mailerlite.com/docs/campaigns.html
Create
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ 'type' => 'regular', 'name' => 'My new campaign', 'language_id' => 10, 'emails' => [ [ 'subject' => 'My new email', 'from_name' => 'me', 'from' => 'me@example.com', 'content' => 'Hello World!', ] ], 'filter' => [], ]; $response = $mailerLite->campaigns->create($data);
To create an email for the simple editor, set editor. To start the email from a template, also set template_id:
use MailerLite\Endpoints\Campaign; use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ 'type' => 'regular', 'name' => 'My new campaign', 'emails' => [ [ 'subject' => 'My new email', 'from_name' => 'me', 'from' => 'me@example.com', 'editor' => Campaign::EDITOR_SIMPLE, 'template_id' => '123', ] ], ]; $response = $mailerLite->campaigns->create($data);
template_id is the ID of a simple editor template. Use a template from the shared gallery, or a template
that you saved from your own email with createTemplate. Send template_id only
when editor is simple. Send the same template_id on every email in the request. Without template_id,
the email starts from the default blank template. The API copies the template into the new email and does not
change the template.
Read
Single record
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $campaignId = '123'; $response = $mailerLite->campaigns->find($campaignId);
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ 'filter' => ['status' => 'sent'], ]; $response = $mailerLite->campaigns->get($data);
Update
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $campaignId = '123'; $data = [ 'name' => 'Changed campaign name', 'emails' => [ [ 'subject' => 'Changed email subject', 'from_name' => 'Changed from name', 'from' => 'changed@example.com', ] ], ]; $response = $mailerLite->campaigns->update($campaignId, $data);
Delete
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $campaignId = '123'; $response = $mailerLite->campaigns->delete($campaignId);
Schedule
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $campaignId = '123'; $data = [ 'delivery' => 'instant', ]; $response = $mailerLite->campaigns->schedule($campaignId, $data);
Cancel
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $campaignId = '123'; $response = $mailerLite->campaigns->cancel($campaignId);
Subscriber activity of sent campaign
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $campaignId = '123'; $data = [ 'type' => 'opened', ]; $response = $mailerLite->campaigns->getSubscriberActivity($campaignId, $data);
Email API
Etags, retries and errors
Every write must send the etag from your last read or write of the email. Reads return it in
$response['body']['etag'], and each write returns the next one. For createBlock, updateBlock,
moveBlock, updateSettings and createTemplate, put etag in $data. deleteBlock and
restoreVersion take it as an argument.
If the email changed after you read it, the write throws a MailerLiteHttpException with status 409:
use MailerLite\Exceptions\MailerLiteHttpException; use MailerLite\Exceptions\MailerLiteValidationException; try { $response = $mailerLite->emails->deleteBlock($emailId, $blockId, $etag); $etag = $response['body']['etag']; } catch (MailerLiteHttpException $e) { if ($e->getErrorCode() === MailerLiteHttpException::VERSION_CONFLICT) { // Your copy is out of date. $e->getEtag() is the current etag, // but read the email again before you decide to retry. } } catch (MailerLiteValidationException $e) { $errors = $e->getErrors(); // keyed by field, empty when the 422 has only a message }
To retry a write safely after a network error, pass an idempotency key as the last argument. Use
the same key for the retry. If the API returns the stored response of the first attempt,
$response['is_idempotent_replay'] is true.
$response = $mailerLite->emails->createBlock($emailId, $data, 'create-block-7f3a');
Email, block and version IDs must contain only the digits 0-9. An empty ID throws
MailerLiteEmptyIdException, and any other ID that is not valid throws
MailerLiteInvalidIdException. Both are thrown before the request is sent.
Read
Single record
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $response = $mailerLite->emails->find($emailId);
Rendered HTML
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $response = $mailerLite->emails->getHtml($emailId); $html = $response['body']['data']['html'];
Read a block
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $blockId = '456'; $response = $mailerLite->emails->findBlock($emailId, $blockId);
Versions
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $response = $mailerLite->emails->getVersions($emailId);
Save the current content as a new version
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $response = $mailerLite->emails->createVersion($emailId); // 201 when a version is saved, 200 when nothing changed since the last one
Restore a version
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $versionId = '789'; $etag = '42'; // from your last read or write of this email $response = $mailerLite->emails->restoreVersion($emailId, $versionId, $etag);
Create a block
use MailerLite\Endpoints\Email; use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $data = [ 'etag' => '42', 'type' => Email::BLOCK_TYPE_DIVIDER, 'editor_content' => new \stdClass(), 'placement' => ['position' => Email::POSITION_AFTER, 'block_id' => '57'], ]; $response = $mailerLite->emails->createBlock($emailId, $data);
In createBlock, updateBlock and validateBlock, the SDK sends an empty editor_content, and each empty
attrs and mobile in it, as {}. Thus you can send back an editor_content that you read, with no changes.
In other places, the SDK sends a PHP empty array as []. To send {} there, use new \stdClass().
placement.position is start, end, before or after (the Email::POSITION_* constants).
before and after need a block_id.
Update a block
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $blockId = '456'; $data = [ // fields to change, see the API docs ]; $response = $mailerLite->emails->updateBlock($emailId, $blockId, $data);
Move a block
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $blockId = '456'; $data = [ 'etag' => '42', 'placement' => ['position' => 'after', 'block_id' => '57'], ]; $response = $mailerLite->emails->moveBlock($emailId, $blockId, $data);
Delete a block
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $blockId = '456'; $etag = '42'; // from your last read or write of this email $response = $mailerLite->emails->deleteBlock($emailId, $blockId, $etag); $etag = $response['body']['etag']; // the email's new etag
Validate a block
Checks a block without saving it, so no email ID is needed.
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ // block fields, see the API docs ]; $response = $mailerLite->emails->validateBlock($data);
Update settings
use MailerLite\Endpoints\Email; use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $data = [ 'etag' => '42', 'brand' => ['mode' => Email::BRAND_MODE_CUSTOM, 'background_color' => '#f4f4f4'], ]; $response = $mailerLite->emails->updateSettings($emailId, $data);
Send only the keys you want to change. A value you send is stored on this email, even if it is the same as the inherited value. To go back to the inherited value:
- for a brand colour, send
''; - for a footer text, send an empty editor document, such as
['editor_content' => ['content' => []]].
An empty string is not accepted for other colours, sizes, button.border_radius or brand.style.
Those return 422.
Validate settings
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $data = [ // settings fields, see the API docs ]; $response = $mailerLite->emails->validateSettings($emailId, $data);
Save as template
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $emailId = '123'; $data = [ // template fields, see the API docs ]; $response = $mailerLite->emails->createTemplate($emailId, $data);
To start a new campaign email from the saved template, send $response['body']['data']['id'] as template_id
when you create a campaign.
Brand styles API
Read
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->brandStyles->get();
Files API
Read
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->files->get();
Group API
More information on request parameters: https://developers.mailerlite.com/docs/groups.html
Create
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ "name" => "New group", ]; $response = $mailerLite->groups->create($data);
Read
Single record
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $groupId = '123'; $response = $mailerLite->groups->find($groupId);
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->groups->get();
Update
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $groupId = '123'; $data = [ "name" => "Updated name", ]; $response = $mailerLite->groups->update($groupId, $data);
Delete
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $groupId = '123'; $response = $mailerLite->groups->delete($groupId);
Get subscribers who belong to a group
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $groupId = '123'; $response = $mailerLite->groups->getSubscribers($groupId);
Assign subscriber to a group
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $groupId = '123'; $subscriberId = '456'; $response = $mailerLite->groups->assignSubscriber($groupId, $subscriberId);
unassign subscriber from a group
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $groupId = '123'; $subscriberId = '456'; $response = $mailerLite->groups->unAssignSubscriber($groupId, $subscriberId);
Import subscribers to a group
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $groupId = '123'; $data = [ 'subscribers' => [ ['email' => 'dummy@example.com'], ], 'resubscribe' => false, 'trigger_automations' => true, ]; $response = $mailerLite->groups->importSubscribers($groupId, $data);
Segment API
More information on request parameters: https://developers.mailerlite.com/docs/segments.html
Read
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->segments->get();
Update
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $segmentId = '123'; $data = [ "name" => "Updated name", ]; $response = $mailerLite->segments->update($segmentId, $data);
Delete
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $segmentId = '123'; $response = $mailerLite->segments->delete($segmentId);
Get subscribers who belong to a segment
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $segmentId = '123'; $data = [ 'filter' => [ 'status' => 'active', ], 'limit' => 25, 'cursor' => 'next_page_cursor', ]; $response = $mailerLite->segments->getSubscribers($segmentId, $data);
Field API
More information on request parameters: https://developers.mailerlite.com/docs/fields.html
Create
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ "name" => "New field", "type" => "text", ]; $response = $mailerLite->fields->create($data);
Read
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->fields->get();
Update
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $fieldId = '123'; $data = [ "name" => "Updated name", ]; $response = $mailerLite->fields->update($fieldId, $data);
Delete
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $fieldId = '123'; $response = $mailerLite->fields->delete($fieldId);
Form API
More information on request parameters: https://developers.mailerlite.com/docs/forms.html
Read
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->forms->get('popup', []);
Single
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $formId = '123'; $response = $mailerLite->forms->find($formId);
Update
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $formId = '123'; $data = [ "name" => "Updated name", ]; $response = $mailerLite->forms->update($formId, $data);
Delete
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $formId = '123'; $response = $mailerLite->forms->delete($formId);
Signed up subscribers
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $formId = '123'; $response = $mailerLite->forms->getSignups($formId);
Automation API
More information on request parameters: https://developers.mailerlite.com/docs/automations.html
Read
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->automations->get([]);
Single
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $response = $mailerLite->automations->find($automationId);
Activity
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $data = [ 'filter' => [ 'status' => 'active', ], ]; $response = $mailerLite->automations->activity($automationId, $data);
Manage
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $response = $mailerLite->automations->create(['name' => 'Welcome']); $response = $mailerLite->automations->update($automationId, ['name' => 'Welcome series']); $response = $mailerLite->automations->delete($automationId); $response = $mailerLite->automations->copy($automationId); $response = $mailerLite->automations->enable($automationId); $response = $mailerLite->automations->disable($automationId); $response = $mailerLite->automations->test($automationId, ['email' => 'dummy@example.com']); $response = $mailerLite->automations->addSubscribers($automationId, ['emails' => ['dummy@example.com']]); $response = $mailerLite->automations->readd($automationId, [ 'readd_subscribers_to' => 'last_completed_step', 'filter' => ['status' => 'completed', 'search' => 'example.com'], ]);
Activity actions
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $filter = ['filter' => ['status' => 'active']]; $response = $mailerLite->automations->addActivityToGroup($automationId, ['destination_groups' => ['456']] + $filter); $response = $mailerLite->automations->cancelActivity($automationId, $filter); $response = $mailerLite->automations->skipActivityDelay($automationId, $filter);
Triggers
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $triggerId = '456'; $response = $mailerLite->automations->getTriggers($automationId); $response = $mailerLite->automations->findTrigger($automationId, $triggerId); $response = $mailerLite->automations->createTrigger($automationId, [ 'type' => 'subscriber_joins_group', 'data' => ['group_ids' => ['789']], ]); $response = $mailerLite->automations->updateTrigger($automationId, $triggerId, ['data' => ['group_ids' => ['789']]]); $response = $mailerLite->automations->deleteTrigger($automationId, $triggerId);
Steps
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $stepId = '456'; $response = $mailerLite->automations->getSteps($automationId); $response = $mailerLite->automations->findStep($automationId, $stepId); $response = $mailerLite->automations->createStep($automationId, ['type' => 'delay', 'parent_id' => '789']); $response = $mailerLite->automations->updateStep($automationId, $stepId, ['data' => ['unit' => 'days', 'value' => 3]]); $response = $mailerLite->automations->deleteStep($automationId, $stepId, ['branch_to_delete' => 'yes']); $response = $mailerLite->automations->copyStep($automationId, $stepId, ['parent_id' => '789']); $response = $mailerLite->automations->reorderSteps($automationId, ['dragged_step_id' => $stepId, 'new_parent_step_id' => '789']); $response = $mailerLite->automations->selectAbTestWinner($automationId, $stepId, ['ab_test_winner' => 'a_path']);
Emails
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $emailId = '456'; $response = $mailerLite->automations->getEmailContent($automationId, $emailId); $response = $mailerLite->automations->updateEmailContent($automationId, $emailId, ['html' => '<p>Hello</p>']); $response = $mailerLite->automations->getEmailReportStats($automationId, $emailId, ['start_date' => '2026-10-01', 'end_date' => '2026-10-31']); $response = $mailerLite->automations->getEmailUnsubscribeReasons($automationId, $emailId);
Templates
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->automations->getTemplates(['filter' => ['category' => 3]]); $response = $mailerLite->automations->selectTemplate('123');
Reports
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $automationId = '123'; $stepId = '456'; $triggerId = '789'; $response = $mailerLite->automations->getStepRunCounts($automationId); $response = $mailerLite->automations->getStepRunCount($automationId, $stepId); $response = $mailerLite->automations->getTriggerRunCounts($automationId); $response = $mailerLite->automations->getTriggerRunCount($automationId, $triggerId); $response = $mailerLite->automations->getAbStepsStats($automationId); $response = $mailerLite->automations->getAbStepStats($automationId, $stepId); $response = $mailerLite->automations->getStepSubscribers($automationId, $stepId, ['status' => 'completed']); $response = $mailerLite->automations->getTriggerSubscribers($automationId, $triggerId, ['status' => 'completed']); $response = $mailerLite->automations->getEmailStats($automationId, ['start_date' => '2026-10-01', 'end_date' => '2026-10-31']);
Webhook API
More information on request parameters: https://developers.mailerlite.com/docs/webhooks.html
Create
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ "name" => "Name", "events" => ["subscriber.created"], "url": "https://www.cartwright.info/eligendi-soluta-corporis-in-quod-ullam", ]; $response = $mailerLite->webhooks->create($data);
Read
All records
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->webhooks->get([]);
Single
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $webhookId = '123'; $response = $mailerLite->webhooks->find($webhookId);
Update
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $webhookId = '123'; $data = [ "name" => "Updated name", ]; $response = $mailerLite->webhooks->update($webhookId, $data);
Delete
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $webhookId = '123'; $response = $mailerLite->webhooks->delete($webhookId);
Campaign language API
More information about request parameters on https://developers.mailerlite.com/docs/campaign-languages.html
Read
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->campaignLanguages->get();
Timezone API
More information about request parameters on https://developers.mailerlite.com/docs/timezones.html
Read
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $response = $mailerLite->timezones->get();
Batch API
More information about request parameters on https://developers.mailerlite.com/docs/batching.html
E-commerce
E-commerce endpoints follow:
/api/ecommerce/shops/{shopId}/...
shopId is provided per call.
Shops
$res = $mailerLite->ecommerceShops->get(); $res = $mailerLite->ecommerceShops->find('YOUR_SHOP_ID'); $res = $mailerLite->ecommerceShops->create(['name' => 'My shop', 'url' => 'https://shop.example.com', 'currency' => 'EUR']); $res = $mailerLite->ecommerceShops->update('YOUR_SHOP_ID', ['name' => 'New name']); $res = $mailerLite->ecommerceShops->delete('YOUR_SHOP_ID');
Products
$res = $mailerLite->ecommerceProducts->get('YOUR_SHOP_ID', [ 'filter' => ['enabled' => 'true', 'category' => 'CATEGORY_ID'], 'sort' => '-created_at', ]); $res = $mailerLite->ecommerceProducts->delete('YOUR_SHOP_ID', 'PRODUCT_ID'); $res = $mailerLite->ecommerceProducts->changeStatus('YOUR_SHOP_ID', 'PRODUCT_ID', false); $res = $mailerLite->ecommerceProducts->assignCategories('YOUR_SHOP_ID', 'PRODUCT_ID', ['CATEGORY_ID'], true); $res = $mailerLite->ecommerceProducts->create('YOUR_SHOP_ID', [ 'title' => 'Red T-shirt', 'price' => 19.99, 'currency' => 'USD', ]); $res = $mailerLite->ecommerceProducts->find('YOUR_SHOP_ID', 'PRODUCT_ID'); $res = $mailerLite->ecommerceProducts->update('YOUR_SHOP_ID', 'PRODUCT_ID', [ 'title' => 'New title', ]);
Product variants
$res = $mailerLite->ecommerceProductVariants->get('YOUR_SHOP_ID', 'PRODUCT_ID'); $res = $mailerLite->ecommerceProductVariants->sync('YOUR_SHOP_ID', 'PRODUCT_ID', [ ['name' => 'Large', 'attributes' => ['size' => 'L'], 'resource_id' => 'VARIANT-L'], ]); $res = $mailerLite->ecommerceProductVariants->update('YOUR_SHOP_ID', 'PRODUCT_ID', 'VARIANT_ID', [ 'name' => 'Extra large', 'attributes' => ['size' => 'XL'], ]); $res = $mailerLite->ecommerceProductVariants->delete('YOUR_SHOP_ID', 'PRODUCT_ID', 'VARIANT_ID');
Categories
$res = $mailerLite->ecommerceCategories->get('YOUR_SHOP_ID'); $res = $mailerLite->ecommerceCategories->find('YOUR_SHOP_ID', 'CATEGORY_ID'); $res = $mailerLite->ecommerceCategories->create('YOUR_SHOP_ID', ['name' => 'Hats']); $res = $mailerLite->ecommerceCategories->update('YOUR_SHOP_ID', 'CATEGORY_ID', ['name' => 'Caps']); $res = $mailerLite->ecommerceCategories->delete('YOUR_SHOP_ID', 'CATEGORY_ID'); $res = $mailerLite->ecommerceCategories->products('YOUR_SHOP_ID', 'CATEGORY_ID'); $res = $mailerLite->ecommerceCategories->assignProduct('YOUR_SHOP_ID', 'CATEGORY_ID', 'PRODUCT_ID'); $res = $mailerLite->ecommerceCategories->unassignProduct('YOUR_SHOP_ID', 'CATEGORY_ID', 'PRODUCT_ID');
Orders
$res = $mailerLite->ecommerceOrders->get('YOUR_SHOP_ID', [ 'filter' => ['attributed' => 'true', 'email_id' => 'EMAIL_ID'], ]); $res = $mailerLite->ecommerceOrders->delete('YOUR_SHOP_ID', 'ORDER_ID'); $res = $mailerLite->ecommerceOrders->create('YOUR_SHOP_ID', [ 'order_id' => 'ORD-1001', ]); $res = $mailerLite->ecommerceOrders->find('YOUR_SHOP_ID', 'ORD-1001'); $res = $mailerLite->ecommerceOrders->update('YOUR_SHOP_ID', 'ORD-1001', [ 'status' => 'paid', ]);
Customers
$res = $mailerLite->ecommerceCustomers->get('YOUR_SHOP_ID', ['limit' => 50]); $res = $mailerLite->ecommerceCustomers->create('YOUR_SHOP_ID', ['email' => 'user@example.com']); $res = $mailerLite->ecommerceCustomers->find('YOUR_SHOP_ID', 'CUSTOMER_ID'); $res = $mailerLite->ecommerceCustomers->update('YOUR_SHOP_ID', 'CUSTOMER_ID', ['name' => 'Jane']); $res = $mailerLite->ecommerceCustomers->delete('YOUR_SHOP_ID', 'CUSTOMER_ID');
Carts and cart items
$res = $mailerLite->ecommerceCarts->get('YOUR_SHOP_ID'); $res = $mailerLite->ecommerceCarts->update('YOUR_SHOP_ID', 'CART_ID', ['checkout_url' => 'https://shop.example.com/cart']); $res = $mailerLite->ecommerceCartItems->get('YOUR_SHOP_ID', 'CART_ID'); $res = $mailerLite->ecommerceCartItems->find('YOUR_SHOP_ID', 'CART_ID', 'ITEM_ID'); $res = $mailerLite->ecommerceCartItems->update('YOUR_SHOP_ID', 'CART_ID', 'ITEM_ID', ['quantity' => 2]); $res = $mailerLite->ecommerceCartItems->delete('YOUR_SHOP_ID', 'CART_ID', 'ITEM_ID');
Imports
$res = $mailerLite->ecommerceImport->products('YOUR_SHOP_ID', [['name' => 'Red T-shirt', 'price' => 19.99]]); $res = $mailerLite->ecommerceImport->categories('YOUR_SHOP_ID', [['name' => 'Hats']]); $res = $mailerLite->ecommerceImport->customers('YOUR_SHOP_ID', [['email' => 'user@example.com']]);
Revenue reports
$res = $mailerLite->campaigns->getEcommerceStats('CAMPAIGN_ID', ['shop_id' => 'YOUR_SHOP_ID']); $res = $mailerLite->campaigns->getEcommerceOrders('CAMPAIGN_ID', ['shop_id' => 'YOUR_SHOP_ID']); $res = $mailerLite->subscribers->getEcommerceStats('SUBSCRIBER_ID', ['shop_id' => 'YOUR_SHOP_ID']); $res = $mailerLite->subscribers->getEcommerceOrders('SUBSCRIBER_ID', ['shop_id' => 'YOUR_SHOP_ID']); $res = $mailerLite->automations->getEcommerceStats('AUTOMATION_ID'); $res = $mailerLite->automations->getEmailEcommerceStats('AUTOMATION_ID', 'EMAIL_ID'); $res = $mailerLite->automations->getEcommerceOrders('AUTOMATION_ID', ['time_frame' => 'all_time']); $res = $mailerLite->ecommerceShops->stats('YOUR_SHOP_ID', ['start_date' => '2026-10-01', 'end_date' => '2026-10-31']);
Tracking settings
$res = $mailerLite->ecommerceSettings->get();
Optional PSR transport (no BC break)
use MailerLite\MailerLite; use MailerLite\Http\Adapters\Psr17FactoryAggregate; use Nyholm\Psr7\Factory\Psr17Factory; use GuzzleHttp\Client as GuzzleHttpClient; $ml = new MailerLite(['api_key' => 'YOUR_API_KEY']); $psr17 = new Psr17Factory(); $factories = new Psr17FactoryAggregate($psr17, $psr17); $httpClient = new GuzzleHttpClient(); $ml->enablePsrTransport($httpClient, $factories, 'YOUR_API_KEY', 'https://connect.mailerlite.com'); $ml->subscribers->create(['email' => 'subscriber@example.com']);
Send
use MailerLite\MailerLite; $mailerLite = new MailerLite(['api_key' => 'key']); $data = [ 'requests' => [ [ 'method' => 'post', 'path' => 'api/subscribers', 'body' => [ 'email' => 'new_subscriber@mail.com' ] ] ] ]; $response = $mailerLite->batches->send($data);
Testing
composer test
Support and Feedback
In case you find any bugs, submit an issue directly here in GitHub.
You are welcome to create SDK for any other programming language.
If you have any troubles using our API or SDK free to contact our support by email info@mailerlite.com