@@ -504,82 +504,122 @@ public function get_form_subscriptions(
504
504
}
505
505
506
506
/**
507
- * Gets all sequences
507
+ * Gets sequences
508
508
*
509
- * @see https://developers.convertkit.com/#list-sequences
509
+ * @param string $after_cursor Return results after the given pagination cursor.
510
+ * @param string $before_cursor Return results before the given pagination cursor.
511
+ * @param integer $per_page Number of results to return.
512
+ *
513
+ * @see https://developers.convertkit.com/v4.html#list-sequences
510
514
*
511
515
* @return false|mixed
512
516
*/
513
- public function get_sequences ()
517
+ public function get_sequences (string $ after_cursor = '' , string $ before_cursor = '' , int $ per_page = 100 )
514
518
{
515
- return $ this ->get ('sequences ' );
519
+ return $ this ->get (
520
+ endpoint: 'sequences ' ,
521
+ args: $ this ->build_pagination_params (
522
+ after_cursor: $ after_cursor ,
523
+ before_cursor: $ before_cursor ,
524
+ per_page: $ per_page
525
+ )
526
+ );
516
527
}
517
528
518
529
/**
519
530
* Adds a subscriber to a sequence by email address
520
531
*
521
- * @param integer $sequence_id Sequence ID.
522
- * @param string $email Email Address.
523
- * @param string $first_name First Name.
524
- * @param array<string, string> $fields Custom Fields.
525
- * @param array<string, int> $tag_ids Tag ID(s) to subscribe to.
532
+ * @param integer $sequence_id Sequence ID.
533
+ * @param string $email Email Address.
526
534
*
527
- * @see https://developers.convertkit.com/#add-subscriber-to-a- sequence
535
+ * @see https://developers.convertkit.com/v4.html #add-subscriber-to-sequence-by-email-address
528
536
*
529
537
* @return false|mixed
530
538
*/
531
- public function add_subscriber_to_sequence (
532
- int $ sequence_id ,
533
- string $ email ,
534
- string $ first_name = '' ,
535
- array $ fields = [],
536
- array $ tag_ids = []
537
- ) {
538
- // Build parameters.
539
- $ options = ['email ' => $ email ];
540
-
541
- if (!empty ($ first_name )) {
542
- $ options ['first_name ' ] = $ first_name ;
543
- }
544
- if (!empty ($ fields )) {
545
- $ options ['fields ' ] = $ fields ;
546
- }
547
- if (!empty ($ tag_ids )) {
548
- $ options ['tags ' ] = $ tag_ids ;
549
- }
550
-
551
- // Send request.
539
+ public function add_subscriber_to_sequence (int $ sequence_id , string $ email )
540
+ {
552
541
return $ this ->post (
553
- sprintf ('sequences/%s/subscribe ' , $ sequence_id ),
554
- $ options
542
+ endpoint: sprintf ('sequences/%s/subscribers ' , $ sequence_id ),
543
+ args: [ ' email_address ' => $ email ]
555
544
);
556
545
}
557
546
558
547
/**
559
- * Gets subscribers to a sequence
548
+ * Adds a subscriber to a sequence by subscriber ID
560
549
*
561
- * @param integer $sequence_id Sequence ID.
562
- * @param string $sort_order Sort Order (asc|desc) .
563
- * @param string $subscriber_state Subscriber State (active,cancelled).
564
- * @param integer $page Page.
550
+ * @param integer $sequence_id Sequence ID.
551
+ * @param integer $subscriber_id Subscriber ID .
552
+ *
553
+ * @see https://developers.convertkit.com/v4.html#add-subscriber-to-sequence
565
554
*
566
- * @see https://developers.convertkit.com/#list-subscriptions-to-a-sequence
555
+ * @since 2.0.0
556
+ *
557
+ * @return false|mixed
558
+ */
559
+ public function add_subscriber_to_sequence_by_subscriber_id (int $ sequence_id , int $ subscriber_id )
560
+ {
561
+ return $ this ->post (sprintf ('sequences/%s/subscribers/%s ' , $ sequence_id , $ subscriber_id ));
562
+ }
563
+
564
+ /**
565
+ * List subscribers for a sequence
566
+ *
567
+ * @param integer $sequence_id Sequence ID.
568
+ * @param string $subscriber_state Subscriber State (active|bounced|cancelled|complained|inactive).
569
+ * @param \DateTime $created_after Filter subscribers who have been created after this date.
570
+ * @param \DateTime $created_before Filter subscribers who have been created before this date.
571
+ * @param \DateTime $added_after Filter subscribers who have been added to the form after this date.
572
+ * @param \DateTime $added_before Filter subscribers who have been added to the form before this date.
573
+ * @param string $after_cursor Return results after the given pagination cursor.
574
+ * @param string $before_cursor Return results before the given pagination cursor.
575
+ * @param integer $per_page Number of results to return.
576
+ *
577
+ * @see https://developers.convertkit.com/v4.html#list-subscribers-for-a-sequence
567
578
*
568
579
* @return false|mixed
569
580
*/
570
581
public function get_sequence_subscriptions (
571
582
int $ sequence_id ,
572
- string $ sort_order = 'asc ' ,
573
583
string $ subscriber_state = 'active ' ,
574
- int $ page = 1
584
+ \DateTime $ created_after = null ,
585
+ \DateTime $ created_before = null ,
586
+ \DateTime $ added_after = null ,
587
+ \DateTime $ added_before = null ,
588
+ string $ after_cursor = '' ,
589
+ string $ before_cursor = '' ,
590
+ int $ per_page = 100
575
591
) {
592
+ // Build parameters.
593
+ $ options = [];
594
+
595
+ if (!empty ($ subscriber_state )) {
596
+ $ options ['status ' ] = $ subscriber_state ;
597
+ }
598
+ if (!is_null ($ created_after )) {
599
+ $ options ['created_after ' ] = $ created_after ->format ('Y-m-d ' );
600
+ }
601
+ if (!is_null ($ created_before )) {
602
+ $ options ['created_before ' ] = $ created_before ->format ('Y-m-d ' );
603
+ }
604
+ if (!is_null ($ added_after )) {
605
+ $ options ['added_after ' ] = $ added_after ->format ('Y-m-d ' );
606
+ }
607
+ if (!is_null ($ added_before )) {
608
+ $ options ['added_before ' ] = $ added_before ->format ('Y-m-d ' );
609
+ }
610
+
611
+ // Build pagination parameters.
612
+ $ options = $ this ->build_pagination_params (
613
+ params: $ options ,
614
+ after_cursor: $ after_cursor ,
615
+ before_cursor: $ before_cursor ,
616
+ per_page: $ per_page
617
+ );
618
+
619
+ // Send request.
576
620
return $ this ->get (
577
- sprintf ('sequences/%s/subscriptions ' , $ sequence_id ),
578
- [
579
- 'sort_order ' => $ sort_order ,
580
- 'subscriber_state ' => $ subscriber_state ,
581
- 'page ' => $ page ,
582
- ]
621
+ endpoint: sprintf ('sequences/%s/subscribers ' , $ sequence_id ),
622
+ args: $ options
583
623
);
584
624
}
585
625
0 commit comments