List of all webhooks (array) is obtained.
webhooks() : array
Array of webhooks. Each webhook is represented as an array that includes:
<?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"; } }
Create new webhook.
webhookCreate(string $title, array $options) : string
<?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"; }
Updates webhook options.
webhookUpdate(string $wid, string $name, string/array $value) : string
List of possible names:
<?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»; }
Deletes webhook.
webhookDelete(string $wid) : string
<?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»; }
Creates a copy of webhook.
webhookReplicate(string $wid) : string
<?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»; }