Skip to content

Commit 12c0618

Browse files
committed
Add API support
1 parent 8354a55 commit 12c0618

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/ConvertKit_API.php

+40-6
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,38 @@ public function destroy_broadcast(int $id)
14851485
return $this->delete(sprintf('broadcasts/%s', $id));
14861486
}
14871487

1488+
/**
1489+
* List webhooks.
1490+
*
1491+
* @param boolean $include_total_count To include the total count of records in the response, use true.
1492+
* @param string $after_cursor Return results after the given pagination cursor.
1493+
* @param string $before_cursor Return results before the given pagination cursor.
1494+
* @param integer $per_page Number of results to return.
1495+
*
1496+
* @since 2.0.0
1497+
*
1498+
* @see https://developers.convertkit.com/v4.html#list-webhooks
1499+
*
1500+
* @return false|mixed
1501+
*/
1502+
public function get_webhooks(
1503+
bool $include_total_count = false,
1504+
string $after_cursor = '',
1505+
string $before_cursor = '',
1506+
int $per_page = 100
1507+
) {
1508+
// Send request.
1509+
return $this->get(
1510+
endpoint: 'webhooks',
1511+
args: $this->build_total_count_and_pagination_params(
1512+
include_total_count: $include_total_count,
1513+
after_cursor: $after_cursor,
1514+
before_cursor: $before_cursor,
1515+
per_page: $per_page
1516+
)
1517+
);
1518+
}
1519+
14881520
/**
14891521
* Creates a webhook that will be called based on the chosen event types.
14901522
*
@@ -1494,7 +1526,7 @@ public function destroy_broadcast(int $id)
14941526
*
14951527
* @since 1.0.0
14961528
*
1497-
* @see https://developers.convertkit.com/#create-a-webhook
1529+
* @see https://developers.convertkit.com/v4.html#create-a-webhook
14981530
*
14991531
* @throws \InvalidArgumentException If the event is not supported.
15001532
*
@@ -1506,6 +1538,8 @@ public function create_webhook(string $url, string $event, string $parameter = '
15061538
switch ($event) {
15071539
case 'subscriber.subscriber_activate':
15081540
case 'subscriber.subscriber_unsubscribe':
1541+
case 'subscriber.subscriber_bounce':
1542+
case 'subscriber.subscriber_complain':
15091543
case 'purchase.purchase_create':
15101544
$eventData = ['name' => $event];
15111545
break;
@@ -1553,7 +1587,7 @@ public function create_webhook(string $url, string $event, string $parameter = '
15531587

15541588
// Send request.
15551589
return $this->post(
1556-
'automations/hooks',
1590+
'webhooks',
15571591
[
15581592
'target_url' => $url,
15591593
'event' => $eventData,
@@ -1564,17 +1598,17 @@ public function create_webhook(string $url, string $event, string $parameter = '
15641598
/**
15651599
* Deletes an existing webhook.
15661600
*
1567-
* @param integer $rule_id Rule ID.
1601+
* @param integer $id Webhook ID.
15681602
*
15691603
* @since 1.0.0
15701604
*
1571-
* @see https://developers.convertkit.com/#destroy-webhook
1605+
* @see https://developers.convertkit.com/v4.html#delete-a-webhook
15721606
*
15731607
* @return false|object
15741608
*/
1575-
public function destroy_webhook(int $rule_id)
1609+
public function delete_webhook(int $id)
15761610
{
1577-
return $this->delete(sprintf('automations/hooks/%s', $rule_id));
1611+
return $this->delete(sprintf('webhooks/%s', $id));
15781612
}
15791613

15801614
/**

0 commit comments

Comments
 (0)