From 4afb526eb4bc3a24f4555582f578f80bb9730d37 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 25 May 2026 12:29:08 +0800 Subject: [PATCH] Add `slim` query parameter support --- src/ConvertKit_API_Traits.php | 8 ++++-- tests/ConvertKitAPITest.php | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 9813a41..f758017 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -1212,6 +1212,7 @@ public function remove_tag_from_subscriber_by_email(int $tag_id, string $email_a * @param \DateTime|null $created_before Filter subscribers who have been created before this date. * @param \DateTime|null $tagged_after Filter subscribers who have been tagged after this date. * @param \DateTime|null $tagged_before Filter subscribers who have been tagged before this date. + * @param boolean $slim When true, omits expensive optional fields from the response. * @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. @@ -1228,13 +1229,14 @@ public function get_tag_subscriptions( \DateTime|null $created_before = null, \DateTime|null $tagged_after = null, \DateTime|null $tagged_before = null, + bool $slim = false, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', int $per_page = 100 ) { // Build parameters. - $options = []; + $options = ['slim' => $slim]; if (!empty($subscriber_state)) { $options['status'] = $subscriber_state; @@ -1750,6 +1752,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 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. @@ -1762,13 +1765,14 @@ public function get_subscriber_tags( public function get_broadcasts( \DateTime|null $sent_after = null, \DateTime|null $sent_before = null, + bool $slim = false, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', int $per_page = 100 ) { // Build parameters. - $options = []; + $options = ['slim' => $slim]; 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 613c20a..cb07ce6 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -2959,6 +2959,30 @@ public function testGetTagSubscriptions() $this->assertPaginationExists($result); } + /** + * Test that get_tag_subscriptions() returns the expected data + * when the slim parameter is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetTagSubscriptionsSlim() + { + $result = $this->api->get_tag_subscriptions( + tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'], + slim: true + ); + + // Assert subscribers and pagination exist. + $this->assertDataExists($result, 'subscribers'); + $this->assertPaginationExists($result); + + // Confirm custom field values are excluded from the data. + $broadcast = get_object_vars($result->subscribers[0]); + $this->assertArrayNotHasKey('fields', $broadcast); + } + /** * Test that get_tag_subscriptions() returns the expected data * when the total count is included. @@ -5292,6 +5316,33 @@ public function testGetBroadcastsWithSentBefore() $this->assertCount(12, $result->broadcasts); } + /** + * Test that get_broadcasts() returns the expected data + * when the slim parameter is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsSlim() + { + $result = $this->api->get_broadcasts( + slim: true + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + $this->assertPaginationExists($result); + + // Confirm content, public_url, email_address, email_template and subscriber_filter are excluded from the data. + $broadcast = get_object_vars($result->broadcasts[0]); + $this->assertArrayNotHasKey('content', $broadcast); + $this->assertArrayNotHasKey('public_url', $broadcast); + $this->assertArrayNotHasKey('email_address', $broadcast); + $this->assertArrayNotHasKey('email_template', $broadcast); + $this->assertArrayNotHasKey('subscriber_filter', $broadcast); + } + /** * Test that get_broadcasts() returns the expected data * when pagination parameters and per_page limits are specified.