You are here

function mailchimp_webhook_delete in Mailchimp 8

Same name and namespace in other branches
  1. 7.5 mailchimp.module \mailchimp_webhook_delete()
  2. 7.3 mailchimp.module \mailchimp_webhook_delete()
  3. 7.4 mailchimp.module \mailchimp_webhook_delete()
  4. 2.x mailchimp.module \mailchimp_webhook_delete()

Deletes a Mailchimp list webhook.

Parameters

string $list_id: The ID of the Mailchimp list to delete the webhook from.

string $url: The URL of the webhook endpoint.

Return value

bool TRUE if deletion was successful, FALSE otherwise.

See also

Mailchimp_Lists::webhookDel()

2 calls to mailchimp_webhook_delete()
MailchimpListsWebhookSettingsForm::submitForm in modules/mailchimp_lists/src/Form/MailchimpListsWebhookSettingsForm.php
Form submission handler.
MailchimpListsWebhookTest::testDeleteWebhook in modules/mailchimp_lists/src/Tests/MailchimpListsWebhookTest.php
Tests deletion of a webhook.

File

./mailchimp.module, line 1024
Mailchimp module.

Code

function mailchimp_webhook_delete($list_id, $url) {
  try {

    /* @var \Mailchimp\MailchimpLists $mc_lists */
    $mc_lists = mailchimp_get_api_object('MailchimpLists');
    $result = $mc_lists
      ->getWebhooks($list_id);
    if ($result->total_items > 0) {
      foreach ($result->webhooks as $webhook) {
        if ($webhook->url == $url) {
          $mc_lists
            ->deleteWebhook($list_id, $webhook->id);
          return TRUE;
        }
      }
    }
    return FALSE;
  } catch (\Exception $e) {
    \Drupal::logger('mailchimp')
      ->error('An error occurred deleting webhook for list {list}. "{message}"', [
      'list' => $list_id,
      'message' => $e
        ->getMessage(),
    ]);
    return FALSE;
  }
}