Skip to content

Subaccounts Calls

Introduction

Mandrill Subaccounts can be mapped on Mailjet sub API keys manageable with apikey. The Mailjet REST API lets you manage multiple API key. Each API key will have its own contacts, lists, newsletters and statistics dedicated database. The contacts and lists will not be shared between API keys (including the main API key)..

List

Info

Maps to /subaccounts/list.json

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->get(Resources::$Apikey);
$response->success() && var_dump($response->getData());
?>
{
  "Count": 1,
  "Data": [
    {
      "ACL": "",
      "APIKey": "",
      "CreatedAt": "",
      "ID": "",
      "IsActive": "false",
      "IsMaster": "false",
      "Name": "",
      "QuarantineValue": "",
      "Runlevel": "Normal",
      "SecretKey": "",
      "TrackHost": "",
      "UserID": ""
    }
  ],
  "Total": 1
}

Issue a GET request on the apikey resource

Add

Info

Maps to /subaccounts/add.json

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'Name' => "MynewKEY"
];
$response = $mj->post(Resources::$Apikey, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>
{
  "Count": 1,
  "Data": [
    {
      "ACL": "",
      "APIKey": "",
      "CreatedAt": "",
      "ID": "",
      "IsActive": "false",
      "IsMaster": "false",
      "Name": "",
      "QuarantineValue": "",
      "Runlevel": "Normal",
      "SecretKey": "",
      "TrackHost": "",
      "UserID": ""
    }
  ],
  "Total": 1
}

To create a new API key , you just need to do a POST request on the apikey.

The response will contain a new APIKey and SecretKey. Please allow a few seconds before running any additional API request on this new APIkey as the full setup process of this new sub-account will take longer than the API call.