Skip to content

Webhooks Calls

Introduction

Instead of polling to get data, you can use our Event API for your system to be notified in near real-time when any event you've subscribed to happen. The Mailjet resource involved here is eventcallbackurl, which lets you define a webhook per event type we support (including sent,open,click,bounce,blocked and spam).

List

Info

Maps to /webhooks/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::$Eventcallbackurl);
$response->success() && var_dump($response->getData());
?>
{
  "Count": 1,
  "Data": [
    {
      "APIKeyID": "",
      "EventType": "",
      "ID": "",
      "IsBackup": "false",
      "Status": "",
      "Url": "",
      "Version": ""
    }
  ],
  "Total": 1
}

Issue a GET request to eventcallbackurl to list all the resources for your current API key.

Add

Info

Maps to /webhooks/add.json

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'EventType' => "open",
    'Url' => "https://mydomain.com/event_handler"
];
$response = $mj->post(Resources::$Eventcallbackurl, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>
{
  "Count": 1,
  "Data": [
    {
      "APIKey": "",
      "EventType": "",
      "ID": "",
      "IsBackup": "false",
      "Status": "",
      "Url": "",
      "Version": ""
    }
  ],
  "Total": 1
}

Issue a POST request to eventcallbackurl to create a new event subscriber.

Info

Info

Maps to /webhooks/add.json

Issue a GET request to eventcallbackurl with the ID or the event type to list it. See #List above.

Update

Info

Maps to /webhooks/update.json

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'APIKeyID' => "",
    'IsBackup' => "false",
    'Status' => "",
    'Url' => "",
    'Version' => ""
];
$response = $mj->put(Resources::$Eventcallbackurl, ['id' => $id, 'body' => $body]);
$response->success() && var_dump($response->getData());
?>
{
  "Count": 1,
  "Data": [
    {
      "APIKeyID": "",
      "EventType": "",
      "ID": "",
      "IsBackup": "false",
      "Status": "",
      "Url": "",
      "Version": ""
    }
  ],
  "Total": 1
}

Issue a PUT request to eventcallbackurl with the ID to update

Delete

Info

Maps to /webhooks/delete.json

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->delete(Resources::$Eventcallbackurl, ['id' => $id]);
$response->success() && var_dump($response->getData());
?>
{
  "Count": 1,
  "Data": [
    {
      "APIKeyID": "",
      "EventType": "",
      "ID": "",
      "IsBackup": "false",
      "Status": "",
      "Url": "",
      "Version": ""
    }
  ],
  "Total": 1
}

Issue a PUT request to eventcallbackurl with the ID to delete

Events content sample

All JSON event objects contain the following properties:

  • event : the event type
  • time : unix timestamp of event
  • email : email address of recipient triggering the event
  • mj_campaign_id : internal Mailjet campaign ID associated to the message
  • mj_contact_id : internal Mailjet contact ID
  • customcampaign : value of the X-Mailjet-Campaign header when provided
  • MessageID : The unique message ID
  • CustomID: the custom ID, when provided at send time
  • Payload: the event payload, when provided at send time

###Sent event

Sample sent event

{
  "event": "sent",
  "time": 1433333949,
  "MessageID": 19421777835146490,
  "email": "api@mailjet.com",
  "mj_campaign_id": 7257,
  "mj_contact_id": 4,
  "customcampaign": "",
  "mj_message_id": "19421777835146490",
  "smtp_reply": "sent (250 2.0.0 OK 1433333948 fa5si855896wjc.199 - gsmtp)",
  "CustomID": "helloworld",
  "Payload": ""
}

Dispatched when the destination SMTP server (gmail, hotmail, yahoo, etc) has accepted the message. Depending on your volume, it could dispatch a lot of events to your system. Please make sure you have checked the Group Events Checkbox in the Event API user interface or that the /eventcallbackurl Version property is set to 2.

Sent event additional properties:

  • mj_message_id : The unique message ID as a string (deprecated, see MessageID)
  • smtp_reply: The raw SMTP response message

###Open event

Sample open event

{
  "event": "open",
  "time": 1433103519,
  "MessageID": 19421777396190490,
  "email": "api@mailjet.com",
  "mj_campaign_id": 7173,
  "mj_contact_id": 320,
  "customcampaign": "",
  "CustomID": "helloworld",
  "Payload": "",
  "ip": "127.0.0.1",
  "geo": "US",
  "agent": "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0"
}

Open event additional properties:

  • ip : IP address (can be IPv4 or IPv6) that triggered the event
  • geo : country code of IP address (see list)
  • agent : User-Agent

###Click event

Sample click event

{
  "event": "click",
  "time": 1433334653,
  "MessageID": 19421777836302490,
  "email": "api@mailjet.com",
  "mj_campaign_id": 7272,
  "mj_contact_id": 4,
  "customcampaign": "",
  "CustomID": "helloworld",
  "Payload": "",
  "url": "https://mailjet.com",
  "ip": "127.0.0.1",
  "geo": "FR",
  "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36"
}

Click event additional properties:

  • url : the link that was clicked

###Bounce event

Sample bounce event

{
  "event": "bounce",
  "time": 1430812195,
  "MessageID": 13792286917004336,
  "email": "bounce@mailjet.com",
  "mj_campaign_id": 0,
  "mj_contact_id": 0,
  "customcampaign": "",
  "CustomID": "helloworld",
  "Payload": "",
  "blocked": true,
  "hard_bounce": true,
  "error_related_to": "recipient",
  "error": "user unknown"
}

Bounce event additional properties:

  • blocked : true if this bounce leads to the recipient being blocked
  • hard_bounce : true if error was permanent
  • error_related_to : see error table
  • error : see error table

###Blocked event

Sample blocked event

{
  "event": "blocked",
  "time": 1430812195,
  "MessageID": 13792286917004336,
  "email": "bounce@mailjet.com",
  "mj_campaign_id": 0,
  "mj_contact_id": 0,
  "customcampaign": "",
  "CustomID": "helloworld",
  "Payload": "",
  "error_related_to": "recipient",
  "error": "user unknown"
}

Blocked event additional properties:

  • error_related_to : see error table
  • error : see error table

###Spam event

Sample spam event

{
  "event": "spam",
  "time": 1430812195,
  "MessageID": 13792286917004336,
  "email": "bounce@mailjet.com",
  "mj_campaign_id": 0,
  "mj_contact_id": 0,
  "customcampaign": "",
  "CustomID": "helloworld",
  "Payload": "",
  "source": "JMRPP"
}

Spam event additional properties:

  • source : indicates which feedback loop program reported this complaint

###Unsub event

Sample unsub event

{
  "event": "unsub",
  "time": 1433334941,
  "MessageID": 20547674933128000,
  "email": "api@mailjet.com",
  "mj_campaign_id": 7276,
  "mj_contact_id": 126,
  "customcampaign": "",
  "CustomID": "helloworld",
  "Payload": "",
  "mj_list_id": 1,
  "ip": "127.0.0.1",
  "geo": "FR",
  "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36"
}

Unsub event additional properties:

  • mj_list_id : internal Mailjet List id for REST API access to lists management
  • ip : IP address (can be IPv4 or IPv6) that triggered the event
  • geo : country code of IP address (see list)
  • agent : User-Agent