Webhook Management

webhooks()

List of all webhooks (array) is obtained.

webhooks() : array
Information obtained

Array of webhooks. Each webhook is represented as an array that includes:

  • id - webhook ID that is used in other API functions
  • web_id - webhook ID that is used in the administration page
  • title - name of webhook
  • create_time - GMT date of webhook creation given in YYYY-MM-DD HH:II:SS format
  • list_id - list ID that the webhook is based on
  • list_name - list name that the webhook is based on
  • last_event - GMT date of last triggered successful event given in YYYY-MM-DD HH:II:SS format
  • total_events - number of total successful event triggered
  • status - flag that indicates the status of the webhook (enabled / disabled)
  • url - URL where requests are delivered to
  • secret_key - secret key that is passed in every webhook request you receive. It gives you the opportunity to verify that requests originated from us.
  • events - array of events used to trigger the webhook. Possible values are: contact.subscribe, contact.unsubscribe, contact.update, email.change, email.bounce, email.open, email.click.
  • sources - array of sources used to trigger the webhook. Possible values are: subscriber, admin, api

Examples

mgapi_webhooks.php
<?php
/**
This Example shows how to webhoks using the MGAPI.php class and do some basic error checking.
**/
require_once 'inc/MGAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey

$api = new MGAPI($apikey);

$retval = $api->webhooks();

header("Content-Type: text/plain");
if ($api->errorCode){
	echo "Unable to load webhooks()!";
	echo "\tCode={$api->errorCode}\n";
	echo "\tMsg={$api->errorMessage}\n";
} else {
	echo sizeof($retval) . " Webhooks Returned:\n";
	foreach($retval as $c){
		echo "Webhook Id: {$c['id']} - {$c['title']}\n";
		echo "\tLast event: {$c['last_event']}\n";
		echo "\tTotal events: {$c['total_events']}\n";
	}
}

webhookCreate()

Create new webhook.

webhookCreate(string $title, array $options) : string
Input parametrs
  • title - list name
  • options - array of webhook parameters consisting of:
    • list_id - list ID that the webhook is based on
    • url - URL where requests are delivered to (optional)
    • secret_key - secret key that is passed in every webhook request you receive. It gives you the opportunity to verify that requests originated from us (optional)
    • events - array of events used to trigger the webhook (optional). Possible values are: contact.subscribe, contact.unsubscribe, contact.update, email.change, email.bounce, email.open, email.click
    • sources - array of sources used to trigger the webhook (optional). Possible values are: subscriber, admin, api
Information obtained
  • ID of the new webhook

Examples

mgapi_webhookCreate.php
<?php
/**
This Example shows how to webhookCreate using the MGAPI.php class and do some basic error checking.
**/
require_once 'inc/MGAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey

$api = new MGAPI($apikey);

$title = 'Test Webhook';

$options = array(
	'list_id' => $listId,
	'url' => 'http://www.example.com/webhook-listener/',
	'secret_key' =>	'secret',
	'events' => array(
		'contact.subscribe',
		'contact.unsubscribe',
		'contact.update',
		// 'email.change',
		// 'email.bounce',
		'email.open',
		'email.click',
	),
	'sources' => array(
		'subscriber',
		// 'admin',
		'api',
	),
);

$retval = $api->webhookCreate($title, $options);

header("Content-Type: text/plain");
if ($api->errorCode) {
	echo "Unable to load webhookCreate()!\n";
	echo "\tCode={$api->errorCode}\n";
	echo "\tMsg={$api->errorMessage}\n";
} else {
	echo "New Webhook ID: {$retval}\n";
}

webhookUpdate()

Updates webhook options.

webhookUpdate(string $wid, string $name, string/array $value) : string
Input parameters
  • wid - webhook ID
  • name - name of updated option
  • value - what option will be updated to

List of possible names:

  • title - list name
  • list_id - list ID that the webhook is based on
  • url - URL where requests are delivered to (optional)
  • secret_key - secret key that is passed in every webhook request you receive. It gives you the opportunity to verify that requests originated from us (optional)
  • events - array of events used to trigger the webhook (optional). Possible values are: contact.subscribe, contact.unsubscribe, contact.update, email.change, email.bounce, email.open, email.click
  • sources - array of sources used to trigger the webhook (optional). Possible values are: subscriber, admin, api
Information obtained
  • true if request for updating webhook has succeeded

Examples

mgapi_webhookUpdate.php
<?php
/**
This Example shows how to webhookUpdate using the MGAPI.php class and do some basic error checking.
**/
require_once 'inc/MGAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey

$api = new MGAPI($apikey);

$wid = $webhookId;
$name = 'title';
$value = 'New Title';

$retval = $api->webhookUpdate($wid, $name, $value);

header("Content-Type: text/plain«);
if ($api->errorCode){
	echo «Unable to load webhookUpdate()!\n»;
	echo «\tCode={$api->errorCode}\n»;
	echo «\tMsg={$api->errorMessage}\n»;
} else {
	echo «SUCCESS! \n»;
}

webhookDelete()

Deletes webhook.

webhookDelete(string $wid) : string
Input parameters
  • wid - webhook ID
Information obtained
  • true if request for deleting webhook has succeeded

Examples

mgapi_webhookDelete.php
<?php
/**
This Example shows how to webhookDelete using the MGAPI.php class and do some basic error checking.
**/
require_once 'inc/MGAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey

$api = new MGAPI($apikey);

$wid = $webhookId;

$retval = $api->webhookDelete($wid);

header("Content-Type: text/plain«);
if ($api->errorCode){
	echo «Unable to load webhookDelete()!\n»;
	echo «\tCode={$api->errorCode}\n»;
	echo «\tMsg={$api->errorMessage}\n»;
} else {
	echo «Webhook Deleted!\n»;
}

webhookReplicate()

Creates a copy of webhook.

webhookReplicate(string $wid) : string
Input parameters
  • wid - webhook ID
Information obtained
  • webhook copy ID

Examples

mgapi_webhookReplicate.php
<?php
/**
This Example shows how to webhookReplicate using the MGAPI.php class and do some basic error checking.
**/
require_once 'inc/MGAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey

$api = new MGAPI($apikey);

$wid = $webhookId;

$retval = $api->webhookReplicate($wid);

header("Content-Type: text/plain«);
if ($api->errorCode){
	echo «Unable to load webhookReplicate()!\n»;
	echo «\tCode={$api->errorCode}\n»;
	echo «\tMsg={$api->errorMessage}\n»;
} else {
	echo «New Webhook Id = {$retval}\n»;
}

© 2010-2018 Mailigen. All rights reserved.