@@ -945,6 +945,74 @@ public function create_subscribers(array $subscribers, string $callback_url = ''
945945 );
946946 }
947947
948+ /**
949+ * Filter subscribers based on engagement.
950+ *
951+ * @param array<int, array<string, mixed>> $all Array of filter conditions where ALL must be met (AND logic). Each condition can have.
952+ * - 'type' (string).
953+ * - 'count_greater_than' (int|null).
954+ * - 'count_less_than' (int|null).
955+ * - 'after' (\DateTime|null).
956+ * - 'before' (\DateTime|null).
957+ * - 'any' (array<int|string, mixed>|null).
958+ * @param boolean $include_total_count To include the total count of records in the response, use true.
959+ * @param string $after_cursor Return results after the given pagination cursor.
960+ * @param string $before_cursor Return results before the given pagination cursor.
961+ * @param integer $per_page Number of results to return.
962+ *
963+ * @since 2.4.0
964+ *
965+ * @see https://developers.kit.com/api-reference/subscribers/filter-subscribers-based-on-engagement
966+ *
967+ * @return mixed
968+ */
969+ public function filter_subscribers (
970+ array $ all = [],
971+ bool $ include_total_count = false ,
972+ string $ after_cursor = '' ,
973+ string $ before_cursor = '' ,
974+ int $ per_page = 100
975+ ) {
976+ $ options = [];
977+
978+ foreach ($ all as $ condition ) {
979+ $ option = [];
980+
981+ if (array_key_exists ('count_greater_than ' , $ condition ) && $ condition ['count_greater_than ' ] !== null ) {
982+ $ option ['count_greater_than ' ] = $ condition ['count_greater_than ' ];
983+ }
984+
985+ if (array_key_exists ('count_less_than ' , $ condition ) && $ condition ['count_less_than ' ] !== null ) {
986+ $ option ['count_less_than ' ] = $ condition ['count_less_than ' ];
987+ }
988+
989+ if (array_key_exists ('after ' , $ condition ) && $ condition ['after ' ] instanceof \DateTime) {
990+ $ option ['after ' ] = $ condition ['after ' ]->format ('Y-m-d ' );
991+ }
992+
993+ if (array_key_exists ('before ' , $ condition ) && $ condition ['before ' ] instanceof \DateTime) {
994+ $ option ['before ' ] = $ condition ['before ' ]->format ('Y-m-d ' );
995+ }
996+
997+ if (array_key_exists ('any ' , $ condition ) && !empty ($ condition ['any ' ])) {
998+ $ option ['any ' ] = (array ) $ condition ['any ' ];
999+ }
1000+
1001+ $ options [] = $ option ;
1002+ }//end foreach
1003+
1004+ return $ this ->post (
1005+ 'subscribers/filter ' ,
1006+ $ this ->build_total_count_and_pagination_params (
1007+ ['all ' => $ options ],
1008+ $ include_total_count ,
1009+ $ after_cursor ,
1010+ $ before_cursor ,
1011+ $ per_page
1012+ )
1013+ );
1014+ }
1015+
9481016 /**
9491017 * Get the ConvertKit subscriber ID associated with email address if it exists.
9501018 * Return false if subscriber not found.
@@ -1468,6 +1536,8 @@ public function create_webhook(string $url, string $event, string $parameter = '
14681536 case 'subscriber.subscriber_bounce ' :
14691537 case 'subscriber.subscriber_complain ' :
14701538 case 'purchase.purchase_create ' :
1539+ case 'custom_field.field_created ' :
1540+ case 'custom_field.field_deleted ' :
14711541 $ eventData = ['name ' => $ event ];
14721542 break ;
14731543
@@ -1508,6 +1578,13 @@ public function create_webhook(string $url, string $event, string $parameter = '
15081578 ];
15091579 break ;
15101580
1581+ case 'custom_field.field_value_updated ' :
1582+ $ eventData = [
1583+ 'name ' => $ event ,
1584+ 'custom_field_id ' => $ parameter ,
1585+ ];
1586+ break ;
1587+
15111588 default :
15121589 throw new \InvalidArgumentException (sprintf ('The event %s is not supported ' , $ event ));
15131590 }//end switch
@@ -1617,6 +1694,36 @@ public function create_custom_fields(array $labels, string $callback_url = '')
16171694 );
16181695 }
16191696
1697+ /**
1698+ * Bulk update subscriber custom field values
1699+ *
1700+ * @param array<array<string,string|integer>> $custom_field_values Array of custom field values to update.
1701+ * - 'subscriber_id' (int) Subscriber ID.
1702+ * - 'subscriber_custom_field_id' (int) Custom Field ID.
1703+ * - 'value' (string|integer) Value to update.
1704+ * @param string $callback_url URL to notify for large batch size when async processing complete.
1705+ *
1706+ * @since 2.4.0
1707+ *
1708+ * @see https://developers.kit.com/api-reference/custom-fields/bulk-update-subscriber-custom-field-values
1709+ *
1710+ * @return mixed|object
1711+ */
1712+ public function update_subscriber_custom_field_values (array $ custom_field_values , string $ callback_url = '' )
1713+ {
1714+ // Build parameters.
1715+ $ options = ['custom_field_values ' => $ custom_field_values ];
1716+ if (!empty ($ callback_url )) {
1717+ $ options ['callback_url ' ] = $ callback_url ;
1718+ }
1719+
1720+ // Send request.
1721+ return $ this ->post (
1722+ 'bulk/custom_fields/subscribers ' ,
1723+ $ options
1724+ );
1725+ }
1726+
16201727 /**
16211728 * Update a custom field.
16221729 *
@@ -1854,15 +1961,15 @@ public function strip_html_head_body_tags(string $markup)
18541961 /**
18551962 * Adds total count and pagination parameters to the given array of existing API parameters.
18561963 *
1857- * @param array<string, string|integer|bool > $params API parameters.
1858- * @param boolean $include_total_count Return total count of records.
1859- * @param string $after_cursor Return results after the given pagination cursor.
1860- * @param string $before_cursor Return results before the given pagination cursor.
1861- * @param integer $per_page Number of results to return.
1964+ * @param array<string, string|integer|boolean|list<array<string, mixed>> > $params API parameters.
1965+ * @param boolean $include_total_count Return total count of records.
1966+ * @param string $after_cursor Return results after the given pagination cursor.
1967+ * @param string $before_cursor Return results before the given pagination cursor.
1968+ * @param integer $per_page Number of results to return.
18621969 *
18631970 * @since 2.0.0
18641971 *
1865- * @return array<string, string|integer |bool>
1972+ * @return array<string, string|int |bool|list<array<string, mixed>> >
18661973 */
18671974 private function build_total_count_and_pagination_params (
18681975 array $ params = [],
@@ -1888,8 +1995,8 @@ private function build_total_count_and_pagination_params(
18881995 /**
18891996 * Performs a GET request to the API.
18901997 *
1891- * @param string $endpoint API Endpoint.
1892- * @param array<string, int|string|boolean|array<string, int|string>|string> $args Request arguments.
1998+ * @param string $endpoint API Endpoint.
1999+ * @param array<string, int|string|boolean|array<string, int|string>|list<array< string, mixed>> > $args Request arguments.
18932000 *
18942001 * @return false|mixed
18952002 */
@@ -1901,8 +2008,8 @@ public function get(string $endpoint, array $args = [])
19012008 /**
19022009 * Performs a POST request to the API.
19032010 *
1904- * @param string $endpoint API Endpoint.
1905- * @param array<string, bool|integer|float|string|null|array<int|string, float|integer|string| array<string|string> >> $args Request arguments.
2011+ * @param string $endpoint API Endpoint.
2012+ * @param array<string, bool|integer|float|string|null|array<int|string, array<string|mixed>|boolean|integer|float|string >> $args Request arguments.
19062013 *
19072014 * @return false|mixed
19082015 */
@@ -1940,9 +2047,9 @@ public function delete(string $endpoint, array $args = [])
19402047 /**
19412048 * Performs an API request.
19422049 *
1943- * @param string $endpoint API Endpoint.
1944- * @param string $method Request method.
1945- * @param array<string, bool|integer|float|string|null|array<int|string, float |integer|string|array<string|string >>> $args Request arguments.
2050+ * @param string $endpoint API Endpoint.
2051+ * @param string $method Request method.
2052+ * @param array<string, bool|integer|float|string|null|array<int|string, bool |integer|float| string|array<string, mixed >>> $args Request arguments.
19462053 *
19472054 * @throws \Exception If JSON encoding arguments failed.
19482055 *
0 commit comments