How to Enable Webhooks for Email Service

A webhook is a mechanism for receiving notifications about certain events. You can set up notifications about email deliverability and subscriber activity.

How to Create a Webhook

To create and send webhooks automatically, go to the "Account Settings" section in the "API" tab and click "Create a webhook."

Select the event triggered by the webhook in the email service regarding sending an email:

  • email marked as spam;
  • email opened;
  • link in the email clicked;
  • new subscriber;
  • subscriber unsubscribed;
  • subscriber deleted from the list;
  • delivered;
  • campaign status changed.

Next, specify the URL, to which notifications will be sent.

For each event you should create separate webhooks.

Send Data Format

When a webhook is triggered, SendPulse sends a POST request to the specified URL with the JSON data type.

Data is sent every minute or when the limit of 100 events is reached.

Data is sent in the following format:

[
  {
    "timestamp": "1496827422",
    "event": "event_name",
    "task_id": "3668141",
    "email": "john.doe@sendpulse.com" 
  }
]

Request Formats, Depending on the Event

Marked as spam:

[
  {
    "timestamp": "1496827422",
    "event": "spam",
    "task_id": "3668141",
    "email": "john.doe@sendpulse.com" 
  }
]

Email opened:

[
  {
    "task_id": "3668141",
    "timestamp": "1496827941",
    "open_device": "Desktop",
    "open_platform": "Windows",
    "browser_ver": "11.0",
    "browser_name": "Firefox",
    "email": "john.doe@sendpulse.com",
    "event": "open" 
   }
]

Link clicked:

[
   {
    "link_url": http://google.com,
    "task_id": "3668141",
    "timestamp": "1496828000",
    "open_device": "Desktop",
    "open_platform": "Linux",
    "browser_ver": "58.0.3029.110",
    "browser_name": "Chrome",
    "link_id": "71741389",
    "email": "john.doe@sendpulse.com",
    "event": "redirect" 
  }
]

Client opted-out:

[
  {
    "task_id": "3668141",
    "timestamp": "1496827872",
    "from_all": "1",
    "email": "john.doe@sendpulse.com",
    "reason": null,
    "book_id": "490686",
    "event": "unsubscribe",
    "categories": "" 
  }
]

New subscriber:

[
  {
    "timestamp":"1496827625",
    "variables": [],
    "email": "john.doe@sendpulse.com",
    "source": "address book",
    "book_id": "490686",
    "event": "new_emails" 
  },
  {
    "timestamp": "1496827625",
    "variables": [],
    "email": "doe.john@sendpulse.com",
    "source": "subscription form",
    "book_id": "490686",
    "event": "new_emails" 
  }
]

Removing from an email list:

[
  {
    "timestamp": "1496827422",
    "event": "delete",
    "book_id": "490686",
    "email": "john.doe@sendpulse.com" 
  }
]

Delivered:

[
  {
    "timestamp": 1632316421
    "event": "delivered"
    "task_id": 9333331
    "email": "test@e.cn.ua"
  }
]

Changing email campaign status:

[
  {
    "status": "approve",
    "status_explain": "Approved and will be sent",
    "task_id": "3668138,
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
  {
    "status": "approve_part",
    "status_explain": "Approved and will be sent by parts",
    "task_id": "3668139",
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
  {
    "status": "only_active",
    "status_explain": "Will be sent only to active adresses",
    "task_id": "3668140",
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
  {
    "status": "confirm_addresses",
    "status_explain": "Rejected: confirm the mailing list",
    "task_id": "3668142",
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
  {
    "status": "need_edit",
    "status_explain": "Rejected: edit the email body",
    "task_id": "3668143",
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
  {
    "status": "rejected",
    "status_explain": "Campaign rejected",
    "task_id": "3668144",
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
  {
    "status": "on_moderation",
    "status_explain": "Campaign is on moderation",
    "task_id": "3668145",
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
  {
    "status": "sending",
    "status_explain": "Campaign is in the sending queue",
    "task_id": "3668146",
    "timestamp": "1496827843",
    "book_id": "490686",
    "event": "task_status_update" 
  },
]

Example of the script that processes a webhook in PHP:

<?php
$json_string = file_get_contents('php://input');
$data_array = json_decode($json_string, true);
?>
Rate this article about "How to Enable Webhooks for Email Service"

User Rating: 4 / 5 (5)

    Other useful articles

    Popular in Our Blog

    Try SendPulse today for free