# emailMessages query


`emailMessages` is a GraphQL query of the Chameleoon MAX API. Send it as `POST https://max-api.chameleoon.sk/api/v1/graphql` with your API key, see [Chameleoon MAX](/chameleoon-max).

Returns the messages linked to a record, newest first. Use it to show a record's e-mail
history.

- Requires the `email.read` permission, with the record in your API key's scope (otherwise
  `NOT_FOUND`).
- Lists only the messages your API key may read (see [`EmailMessage`](/chameleoon-max/type/email-message)). A message also
  linked to another record that your API key cannot see is left out.
- A message's `htmlBody` and `textBody` cost 50 points each.

A connection, paged with `first`/`after` or `last`/`before`, at most 250 a page.
Pass exactly one of `first` or `last`, from 1 to 250. `first` (with `after`) pages
forward; `last` (with `before`) pages backward. `last` alone returns the last page.

A page costs 2 + first (or last) × the cost of one node.

## Arguments

- `entity`: [`EmailResourceInput!`](/chameleoon-max/type/email-resource-input) · required
- `first`: `Int`
- `after`: `String`
- `last`: `Int`
- `before`: `String`

## Returns

[`EmailMessageConnection!`](/chameleoon-max/type/email-message-connection): a page of [`EmailMessage`](/chameleoon-max/type/email-message).

## Example

**Query**

```graphql
query emailMessages($entity: EmailResourceInput!, $first: Int) {
  emailMessages(entity: $entity, first: $first) {
    edges {
      cursor
    }
    nodes {
      id
      status
      senderId
      fromAddress
      fromName
      replyTo
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}
```

**Variables**

```json
{
  "entity": {
    "kind": "INVOICE",
    "id": "00000000-0000-4000-8000-000000000001"
  },
  "first": 10
}
```

**Response**

```json
{
  "data": {
    "emailMessages": {
      "edges": [
        {
          "cursor": "example"
        }
      ],
      "nodes": [
        {
          "id": "00000000-0000-4000-8000-000000000001",
          "status": "QUEUED",
          "senderId": "00000000-0000-4000-8000-000000000001",
          "fromAddress": "example",
          "fromName": "example",
          "replyTo": "example"
        }
      ],
      "pageInfo": {
        "hasNextPage": true,
        "hasPreviousPage": true,
        "startCursor": "example",
        "endCursor": "example"
      }
    }
  }
}
```

Values are illustrative: replace IDs and codes with your own before you send the call.
