Email Histories Queries

Query email history for tracking sent communications.

EmailHistory

Returns a single email history entry based on the provided id.

Example Query:

query {
  EmailHistory(id: 100012) {
    id
    to
    cc
    bcc
    object
    body
    emailable_type
    created_at
    attachments {
      id
      filename
      url
    }
  }
}

Example Result:

{
  "data": {
    "EmailHistory": {
      "id": 100012,
      "to": ["[email protected]", "[email protected]"],
      "cc": ["[email protected]"],
      "bcc": ["[email protected]"],
      "object": "Invoice #INV-2025-001",
      "body": "<html>Your invoice is attached.</html>",
      "emailable_type": "Invoice",
      "created_at": "2025-10-01T12:00:00Z",
      "attachments": [
        {
          "id": 5001,
          "filename": "invoice_001.pdf",
          "url": "https://example.com/attachments/invoice_001.pdf"
        }
      ]
    }
  }
}

EmailHistories

Returns a paginated list of email histories. You can apply filters and sorting to refine results.

Example Query:

query {
  EmailHistories(
    where: { AND: [{ column: "TO", operator: "EQ", value: "[email protected]" }] }
    orderBy: { column: "CREATED_AT", order: "DESC" }
    first: 2
    page: 1
  ) {
    paginatorInfo {
      total
      currentPage
      lastPage
    }
    data {
      id
      to
      cc
      object
      emailable_type
      created_at
    }
  }
}

Example Result:

{
  "data": {
    "EmailHistories": {
      "paginatorInfo": {
        "total": 42,
        "currentPage": 1,
        "lastPage": 3
      },
      "data": [
        {
          "id": 100012,
          "to": ["[email protected]"],
          "cc": ["[email protected]"],
          "object": "Invoice #INV-2025-001",
          "emailable_type": "Invoice",
          "created_at": "2025-10-01T12:00:00Z"
        },
        {
          "id": 100011,
          "to": ["[email protected]"],
          "cc": [],
          "object": "Order Confirmation #ORD-2025-042",
          "emailable_type": "Order",
          "created_at": "2025-09-30T15:30:00Z"
        }
      ]
    }
  }
}

Available Fields

FieldTypeDescription
idIntUnique identifier of the email history.
user_profile_idIntUser profile ID associated with the email.
to[String]Recipients of the email.
cc[String]Carbon copy (CC) recipients of the email.
bcc[String]Blind carbon copy (BCC) recipients of the email.
objectStringSubject of the email.
bodyStringBody content of the email.
emailable_idIntID of the document associated with the email.
emailable_typeDocumentTypeType of the document the email is related to.
attachments[File]List of files attached to the email.
created_atDateDate when the email history was created.

Filters

You can filter results using the following fields. Each filter is defined by:

  • column: The field to filter on.
  • operator: Comparison operator (EQ, LIKE, IN, etc.).
  • value: The value to compare against.
FieldExample
id{ "column": "ID", "operator": "EQ", "value": 12345 }
to{ "column": "TO", "operator": "LIKE", "value": "%@fakecompany.com%" }
cc{ "column": "CC", "operator": "IN", "value": ["[email protected]", "[email protected]"] }
bcc{ "column": "BCC", "operator": "EQ", "value": "[email protected]" }
emailable_id{ "column": "EMAILABLE_ID", "operator": "EQ", "value": 987654321 }
emailable_type{ "column": "EMAILABLE_TYPE", "operator": "EQ", "value": "Invoice" }
user_profile_id{ "column": "USER_PROFILE_ID", "operator": "EQ", "value": 123456789 }

Sorting

You can sort results using the following fields:

  • emailable_id
  • emailable_type
  • created_at

Example Sorting:

query {
  EmailHistories(
    orderBy: [
      { column: "CREATED_AT", order: "DESC" }
      { column: "EMAILABLE_TYPE", order: "ASC" }
    ]
    first: 50
    page: 1
  ) {
    data {
      id
      to
      emailable_type
      created_at
    }
  }
}

Example Result:

{
  "data": {
    "EmailHistories": {
      "data": [
        {
          "id": 100012,
          "to": ["[email protected]"],
          "emailable_type": "Invoice",
          "created_at": "2025-10-01T12:00:00Z"
        },
        {
          "id": 100011,
          "to": ["[email protected]"],
          "emailable_type": "Order",
          "created_at": "2025-09-30T15:30:00Z"
        }
      ]
    }
  }
}

Additional Notes

  • Fields like to, cc, and bcc are arrays of strings (e.g., ["[email protected]", "[email protected]"]).
  • The attachments field returns an array of File objects, each with id, filename, and url.
  • For paginated queries, use first to set the number of results per page and page to navigate.

DocumentType

ValueDescription
EstimateDocument is an estimate.
CreditTransactionDocument is a credit transaction.
OrderDocument is a sales order.
InvoiceDocument is an invoice.
ShippingOrderDocument is a shipping order.
ProductReturnDocument is a product return.
PurchaseDocument is a purchase.
PurchaseReceiptDocument is a purchase receipt.
StockAdjustmentDocument is a stock adjustment.
ManufacturingOrderDocument is a manufacturing order.