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

# 搜尋會話

> 透過會話資料中的內容匹配來搜尋會話，包括變數和訊息。

<Warning>
  **已棄用。** 此端點已棄用，將於 **2026-07-11 下架**。在此之前仍可使用。請改用 V1 路徑--完整的新舊路徑對照見[遷移指南](/zh-Hant/migrations/2026-06-outbound-api-v1)。
</Warning>

在所有會話中搜尋，根據會話資料中的字串內容尋找匹配項目。

## 基礎 URL

```
https://api.pathors.com
```

## 搜尋會話

```bash theme={null}
POST /project/{projectId}/session/search
```

### 路徑參數

<ParamField path="projectId" type="string" required>
  您的專案 ID
</ParamField>

### 請求標頭

<ParamField header="Authorization" type="string" required>
  使用您的 Project API Key（以 `sk_` 開頭）進行 Bearer 令牌認證。格式：`Bearer {your-api-key}`
</ParamField>

### 請求主體

<ParamField body="search_string" type="string" required>
  要在會話資料中搜尋的字串。這將匹配所有會話內容，包括變數、訊息和其他儲存的資訊。
</ParamField>

<ParamField body="limit" type="number">
  要返回的最大結果數。預設值：50
</ParamField>

<ParamField body="offset" type="number">
  分頁時要跳過的結果數。預設值：0
</ParamField>

### 回應

<ResponseField name="results" type="array">
  匹配的會話陣列，按最近更新時間排序

  <Expandable title="會話物件">
    <ResponseField name="sessionId" type="string">
      會話 ID
    </ResponseField>

    <ResponseField name="data" type="object">
      包含變數、訊息和其他會話資訊的會話資料
    </ResponseField>

    <ResponseField name="createdAt" type="string">
      會話建立時的 ISO 8601 時間戳記
    </ResponseField>

    <ResponseField name="updatedAt" type="string">
      會話最後更新時的 ISO 8601 時間戳記
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="pagination" type="object">
  分頁資訊

  <Expandable title="分頁物件">
    <ResponseField name="limit" type="number">
      此請求使用的限制數量
    </ResponseField>

    <ResponseField name="offset" type="number">
      此請求使用的偏移量
    </ResponseField>

    <ResponseField name="total" type="number">
      匹配會話的總數
    </ResponseField>
  </Expandable>
</ResponseField>

## 範例

### 請求

```bash theme={null}
curl -X POST https://api.pathors.com/project/{projectId}/session/search \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "search_string": "王小明",
    "limit": 10,
    "offset": 0
  }'
```

### 回應

```json theme={null}
{
  "results": [
    {
      "sessionId": "user-123-session-456",
      "data": {
        "variables": {
          "userName": "王小明",
          "userRole": "admin"
        },
        "messages": [
          {
            "role": "user",
            "content": "你好"
          },
          {
            "role": "assistant",
            "content": "您好，王小明！有什麼可以幫助您的嗎?"
          }
        ]
      },
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:35:00.000Z"
    },
    {
      "sessionId": "user-456-session-789",
      "data": {
        "variables": {
          "userName": "王小明",
          "userRole": "user"
        },
        "messages": []
      },
      "createdAt": "2024-01-14T15:20:00.000Z",
      "updatedAt": "2024-01-14T15:25:00.000Z"
    }
  ],
  "pagination": {
    "limit": 10,
    "offset": 0,
    "total": 2
  }
}
```

## 使用說明

* **搜尋字串**: 搜尋區分大小寫，並匹配會話資料的整個 JSON 內容
* **排序**: 結果按 `updatedAt` 降冪排序（最新的在前）
* **分頁**: 使用 `limit` 和 `offset` 來分頁瀏覽大量結果集
* **效能**: 對於大型資料集，建議使用更具體的搜尋字串以提高查詢效能

## 錯誤回應

| 狀態碼 | 描述                    |
| --- | --------------------- |
| 400 | 缺少或無效的 search\_string |
| 401 | 無效的認證                 |
| 500 | 內部伺服器錯誤               |

錯誤回應範例：

**400 請求錯誤:**

```json theme={null}
{
  "error": "search_string is required"
}
```

**401 身份驗證失敗:**

```json theme={null}
{
  "error": {
    "message": "Invalid authentication"
  }
}
```

## 相關 API

* [建立會話](/api-reference/session/create-session) - 建立新會話
* [查詢會話](/api-reference/session/query-session) - 依 ID 取得特定會話
* [結束會話](/api-reference/session/end-session) - 結束現有會話
