Skip to content
Paride Azzari edited this page Aug 24, 2024 · 1 revision

Through the email entrypoint you can control, sync and unsync the emails sent to the contacts.

The sent email object has the following properties:

[
  "id" => int
  "subject" => ?string
  "headers" => ?string
  "contact_id" => ?int
  "sent_to_address" => string
  "sent_to_cc_addresses" => ?string
  "sent_to_bcc_addresses" => ?string
  "sent_from_address" => ?string
  "sent_from_reply_address" => ?string
  "sent_date" => ?datetime
  "received_date" => ?datetime
  "opened_date" => ?datetime
  "clicked_date" => ?datetime
  "plain_content" => ?string
  "html_content" => ?string
  "original_provider" => "UNKNOWN" // ENUM UNKNWON, GOOGLE or INFUSIONSOFT
  "original_provider_id" => string
  "provider_source_id" => ?string
]

All the ? fields can be null. original_provider is set to UNKNOWN if is not GOOGLE or INFUSIONSOFT, the original_provider_id is set automatically.

List

The method list retrieves a list of all the sent emails.

use KeapGeek\Keap\Facades\Keap;

Keap::email()->list([
    'contact_id' => ?int,
    'email' => ?string,
    'limit' => ?int,
    'offset' => ?int,
    'since_sent_date' => ?datetime,
    'until_sent_date' => ?datetime,
]);

This method accepts different optional parameters, to query on:

  • contact_id. The id of the contact to find emails for.
  • email. The email address to query on.
  • limit is the amount of emails to return, it defaults to 1000.
  • offset is the first item that starts the set, it defaults to 0.
  • since_sent_date is the date to query on, emails sent since the given date.
  • until_sent_date is the date to query on, emails sent until the given date. If not specified, defaults to the current date. If this field is present, since_sent_date must also be included.

You can input any Carbon parsable string in the date fields, since they will automatically be converted into timestamps using Carbon::parse.

It returns an array with all the retrieved Email Models.

Count

The method count returns the counts the emails that have been sent.

use KeapGeek\Keap\Facades\Keap;

Keap::email()->count([
    'contact_id' => ?int,
    'email' => ?string,
    'since_sent_date' => ?datetime,
    'until_sent_date' => ?datetime,
]);

As for the list method, this method accepts optional parameters to query emails on.

Create

The create method creates a record of an email sent to a contact.

use KeapGeek\Keap\Facades\Keap;

Keap::email()->create([
    'clicked_date' => ?datetime,
    'contact_id' => ?int,
    'headers' => ?string,
    'html_content' => ?string,
    'opened_date' => ?datetime,
    'original_provider' => ?string, //ENUM GOOGLE, UNKNOWN or INFUSIONSOFT
    'original_provider_id' => ?string,
    'plain_content' => ?string,
    'provider_source_id' => ?string,
    'received_date' => ?datetime,
    'sent_date' => ?datetime,
    'sent_from_address' => ?string,
    'sent_from_reply_address' => ?string,
    'sent_to_address' => string, //required
    'sent_to_bcc_address' => ?string,
    'sent_to_cc_address' => ?string,
    'subject' => ?string,
]);

You can input any Carbon parsable string in the datetime fields, since they will automatically be converted into timestamps using Carbon::parse.

All the ? fields are optional, only the sent_to_address is required.

  • contact_id is the id of the contact receiving the email.
  • original_provider is the Provider that sent the email case insensitive, must be in list [GOOGLE, INFUSIONSOFT]. If omitted gets mapped to UNKNOWN.
  • original_provider_id is the id of the provider, must be unique when combined with provider. If omitted a UUID is autogenerated for the record.

Send an email

To send an email to a list of contacts you can use the send method.

use KeapGeek\Keap\Facades\Keap;

Keap::email()->send([
    'address_field' => ?string,
    'attachments' => ?array
    'contacts' => array, //required
    'html_content' => ?string,
    'plain_content' => ?string,
    'subject' => string, //required
    'user_id' => int, //required
]);
  • address_field is the email field of each Contact record to address the email to, such as 'Email', 'EmailAddress2', 'EmailAddress3' or '_CustomFieldName', defaulting to the contact's primary email.
  • attachments is an array of files attachment, each file has the structure shown below.
  • contacts is an array of contact ids to send the email to.
  • html_content is the html formatted content of the email.
  • plain_content is the plain text content of the email.
  • subject is the email subject line, it is required.
  • user_id is the user to send the email on behalf of, it is required.

To add an attachment to the email, you must use the following syntax

    'attachments' => [$file1, $file2, $file3],

where the file are

$file = [
    'file_data' => string,
    'file_name' => string,
]

The method returns true if the request has been accepted.

Find

The find method allows to retrieve a single email that has been sent.

use KeapGeek\Keap\Facades\Keap;

Keap::email()->find(int $email_id);

This method returns the email model or null if not found.

Delete

The method delete removes a specific email record.

use KeapGeek\Keap\Facades\Keap;

Keap::email()->delete(int $email_id);

This methods just returns true if the request succeeded.

Create a Set

If you want to create a set of records of emails sent to contacts, with a maximum of 1000 per transaction. You can use the createSet method.

use KeapGeek\Keap\Facades\Keap;

Keap::email()->createSet([$email1, $email2]);

Where it accepts an array of email records, each one with the syntax of the previously shown create method.

Remove Set

This method removes a batch of emails records.

use KeapGeek\Keap\Facades\Keap;

$email_ids = [1, 2, 3];
Keap::email()->removeSet(array $email_ids);

It accepts an array of id of emails.

Clone this wiki locally