# events query


`events` 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 a page of the event log: what happened to the records listed below, read forward from
a cursor, oldest first. Use it as a change feed, so that your system learns about changes in
MAX without reading every list again.

The log covers orders, receipts, issues, transfers, consignments, shipments, transfer advices,
receipt advices, invoices imported from the accounting system, and documents attached to
orders or to invoices.

#### Permissions

- Each entity type requires its own read permission, listed on [`EventEntityType`](/chameleoon-max/type/event-entity-type).
- Entity types that your API key may not read are left out without an error.
- If your API key is limited to legal entities or warehouses, you see only their events.

#### Errors

| Code | When |
| --- | --- |
| `FORBIDDEN_ROLE` | You name in `types` or `entityTypes` an entity type that your API key may not read, or your API key may read none of the entity types. |
| `VALIDATION` | A name in `types` is not an event type that the feed writes. |
| `VALIDATION` at `wait` | `wait` is outside 0 to 25. |
| `VALIDATION` with `extensions.reason` `CURSOR_EXPIRED` | The events after the cursor are no longer kept (about 30 days), so some changes cannot be replayed. Read the current state from the lists again, then start the feed without a cursor and skip the events that what you read already reflects (see Paging). |

#### Paging

- The feed is forward-only. Pass `pageInfo.endCursor` as `after` while `pageInfo.hasNextPage`
  is `true`, then keep polling with it.
- There is no `last`, no `before` and no total count.
- `first` is required, from 1 to 250. Every edge carries its own cursor.
- One entity's events come in `version` order.
- Without `after`, the feed starts with the oldest event kept, about 30 days back, and returns
  every event since. It does not start at the head, as [`stockCardChanges`](/chameleoon-max/query/stock-card-changes) does.
- You can receive an event that you have already applied: when you start again without a
  cursor, or when you retry with an older cursor. Skip an event whose `version` is not higher
  than the version you hold for its `entityType` and `entityId`.
- Receipts, issues, transfers and shipments return their last event's `version` when you read
  them (null while an event is being written: read again). For the other entity types, keep
  the `version` of the last event you applied; after you read their state again you hold none,
  so take each of their events as a sign to read the record again rather than applying its
  `transitions`.

#### Waiting

`wait` is a number of seconds, from 0 (the default) to 25.

- MAX waits only when you pass `after`, and only when the page would be empty with
  `hasNextPage` `false`.
- It answers as soon as an event that you may see arrives.
- When the time is up, or the server is shutting down, it answers with an empty page and an
  advanced `endCursor`. An empty answer is never an error: poll again with its `endCursor`.
- Your API key holds at most 4 waits open on one server, those of
  [`stockCardChanges`](/chameleoon-max/query/stock-card-changes) included. A further wait lasts `wait` or 5 seconds, whichever is
  less, without watching for events, then answers with what is there by then.

#### Event types

| Entity type | Event types |
| --- | --- |
| `SALES_ORDER` | `sales_order.confirmed`, `sales_order.completed`, `sales_order.reopened`, `sales_order.cancelled`, `sales_order.merged`, `sales_order.changed` |
| `RECEIPT` | `receipt.opened`, `receipt.completed`, `receipt.cancelled`, `receipt.revised`, `receipt.changed` |
| `ISSUE` | `issue.opened`, `issue.completed`, `issue.cancelled`, `issue.revised`, `issue.changed` |
| `TRANSFER` | `transfer.opened`, `transfer.completed`, `transfer.cancelled`, `transfer.revised`, `transfer.changed` |
| `FULFILMENT` | `fulfilment.created`, `fulfilment.shipped`, `fulfilment.cancelled`, `fulfilment.reset`, `fulfilment.changed` |
| `SHIPMENT` | `shipment.created`, `shipment.changed`, `shipment.cancelled` |
| `TRANSFER_ADVICE` | `transfer_advice.opened`, `transfer_advice.changed`, `transfer_advice.closed`, `transfer_advice.cancelled` |
| `RECEIPT_ADVICE` | `receipt_advice.opened`, `receipt_advice.changed`, `receipt_advice.closed`, `receipt_advice.cancelled` |
| `DOCUMENT` | `document.attached`, `document.version_added`, `document.removed` |
| `INVOICE` | `invoice.created`, `invoice.changed` |
| `STOCKTAKE` | `stocktake.handed_over` |

> New event types and enum values are added without notice. Ignore those you do not know.

A page costs 2 + first × the cost of one node.

## Arguments

- `first`: `Int`
- `after`: `String`
- `types`: `[String!]`
- `entityTypes`: [`[EventEntityType!]`](/chameleoon-max/type/event-entity-type)
- `wait`: `Int`

## Returns

[`EventConnection!`](/chameleoon-max/type/event-connection): a page of [`Event`](/chameleoon-max/type/event).

## Example

**Query**

```graphql
query events($first: Int) {
  events(first: $first) {
    edges {
      cursor
    }
    nodes {
      id
      type
      entityType
      entityId
      version
      occurredAt
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

**Variables**

```json
{
  "first": 10
}
```

**Response**

```json
{
  "data": {
    "events": {
      "edges": [
        {
          "cursor": "example"
        }
      ],
      "nodes": [
        {
          "id": "00000000-0000-4000-8000-000000000001",
          "type": "example",
          "entityType": "SALES_ORDER",
          "entityId": "00000000-0000-4000-8000-000000000001",
          "version": 1,
          "occurredAt": "2026-01-01T00:00:00Z"
        }
      ],
      "pageInfo": {
        "hasNextPage": true,
        "endCursor": "example"
      }
    }
  }
}
```

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