> For the complete documentation index, see [llms.txt](https://documentation.connexica.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.connexica.com/api/04.-examples.md).

# 04. Examples

Complete request examples for `api/v1`. Replace `https://cxair.example.com` with your CXAIR base URL and `cxat_<your-token>` with an active API token.

## Execute a query

```bash
curl -X POST https://cxair.example.com/api/v1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer cxat_<your-token>" \
  -H "X-Request-Id: my-request-001" \
  -d '{
    "jsonrpc": "2.0",
    "method": "QUERIES.EXECUTE",
    "params": {
      "index": "MyIndex",
      "query": "error logs",
      "page": 1,
      "pageSize": 50,
      "sort": [{"field": "timestamp", "direction": "desc"}]
    },
    "id": 1
  }'
```

## Find indexes

```bash
curl -X POST https://cxair.example.com/api/v1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer cxat_<your-token>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "INDEXES.FIND",
    "params": {"searchText": "sales"},
    "id": 2
  }'
```

Each index in the result includes `dynamicViews[]` — the distinct-count views available for crosstab totals. `"Records"` (the default record count) is always present.

## Execute a crosstab (HTML)

```bash
curl -X POST https://cxair.example.com/api/v1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer cxat_<your-token>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "CROSSTAB.EXECUTE",
    "params": {
      "index": "MyIndex",
      "query": "*",
      "rows": ["category"],
      "columns": [{"field": "year", "reverse": true}],
      "totals": [
        {"aggregationType": "Sum", "field": "Amount"},
        {"aggregationType": "Count", "dynamicView": "Customers", "name": "Unique Customers"}
      ]
    },
    "id": 3
  }'
```

`dynamicView` on a total selects a distinct-count dynamic view by name; omit it for the default `Records` count.

## Execute a crosstab (chart image)

```bash
curl -X POST https://cxair.example.com/api/v1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer cxat_<your-token>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "CROSSTAB.EXECUTE",
    "params": {
      "index": "MyIndex",
      "query": "*",
      "rows": ["category"],
      "totals": [{"aggregationType": "Sum", "field": "Amount"}],
      "chartType": "MSColumn2D",
      "width": 800,
      "height": 600
    },
    "id": 4
  }'
```

The chart PNG is returned base64-encoded in `result.data.data`; decode it to recover the raw image bytes.

## Find saved reports

```bash
curl -X POST https://cxair.example.com/api/v1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer cxat_<your-token>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "REPORTS.FIND",
    "params": {"search": "sales", "types": ["query", "crosstab"]},
    "id": 5
  }'
```

## Load a saved report's metadata

```bash
curl -X POST https://cxair.example.com/api/v1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer cxat_<your-token>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "REPORTS.METADATA",
    "params": {"guid": "saved-report-guid"},
    "id": 6
  }'
```
