diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 28e03a6..93f1c2e 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -1514,6 +1514,7 @@ public function create_subscribers(array $subscribers, string $callback_url = '' * - 'count_less_than' (int|null). * - 'after' (\DateTime|null). * - 'before' (\DateTime|null). + * - 'states' (array). * - 'any' (array|null). * @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. @@ -1538,6 +1539,10 @@ public function filter_subscribers( foreach ($all as $condition) { $option = []; + if (array_key_exists('type', $condition) && !empty($condition['type'])) { + $option['type'] = $condition['type']; + } + if (array_key_exists('count_greater_than', $condition) && $condition['count_greater_than'] !== null) { $option['count_greater_than'] = $condition['count_greater_than']; } @@ -1554,6 +1559,10 @@ public function filter_subscribers( $option['before'] = $condition['before']->format('Y-m-d'); } + if (array_key_exists('states', $condition) && !empty($condition['states'])) { + $option['states'] = (array) $condition['states']; + } + if (array_key_exists('any', $condition) && !empty($condition['any'])) { $option['any'] = (array) $condition['any']; } diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index c2b013a..33bb640 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -4438,6 +4438,9 @@ public function testFilterSubscribers() 'count_less_than' => 100, 'after' => new \DateTime('2024-01-01'), 'before' => new \DateTime('2027-01-01'), + 'states' => [ + 'active', + ], ] ] ); @@ -4465,6 +4468,9 @@ public function testFilterSubscribersWithMultipleConditions() 'count_less_than' => 100, 'after' => new \DateTime('2024-01-01'), 'before' => new \DateTime('2027-01-01'), + 'states' => [ + 'active', + ], ], [ 'type' => 'clicks', @@ -4483,7 +4489,7 @@ public function testFilterSubscribersWithMultipleConditions() /** * Test that filter_subscribers() returns the expected data - * when multiple any conditions are specified. + * when no parameters are specified. * * @since 2.4.0 * @@ -4498,6 +4504,29 @@ public function testFilterSubscribersWithNoParameters() $this->assertPaginationExists($result); } + /** + * Test that filter_subscribers() throws a ServerException + * when invalid parameters are specified. + * + * @since 2.4.0 + * + * @return void + */ + public function testFilterSubscribersWithInvalidParameters() + { + $this->expectException(ServerException::class); + $result = $this->api->filter_subscribers( + [ + [ + 'foo' => 'bar', + ], + [ + 'type' => 'not-a-real-type', + ] + ] + ); + } + /** * Test that filter_subscribers() returns the expected data * when the total count is included.