2017 © Pedro Peláez
 

library mailjet-api-php

Mailjet PHP API client

image

knplabs/mailjet-api-php

Mailjet PHP API client

  • Friday, September 15, 2017
  • by Knplabs
  • Repository
  • 23 Watchers
  • 11 Stars
  • 21,233 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 11 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

DEPRECATED

Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to hello@knplabs.com., (*1)

mailjet-api-php

mailjet-api-php is a PHP library for quick and simple consuming of Mailjet API., (*2)

It supports both RESTful and Event Tracking APIs., (*3)

Build Status SensioLabsInsight Scrutinizer Quality Score Latest Stable Version Composer Downloads HHVM Status, (*4)

Usage

RESTful API - OOP wrappers

This library provides OOP wrappers to most (all) API endpoints, that are located under Mailjet/Api/Request namespace. These include:, (*5)

  • Api class for sending Api related calls
  • User class for sending User related calls

Simple example:, (*6)

<?php

// This file is generated by Composer
require_once 'vendor/autoload.php';

use Mailjet/Api/Client;
use Mailjet/Api/Request/User;

$user = new User(new Client('api_key', 'secret_key'));
$userInfo = $user->getInfo();

var_dump($userInfo);

//(
//    [username] => KnpLabs
//    [email] => hello@Knplabs.com
//    [locale] => en_US
//    [currency] => USD
//    [timezone] => America/New_York
//    [firstname] => KnpLabs
//    ....
//)

RESTful API - Client

In addition to using wrappers, you can obviously also use the client directly to make API requests on lower level. To ease consumption of RESTful API there's a RequestApi helper class, which lists all available queries. Check Mailjet documentation for a detailed list of queries., (*7)

Simple example:, (*8)

<?php

// This file is generated by Composer
require_once 'vendor/autoload.php';

use Mailjet/Api/Client;
use Mailjet/Api/RequestApi;

$client = new Client('api_key', 'secret_key');
$userInfo = $client->get(RequestApi::USER_INFOS);

var_dump($userInfo);

//(
//    [username] => KnpLabs
//    [email] => hello@Knplabs.com
//    [locale] => en_US
//    [currency] => USD
//    [timezone] => America/New_York
//    [firstname] => KnpLabs
//    [lastname] =>
//    [company_name] => KnpLabs
//    [contact_phone] =>
//    [address_street] =>
//    [address_postal_code] =>
//    [address_city] =>
//    [address_country] =>
//    [tracking_openers] => 1
//    [tracking_clicks] => 1
//)

Sending a POST request:, (*9)

<?php

// ... initialize client

$result = $client->post(RequestApi::USER_DOMAIN_ADD, array(
    'domain' => 'example.com'
));

var_dump($result);

//(
//    [status]    => 200
//    [file_name] => empty_file
//    [id]        => 123
//)

Event Tracking API

mailjet-api-php provides a clean OOP interface to interact with Event Tracking API., (*10)

<?php

use Mailjet/Event/EventFactory;

$factory = new EventFactory();

// fetch incoming data into $data array, example
//(
//    [event]          => open
//    [email]          => hello@Knplabs.com
//    [mj_contact_id]  => 123
//    [mj_campaign_id] => 123
//    [customcampaign] => Hello from KnpLabs
//    [ip]             => 127.0.0.1
//    [geo]            => US
//    [agent]          => Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0
//)

$event = $factory->createEvent($data);

echo get_class($event); // \Mailjet\Event\Events\OpenEvent
echo $event->getType(); // open
echo $event->getIp();   // 127.0.0.1

Note: this library is not responsible for validation of incoming data. However, assuming the data is coming from Mailjet servers, it will work correctly., (*11)

Symfony2 integration

You don't need a special bundle to use the RESTful API with Symfony2, you can initialize the service with a simple config:, (*12)

services:
    knp_mailjet.api:
        class: Mailjet\Api\Client
        arguments: [<your_mailjet_api_key>, <your_mailjet_secret_key>]

And that's it, Mailjet RESTful API is now available via:, (*13)

<?php

$this->container->get('knp_mailjet.api');

And to initialize higher level OOP wrappers:, (*14)

services:
    knp_mailjet.api.request.user:
        class: Mailjet\Api\Request\User
        arguments: [@knp_mailjet.api]

    # ... other wrappers definitions
<?php

$this->container->get('knp_mailjet.api.request.user')->getInfo();

However, if you need both RESTful and Event API support, then there's KnpMailjetBundle., (*15)

Installation

The first step to use mailjet-api-php is to download Composer:, (*16)

$ curl -s http://getcomposer.org/installer | php

Now add mailjet-api-php with Composer:, (*17)

$ php composer.phar require knplabs/mailjet-api-php:1.*

And that's it! Composer will automatically handle the rest., (*18)

Alternatively, you can manually add the dependency to composer.json file..., (*19)

{
    "require": {
        "knplabs/mailjet-api-php": "1.*"
    }
}

... and then install our dependencies using:, (*20)

$ php composer.phar install

Requirements

  • PHP >= 5.3.8
  • HTTP component of Guzzle library
  • (optional) Symfony2 Debug Component

Contributing

See CONTRIBUTING.md file., (*21)

Running the Tests

To run unit tests, you'll need a set of dev dependencies you can install using Composer:, (*22)

php composer.phar install --dev

Once installed, just launch the following command:, (*23)

phpunit

Credits

OOP wrappers idea was originally implemented by David Guyon in his version of the client., (*24)

KnpLabs Team, (*25)

License

mailjet-api-php is released under the MIT License. See the bundled LICENSE file for details., (*26)

The Versions

15/09 2017

dev-master

9999999-dev https://github.com/KnpLabs/mailjet-api-php

Mailjet PHP API client

  Sources   Download

MIT

The Requires

 

The Development Requires

api mailjet

31/01 2015

1.1.2

1.1.2.0 https://github.com/KnpLabs/mailjet-api-php

Mailjet PHP API client

  Sources   Download

MIT

The Requires

 

The Development Requires

api mailjet

27/09 2013

v1.1.1

1.1.1.0 https://github.com/KnpLabs/mailjet-api-php

Mailjet PHP API client

  Sources   Download

MIT

The Requires

 

The Development Requires

api mailjet

01/09 2013

v1.0.0

1.0.0.0 https://github.com/KnpLabs/mailjet-api-php

Mailjet PHP API client

  Sources   Download

MIT

The Requires

 

The Development Requires

api mailjet