2017 © Pedro Peláez
 

library mailerlite-api-v2-php-sdk

MailerLite API v2 PHP SDK

image

mailerlite/mailerlite-api-v2-php-sdk

MailerLite API v2 PHP SDK

  • Tuesday, June 12, 2018
  • by eima
  • Repository
  • 14 Watchers
  • 28 Stars
  • 90,153 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 9 Forks
  • 3 Open issues
  • 15 Versions
  • 26 % Grown

The README.md

MailerLite Classic API v2 PHP SDK

This library is for MailerLite Classic. If you want to integrate with MailerLite please use https://github.com/mailerlite/mailerlite-php instead., (*1)

It is an official PHP SDK for the MailerLite Classic API., (*2)

You can find more examples and information about the MailerLite Classic API here: https://developers-classic.mailerlite.com/docs, (*3)

Getting started

In order to use this library you need to have at least PHP 7.1 version., (*4)

There are two ways to use MailerLite PHP SDK:, (*5)

Use Composer

If you are not familiar with Composer, learn about it here., (*6)

Then you will need to run this simple command using CLI:, (*7)

composer require mailerlite/mailerlite-api-v2-php-sdk

This library is built atop of PSR-7 and PSR-18. If you are receiving Http\Discovery\Exception\DiscoveryFailedException exception, you will need to run:, (*8)

composer require php-http/guzzle6-adapter
Manual (preferable for shared hostings)

This way is preferable only if you are using shared hosting and do not have a possibility to use Composer. You will need to download the source of the latest release from here, extract it and place its contents in the root folder of your project. The next step is the same as using Composer, you will need to require vendor/autoload.php file in your index.php and lets dive in!, (*9)

Usage examples

Groups API

In the given example you will see how to initiate selected API and a few actions which are available:, (*10)

  • Create group
  • Get groups
  • Update group
  • Get subscribers who belongs to selected group
$groupsApi = (new \MailerLiteApi\MailerLite('your-api-key'))->groups();

$newGroup = $groupsApi->create(['name' => 'New group']); // creates group and returns it

$allGroups = $groupsApi->get(); // returns array of groups

$groupId = 123;
$singleGroup = $groupsApi->find($groupId); // returns single item object

$subscribers = $groupsApi->getSubscribers($groupId); // get subscribers who belongs to selected group

$subscribers = $groupsApi->getSubscribers($groupId, 'unsubscribed'); // get unsubscribed subscribers who belongs to selected group

Use multiple APIs at once

Also `MailerLiteApi\MailerLite' object can be initiated before selecting API you want to use and it allows to achieve more., (*11)

$mailerliteClient = new \MailerLiteApi\MailerLite('your-api-key');

$groupsApi = $mailerliteClient->groups();
$groups = $groupsApi->get(); // returns array of groups

$fieldsApi = $mailerliteClient->fields();
$fields = $fieldsApi->get(); // returns array of fields

Use your preferred HTTP client

MailerLite SDK uses cURL as default HTTP client but it is easy to use your preferred client. It is achieved by using HTTPlug which is PSR-7 compliant HTTP client abstraction., (*12)

Here is an example how to use Guzzle instead of cURL:, (*13)

$guzzle = new \GuzzleHttp\Client();
$guzzleClient = new \Http\Adapter\Guzzle6\Client($guzzle);

$mailerliteClient = new \MailerLiteApi\MailerLite('your-api-key', $guzzleClient);

Support and Feedback

In case you find any bugs, submit an issue directly here in GitHub., (*14)

You are welcome to create SDK for any other programming language., (*15)

If you have any troubles using our API or SDK free to contact our support by email info@mailerlite.com, (*16)

Official documentation is at https://developers-classic.mailerlite.com/docs, (*17)

The Versions