Skip to content

Commit c5e2389

Browse files
authored
Merge pull request #136 from Kit/add-sequence-emails-methods
Add Sequence Emails CRUD Methods
2 parents f29083f + 7eb8361 commit c5e2389

3 files changed

Lines changed: 487 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
# Defines PHP Versions matrix to run tests on
2323
strategy:
2424
fail-fast: false
25+
max-parallel: 1
2526
matrix:
2627
php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
2728

src/ConvertKit_API_Traits.php

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,196 @@ public function get_sequence_subscriptions(
662662
);
663663
}
664664

665+
/**
666+
* List sequence emails
667+
*
668+
* @param integer $sequence_id Sequence ID.
669+
* @param boolean $include_total_count To include the total count of records in the response, use true.
670+
* @param string $after_cursor Return results after the given pagination cursor.
671+
* @param string $before_cursor Return results before the given pagination cursor.
672+
* @param integer $per_page Number of results to return.
673+
*
674+
* @see https://developers.kit.com/api-reference/sequence-emails/list-sequence-emails
675+
*
676+
* @return false|mixed
677+
*/
678+
public function get_sequence_emails(
679+
int $sequence_id,
680+
bool $include_total_count = false,
681+
string $after_cursor = '',
682+
string $before_cursor = '',
683+
int $per_page = 100
684+
) {
685+
return $this->get(
686+
sprintf('sequences/%s/emails', $sequence_id),
687+
$this->build_total_count_and_pagination_params(
688+
[],
689+
$include_total_count,
690+
$after_cursor,
691+
$before_cursor,
692+
$per_page
693+
)
694+
);
695+
}
696+
697+
/**
698+
* Create a sequence email
699+
*
700+
* @param integer $sequence_id Sequence ID.
701+
* @param string $subject Subject line of the email.
702+
* @param integer $delay_value Number of days or hours to wait before sending this email after the previous one.
703+
* @param string $delay_unit Unit for the send delay. Use `days` for schedule-aware delivery, `hours` for a fixed hourly delay.
704+
* @param string|null $preview_text Preview text shown in email clients before the email is opened.
705+
* @param string|null $content HTML body content of the email.
706+
* @param integer|null $email_template_id ID of the email template to use for layout and styling.
707+
* @param boolean $published Whether the email is active and will be sent to subscribers.
708+
* @param array<string>|null $send_days Days of the week this email may be sent. Defaults to all 7 days (inherits the sequence schedule). Pass a subset to restrict delivery, or null to reset to all days.
709+
* @param integer|null $position Zero-based position of the email in the sequence. Assigned automatically after the last email if omitted.
710+
*
711+
* @see https://developers.kit.com/api-reference/sequence-emails/create-a-sequence-email
712+
*
713+
* @return mixed|object
714+
*/
715+
public function create_sequence_email(
716+
int $sequence_id,
717+
string $subject,
718+
int $delay_value,
719+
string $delay_unit,
720+
string|null $preview_text = null,
721+
string|null $content = null,
722+
int|null $email_template_id = null,
723+
bool $published = false,
724+
array|null $send_days = null,
725+
int|null $position = null,
726+
) {
727+
$options = [
728+
'subject' => $subject,
729+
'delay_value' => $delay_value,
730+
'delay_unit' => $delay_unit,
731+
'published' => $published,
732+
'send_days' => $send_days,
733+
];
734+
735+
if (!empty($preview_text)) {
736+
$options['preview_text'] = $preview_text;
737+
}
738+
if (!empty($content)) {
739+
$options['content'] = $content;
740+
}
741+
if (!empty($email_template_id)) {
742+
$options['email_template_id'] = $email_template_id;
743+
}
744+
if (!empty($position)) {
745+
$options['position'] = $position;
746+
}
747+
748+
// Send request.
749+
return $this->post(
750+
sprintf('sequences/%s/emails', $sequence_id),
751+
$options
752+
);
753+
}
754+
755+
/**
756+
* Get a sequence email.
757+
*
758+
* @param integer $sequence_id Sequence ID.
759+
* @param integer $email_id Email ID.
760+
*
761+
* @see https://developers.kit.com/api-reference/sequence-emails/get-a-sequence-email
762+
*
763+
* @return mixed|object
764+
*/
765+
public function get_sequence_email(int $sequence_id, int $email_id)
766+
{
767+
return $this->get(sprintf('sequences/%s/emails/%s', $sequence_id, $email_id));
768+
}
769+
770+
/**
771+
* Updates a sequence
772+
*
773+
* @param integer $sequence_id Sequence ID.
774+
* @param integer $email_id Sequence Email ID.
775+
* @param string|null $subject Subject line of the email.
776+
* @param integer|null $delay_value Number of days or hours to wait before sending this email after the previous one.
777+
* @param string|null $delay_unit Unit for the send delay. Use `days` for schedule-aware delivery, `hours` for a fixed hourly delay.
778+
* @param string|null $preview_text Preview text shown in email clients before the email is opened.
779+
* @param string|null $content HTML body content of the email.
780+
* @param integer|null $email_template_id ID of the email template to use for layout and styling.
781+
* @param boolean|null $published Whether the email is active and will be sent to subscribers.
782+
* @param array<string>|null $send_days Days of the week this email may be sent. Defaults to all 7 days (inherits the sequence schedule). Pass a subset to restrict delivery, or null to reset to all days.
783+
* @param integer|null $position Zero-based position of the email in the sequence. Assigned automatically after the last email if omitted.
784+
*
785+
* @see https://developers.kit.com/api-reference/sequences/create-a-sequence
786+
*
787+
* @return mixed|object
788+
*/
789+
public function update_sequence_email(
790+
int $sequence_id,
791+
int $email_id,
792+
string|null $subject = null,
793+
int|null $delay_value = null,
794+
string|null $delay_unit = null,
795+
string|null $preview_text = null,
796+
string|null $content = null,
797+
int|null $email_template_id = null,
798+
bool|null $published = null,
799+
array|null $send_days = null,
800+
int|null $position = null,
801+
) {
802+
// Build parameters.
803+
$options = ['send_days' => $send_days];
804+
805+
if (!is_null($subject)) {
806+
$options['subject'] = $subject;
807+
}
808+
if (!is_null($delay_value)) {
809+
$options['delay_value'] = $delay_value;
810+
}
811+
if (!is_null($delay_unit)) {
812+
$options['delay_unit'] = $delay_unit;
813+
}
814+
if (!is_null($preview_text)) {
815+
$options['preview_text'] = $preview_text;
816+
}
817+
if (!is_null($content)) {
818+
$options['content'] = $content;
819+
}
820+
if (!is_null($email_template_id)) {
821+
$options['email_template_id'] = $email_template_id;
822+
}
823+
if (!is_null($published)) {
824+
$options['published'] = $published;
825+
}
826+
if (!is_null($send_days)) {
827+
$options['send_days'] = $send_days;
828+
}
829+
if (!is_null($position)) {
830+
$options['position'] = $position;
831+
}
832+
833+
// Send request.
834+
return $this->put(
835+
sprintf('sequences/%s/emails/%s', $sequence_id, $email_id),
836+
$options
837+
);
838+
}
839+
840+
/**
841+
* Deletes a sequence email.
842+
*
843+
* @param integer $sequence_id Sequence ID.
844+
* @param integer $email_id Email ID.
845+
*
846+
* @see https://developers.kit.com/api-reference/sequence-emails/delete-a-sequence-email
847+
*
848+
* @return mixed|object
849+
*/
850+
public function delete_sequence_email(int $sequence_id, int $email_id)
851+
{
852+
return $this->delete(sprintf('sequences/%s/emails/%s', $sequence_id, $email_id));
853+
}
854+
665855
/**
666856
* List snippets
667857
*

0 commit comments

Comments
 (0)