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

# Solutions API

> Access and filter Live Table data programmatically using the Solutions API.

## Overview

The **Solutions API** gives you programmatic read access to your Live Tables. Use it to fetch rows, apply filters, select specific columns, sort results, and paginate through large datasets from any HTTP client or script.

The platform generates ready-to-run code examples for each of your Live Tables with all IDs pre-filled. Find them in the API docs panel on your database page.

## Authentication

Include your API token in the `Authorization` header of every request:

```
Authorization: Token <YOUR_TOKEN>
```

A missing or invalid token returns `403 Forbidden`.

## Endpoint

### GET /api/database-tables/\{table\_id}/data

Fetch rows from a Live Table. The `table_id` is unique to each table and is pre-filled in the code examples on your database page.

#### Query Parameters

| Parameter  | Type    | Required | Description                                             |
| ---------- | ------- | -------- | ------------------------------------------------------- |
| `offset`   | integer | No       | Number of rows to skip. Default: `0`                    |
| `limit`    | integer | No       | Maximum rows to return. Default: `20`                   |
| `select`   | string  | No       | Comma-separated column names to include in the response |
| `order_by` | string  | No       | Comma-separated column names to sort by                 |
| `q`        | string  | No       | TQL filter expression                                   |

#### Response

```json theme={null}
{
  "total_count": 1500,
  "result_count": 20,
  "offset": 0,
  "limit": 20,
  "results": [
    { "url": "https://example.com", "status_code": 200, "webserver": "nginx" }
  ]
}
```

| Field          | Type    | Description                             |
| -------------- | ------- | --------------------------------------- |
| `total_count`  | integer | Total number of rows matching the query |
| `result_count` | integer | Number of rows returned in this page    |
| `offset`       | integer | Offset used for this page               |
| `limit`        | integer | Limit used for this page                |
| `results`      | array   | Array of row objects                    |

#### Status Codes

| Code  | Meaning                                |
| ----- | -------------------------------------- |
| `200` | Success                                |
| `400` | Invalid query parameters               |
| `403` | Missing or invalid authorization token |

## Examples

### Fetch Rows

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    const response = await fetch(
      "/api/database-tables/{table_id}/data?offset=0&limit=20",
      {
        headers: {
          "Authorization": "Token <YOUR_TOKEN>",
          "Content-Type": "application/json",
        },
      }
    );

    const data = await response.json();
    console.log("Results:", data.results);
    console.log("Total count:", data.total_count);
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    response = requests.get(
        "/api/database-tables/{table_id}/data",
        params={"offset": 0, "limit": 20},
        headers={"Authorization": "Token <YOUR_TOKEN>"},
    )

    data = response.json()
    print("Results:", data["results"])
    print("Total count:", data["total_count"])
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -G "https://trickest.io/api/database-tables/{table_id}/data" \
      -H "Authorization: Token <YOUR_TOKEN>" \
      -d "offset=0" \
      -d "limit=20"
    ```
  </Tab>
</Tabs>

### Select Specific Columns

Use `select` to limit which fields are returned. This reduces response size for tables with many columns.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    const params = new URLSearchParams({
      select: "url,status_code,webserver",
      offset: "0",
      limit: "20",
    });

    const response = await fetch(
      `/api/database-tables/{table_id}/data?${params}`,
      {
        headers: {
          "Authorization": "Token <YOUR_TOKEN>",
          "Content-Type": "application/json",
        },
      }
    );

    const data = await response.json();
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    params = {
        "select": "url,status_code,webserver",
        "offset": 0,
        "limit": 20,
    }

    response = requests.get(
        "/api/database-tables/{table_id}/data",
        params=params,
        headers={"Authorization": "Token <YOUR_TOKEN>"},
    )

    data = response.json()
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -G "https://trickest.io/api/database-tables/{table_id}/data" \
      -H "Authorization: Token <YOUR_TOKEN>" \
      -d "select=url,status_code,webserver" \
      -d "offset=0" \
      -d "limit=20"
    ```
  </Tab>
</Tabs>

### Filter with TQL

Use the `q` parameter to pass a TQL filter expression.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    const params = new URLSearchParams({
      q: 'status_code = 200 AND webserver ~ "nginx"',
      offset: "0",
      limit: "20",
    });

    const response = await fetch(
      `/api/database-tables/{table_id}/data?${params}`,
      {
        headers: {
          "Authorization": "Token <YOUR_TOKEN>",
          "Content-Type": "application/json",
        },
      }
    );

    const data = await response.json();
    console.log("Filtered results:", data.results);
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    params = {
        "q": 'status_code = 200 AND webserver ~ "nginx"',
        "offset": 0,
        "limit": 20,
    }

    response = requests.get(
        "/api/database-tables/{table_id}/data",
        params=params,
        headers={"Authorization": "Token <YOUR_TOKEN>"},
    )

    data = response.json()
    print("Filtered results:", data["results"])
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -G "https://trickest.io/api/database-tables/{table_id}/data" \
      -H "Authorization: Token <YOUR_TOKEN>" \
      --data-urlencode 'q=status_code = 200 AND webserver ~ "nginx"' \
      -d "offset=0" \
      -d "limit=20"
    ```
  </Tab>
</Tabs>

<Note>
  Quote strings and dates in TQL expressions. Leave numbers unquoted. See [Querying](/docs/using-the-app/database-management/querying) for the full TQL syntax reference.
</Note>

### Paginate Through All Results

Use `offset` and `limit` together to iterate through large result sets. Stop when an empty `results` array is returned.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    async function fetchAll(tableId, limit = 100) {
      const allResults = [];
      let offset = 0;

      while (true) {
        const params = new URLSearchParams({
          offset: String(offset),
          limit: String(limit),
        });

        const response = await fetch(
          `/api/database-tables/${tableId}/data?${params}`,
          {
            headers: {
              "Authorization": "Token <YOUR_TOKEN>",
              "Content-Type": "application/json",
            },
          }
        );

        const data = await response.json();
        const rows = data.results || [];

        if (rows.length === 0) break;

        allResults.push(...rows);
        offset += limit;
      }

      return allResults;
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    def fetch_all(table_id, limit=100):
        all_results = []
        offset = 0

        while True:
            response = requests.get(
                f"/api/database-tables/{table_id}/data",
                params={"offset": offset, "limit": limit},
                headers={"Authorization": "Token <YOUR_TOKEN>"},
            )
            data = response.json()
            rows = data.get("results", [])

            if not rows:
                break

            all_results.extend(rows)
            offset += limit

        return all_results
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    # Fetch the first page
    curl -G "https://trickest.io/api/database-tables/{table_id}/data" \
      -H "Authorization: Token <YOUR_TOKEN>" \
      -d "offset=0" \
      -d "limit=100"

    # Fetch the next page by incrementing offset
    curl -G "https://trickest.io/api/database-tables/{table_id}/data" \
      -H "Authorization: Token <YOUR_TOKEN>" \
      -d "offset=100" \
      -d "limit=100"
    ```
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={2}>
  <Card title="Solutions & Database" icon="gem" href="/docs/key-concepts/solutions-database">
    How Solutions and Live Tables work on the platform.
  </Card>

  <Card title="Querying" icon="magnifying-glass" href="/docs/using-the-app/database-management/querying">
    Write and run TQL filters against your Live Tables in the UI.
  </Card>
</CardGroup>
