mailerlite / mailerlite-php
MailerLite PHP SDK
Installs: 126 050
Dependents: 2
Suggesters: 0
Security: 0
Stars: 24
Watchers: 9
Forks: 7
Open Issues: 6
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-implementation: ^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
- 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
This package is not auto-updated.
Last update: 2024-11-20 12:06:08 UTC
README
Table of Contents
- Installation
- Usage
- 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 guzzlehttp/psr7 php-http/message
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);
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);
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);
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);
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'; $response = $mailerLite->segments->getSubscribers($segmentId);
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);
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
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