From 8e70e062188182384e0a122a21f75205348ea6b0 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 9 Jun 2026 11:52:00 +0100 Subject: [PATCH 1/3] Add `status` query parameter to Broadcasts + Broadcasts Stats --- src/ConvertKit_API_Traits.php | 10 +++++ tests/ConvertKitAPITest.php | 84 +++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index f758017..28e03a6 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -1753,6 +1753,7 @@ public function get_subscriber_tags( * @param \DateTime|null $sent_after Get broadcasts sent after the given date. * @param \DateTime|null $sent_before Get broadcasts sent before the given date. * @param boolean $slim When true, omits expensive optional fields from the response. + * @param string|null $status Get broadcasts with the given status (draft, scheduled, sending, completed, aborted). * @param boolean $include_total_count To include the total count of records in the response, use true. * @param string $after_cursor Return results after the given pagination cursor. * @param string $before_cursor Return results before the given pagination cursor. @@ -1766,6 +1767,7 @@ public function get_broadcasts( \DateTime|null $sent_after = null, \DateTime|null $sent_before = null, bool $slim = false, + string|null $status = null, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', @@ -1774,6 +1776,9 @@ public function get_broadcasts( // Build parameters. $options = ['slim' => $slim]; + if (!is_null($status)) { + $options['status'] = $status; + } if (!is_null($sent_after)) { $options['sent_after'] = $sent_after->format('Y-m-d'); } @@ -1935,6 +1940,7 @@ public function get_broadcast_link_clicks( * * @param \DateTime|null $sent_after Get broadcasts sent after the given date. * @param \DateTime|null $sent_before Get broadcasts sent before the given date. + * @param string|null $status Get broadcasts with the given status (draft, scheduled, sending, completed, aborted). * @param boolean $include_total_count To include the total count of records in the response, use true. * @param string $after_cursor Return results after the given pagination cursor. * @param string $before_cursor Return results before the given pagination cursor. @@ -1949,6 +1955,7 @@ public function get_broadcast_link_clicks( public function get_broadcasts_stats( \DateTime|null $sent_after = null, \DateTime|null $sent_before = null, + string|null $status = null, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', @@ -1957,6 +1964,9 @@ public function get_broadcasts_stats( // Build parameters. $options = []; + if (!is_null($status)) { + $options['status'] = $status; + } if (!is_null($sent_after)) { $options['sent_after'] = $sent_after->format('Y-m-d'); } diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index cb07ce6..e349b18 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -5343,6 +5343,46 @@ public function testGetBroadcastsSlim() $this->assertArrayNotHasKey('subscriber_filter', $broadcast); } + /** + * Test that get_broadcasts() returns the expected data + * when the completed status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsWithCompletedStatus() + { + $result = $this->api->get_broadcasts( + status: 'completed' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + } + + /** + * Test that get_broadcasts() returns the expected data + * when the aborted status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsWithAbortedStatus() + { + $result = $this->api->get_broadcasts( + status: 'aborted' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + $this->assertPaginationExists($result); + + // Assert no broadcasts were returned. + $this->assertCount(0, $result->broadcasts); + } + /** * Test that get_broadcasts() returns the expected data * when pagination parameters and per_page limits are specified. @@ -5740,6 +5780,50 @@ public function testGetBroadcastsStatsWithSentBefore() $this->assertCount(12, $result->broadcasts); } + /** + * Test that get_broadcasts_stats() returns the expected data + * when the completed status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsStatsWithCompletedStatus() + { + $result = $this->api->get_broadcasts_stats( + status: 'completed' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + $this->assertPaginationExists($result); + + // Assert the expected number of broadcasts were returned. + $this->assertCount(12, $result->broadcasts); + } + + /** + * Test that get_broadcasts_stats() returns the expected data + * when the aborted status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsStatsWithAbortedStatus() + { + $result = $this->api->get_broadcasts_stats( + status: 'aborted' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + $this->assertPaginationExists($result); + + // Assert the expected number of broadcasts were returned. + $this->assertCount(0, $result->broadcasts); + } + /** * Test that get_broadcasts_stats() returns the expected data * when the total count is included. From 65fbb1596b45a4e11fe7e8667c71a4cccb6bffab Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 11 Jun 2026 17:49:48 +0100 Subject: [PATCH 2/3] Fix Sequence Email Test --- tests/ConvertKitAPITest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index cb07ce6..6b013f0 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -1755,7 +1755,7 @@ public function testCreateGetUpdateAndDeleteSequenceEmail() preview_text: 'Test Preview Text', content: 'Test Content', email_template_id: (int) $_ENV['CONVERTKIT_API_EMAIL_TEMPLATE_ID'], - published: false, + published: true, send_days: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'], position: 0 ); @@ -1770,7 +1770,7 @@ public function testCreateGetUpdateAndDeleteSequenceEmail() $this->assertEquals('Test Preview Text', $result['preview_text']); $this->assertEquals('Test Content', $result['content']); $this->assertEquals((int) $_ENV['CONVERTKIT_API_EMAIL_TEMPLATE_ID'], $result['email_template_id']); - $this->assertEquals(false, $result['published']); + $this->assertEquals(true, $result['published']); $this->assertEquals(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'], $result['send_days']); $this->assertEquals(2, $result['position']); From e4cdea0e6fd19de4b6789df172e290d31171d10a Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 11 Jun 2026 18:16:31 +0100 Subject: [PATCH 3/3] Fix `testCreateSubscriberWithInvalidCustomFields` test The API now returns a `warnings` array rather than throwing a ClientException --- tests/ConvertKitAPITest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 6b013f0..b791d55 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -4329,8 +4329,8 @@ public function testCreateSubscriberWithInvalidSubscriberState() } /** - * Test that create_subscriber() throws a ClientException when an invalid - * custom field is included. + * Test that create_subscriber() returns the expected warnings + * when an invalid custom field is included. * * @since 2.0.0 * @@ -4338,7 +4338,6 @@ public function testCreateSubscriberWithInvalidSubscriberState() */ public function testCreateSubscriberWithInvalidCustomFields() { - $this->expectException(ClientException::class); $emailAddress = $this->generateEmailAddress(); $result = $this->api->create_subscriber( email_address: $emailAddress, @@ -4346,6 +4345,7 @@ public function testCreateSubscriberWithInvalidCustomFields() 'not_a_custom_field' => 'value' ] ); + $this->assertArrayHasKey('warnings', get_object_vars($result)); } /**