function mailchimp_webhook_add in Mailchimp 8
Same name and namespace in other branches
- 7.5 mailchimp.module \mailchimp_webhook_add()
- 7.3 mailchimp.module \mailchimp_webhook_add()
- 7.4 mailchimp.module \mailchimp_webhook_add()
- 2.x mailchimp.module \mailchimp_webhook_add()
Adds a webhook to a Mailchimp list.
Parameters
string $list_id: The Mailchimp list ID to add a webhook for.
string $url: The URL of the webhook endpoint.
array $events: Associative array of events action to bool, indicating enabled status.
array $sources: Associative array of source name to bool, indicating source status.
Return value
string The ID of the new webhook.
See also
Mailchimp_Lists::addWebhook()
2 calls to mailchimp_webhook_add()
- MailchimpListsWebhookSettingsForm::submitForm in modules/
mailchimp_lists/ src/ Form/ MailchimpListsWebhookSettingsForm.php - Form submission handler.
- MailchimpListsWebhookTest::testAddWebhook in modules/
mailchimp_lists/ src/ Tests/ MailchimpListsWebhookTest.php - Tests adding a webhook to a list.
File
- ./
mailchimp.module, line 984 - Mailchimp module.
Code
function mailchimp_webhook_add($list_id, $url, array $events = [], array $sources = []) {
try {
/* @var \Mailchimp\MailchimpLists $mc_lists */
$mc_lists = mailchimp_get_api_object('MailchimpLists');
if (!$mc_lists) {
throw new Exception('Cannot add webhook without Mailchimp API. Check API key has been entered.');
}
$parameters = [
'events' => (object) $events,
'sources' => (object) $sources,
];
$result = $mc_lists
->addWebhook($list_id, $url, $parameters);
return $result->id;
} catch (\Exception $e) {
\Drupal::logger('mailchimp')
->error('An error occurred adding webhook for list {list}. "{message}"', [
'list' => $list_id,
'message' => $e
->getMessage(),
]);
return FALSE;
}
}