> ## Documentation Index
> Fetch the complete documentation index at: https://docs.legend.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Events

> Poll for real-time account events

# Get Events

Returns events for a sub-account. Supports long-polling for real-time updates — the request will hang until new events arrive or the timeout is reached.

## Request

```
GET /accounts/:account_id/events
GET /accounts/:account_id/events?since=1706900000&poll=true
```

### Path parameters

| Parameter    | Type   | Description        |
| ------------ | ------ | ------------------ |
| `account_id` | string | The sub-account ID |

### Query parameters

| Parameter | Type    | Default | Description                                                |
| --------- | ------- | ------- | ---------------------------------------------------------- |
| `since`   | integer | none    | Only return events after this cursor value                 |
| `poll`    | boolean | `false` | If `true`, long-poll until new events arrive (up to \~30s) |

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  # Get all events
  curl https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/events \
    -H "Authorization: Bearer $LEGEND_QUERY_KEY"

  # Long-poll for new events after cursor 1706900000
  curl "https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/events?since=1706900000&poll=true" \
    -H "Authorization: Bearer $LEGEND_QUERY_KEY"
  ```

  ```typescript TypeScript theme={null}
  // Get all events
  const { events, cursor } = await client.accounts.events("acc_2o0yiljtp378");

  // Long-poll for new events
  const result = await client.accounts.events("acc_2o0yiljtp378", {
    since: cursor,
    poll: true,
  });
  ```

  ```python Python theme={null}
  # Get all events
  result = await client.accounts.events("acc_2o0yiljtp378")
  cursor = result["cursor"]

  # Long-poll for new events
  result = await client.accounts.events(
      "acc_2o0yiljtp378",
      since=cursor,
      poll=True,
  )
  ```

  ```rust Rust theme={null}
  let events = client.accounts.events("acc_2o0yiljtp378", Some(0), Some(true)).await?;
  ```
</CodeGroup>

```json Response theme={null}
{
  "events": [
    {
      "event_type": "activity_updated",
      "data": {
        "activity_id": 1,
        "activity_type": "quark_operation_executed",
        "activity_status": "confirmed"
      },
      "timestamp": 1706900001
    }
  ],
  "cursor": 1706900001
}
```

### Response fields

| Field                 | Type    | Description                                        |
| --------------------- | ------- | -------------------------------------------------- |
| `events`              | array   | List of event objects                              |
| `events[].event_type` | string  | Type of event                                      |
| `events[].data`       | object  | Event-specific data                                |
| `events[].timestamp`  | integer | Unix timestamp of the event                        |
| `cursor`              | integer | Cursor value — pass as `since` in the next request |

## Long-polling pattern

For real-time monitoring, use a long-polling loop:

<CodeGroup>
  ```typescript TypeScript theme={null}
  let cursor = 0;

  while (true) {
    const { events, cursor: newCursor } = await client.accounts.events(
      "acc_2o0yiljtp378",
      { since: cursor, poll: true }
    );

    for (const event of events) {
      console.log(event.event_type, event.data);
    }

    cursor = newCursor;
  }
  ```

  ```python Python theme={null}
  cursor = 0

  while True:
      result = await client.accounts.events(
          "acc_2o0yiljtp378",
          since=cursor,
          poll=True,
      )

      for event in result["events"]:
          print(event["event_type"], event["data"])

      cursor = result["cursor"]
  ```

  ```rust Rust theme={null}
  let mut cursor = 0;

  loop {
      let result = client.accounts.events("acc_2o0yiljtp378", Some(cursor), Some(true)).await?;

      for event in &result.events {
          println!("{}: {:?}", event.event_type, event.data);
      }

      cursor = result.cursor;
  }
  ```
</CodeGroup>

## Errors

| Status | Code                | Description           |
| ------ | ------------------- | --------------------- |
| 404    | `account_not_found` | Account doesn't exist |
