# Query semantic entries

Lists business definition entries in the knowledge base in pages.

```text
GET https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/entries
```

## Preparation before calling

First [query the knowledge base list](list-knowledge-bases.md) to obtain the knowledge base ID. Prepare a personal access token and target workspace ID that has access to the target workspace.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through `X-Workspace-ID` Header.
- `$MODEL_ID`: ID of the knowledge base to be queried.

## Request example

```bash
curl "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/entries?kind=metric&page_size=20" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

## Path parameters

| Parameters | Type | Description |
| --- | --- | --- |
| `model_id` | integer | Knowledge base ID. |

## Query parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `kind` | string | No | Entry type filter criteria; available values and their configuration fields can be found in [Create Semantic Entry](create-semantic-entry.md). |
| `page_size` | integer | No | The number of items in a single page, ranging from `1` to `100`; when not transmitted, it is `20`. |
| `page_token` | string | No | `next_page_token` from the previous page response. |

## Successful response

Returns `200` on success. Save `data.items[].id` and use it for subsequent update and deletion interfaces.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "items": [
      {
        "id": 501,
        "kind": "metric",
        "key": "total_rows",
        "tables": ["orders"],
        "spec": {
          "expr": "COUNT(*)"
        },
        "created_at": 1735632000,
        "updated_at": 1735632000
      }
    ],
    "total": 1,
    "next_page_token": ""
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.items` | object[] | The semantic entry of the current page. |
| `data.items[].id` | integer | Entry ID. |
| `data.items[].kind` | string | Entry type. |
| `data.items[].key` | string | Stable reference key within the knowledge base. |
| `data.items[].tables` | array[string] | Association table name; may be omitted if not set. |
| `data.items[].spec` | object | Type-specific configuration object corresponding to `data.items[].kind`; see [Create semantic entry](create-semantic-entry.md#spec-configuration) for fields. |
| `data.items[].created_at` | integer | Creation time as a Unix timestamp. |
| `data.items[].updated_at` | integer | Update time as a Unix timestamp. |
| `data.total` | integer | The total number of entries matching the filter criteria. |
| `data.next_page_token` | string | Next page token; if empty, there is no next page. |

In field paths, `[]` means each item in an array. For example, `data.items[].id` is the `id` field of each item in `data.items`.

## Read next page

When `data.next_page_token` in the response is not empty, it is passed to the next page request as `page_token`; when it is empty, it means that the last page has been read.

## Error response

```json
{
  "code": "ErrParamInvalid",
  "msg": "page_size is invalid",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - `model_id`, `kind` or `page_size` are not valid.
  - Correct the parameters and try again.
* - `401`
  - `ErrUnauthorized`
  - The API Key is invalid or has expired.
  - Check API Key.
* - `403`
  - `ErrForbidden`
  - The caller does not have read permission.
  - Check workspace and object authorization.
* - `404`
  - `ErrNotFound`
  - The knowledge base does not exist or is not visible.
  - Reconfirm `model_id`.
* - `500`
  - `ErrServer`
  - The service failed to read the entry.
  - Keep the desensitized response information and try again.
```

## Follow-up operations

When you need to add a new one, [Create semantic entries](create-semantic-entry.md); after selecting an existing entry, you can [Update semantic entries](update-semantic-entry.md) or [Delete semantic entries](delete-semantic-entry.md).
