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

# 過濾規則

> 使用 OData 過濾從知行之橋系統 API 檢索特定資源集。

系統 API 支援 OData 過濾以檢索特定的資源集。在目標 URL 中，OData 過濾器被設定為 `$filter` 查詢參數。以下邏輯運算子可用於構建 OData 過濾器：

| 運算子 | 描述 |
| - | - |
| **eq** | 等於 |
| **ne** | 不等於 |
| **gt** | 大於 |
| **ge** | 大於或等於 |
| **lt** | 小於 |
| **le** | 小於或等於 |
| **not** | 否定 |

例如，以下 API 請求使用 **gt** 來檢索 2019 年 8 月 26 日之後所有交易的交易日誌中繼資料：

`GET http://mydomain.com:8001/api.rsc/transactions?$filter=timestamp gt 2019-08-26`

OData 過濾器可與 **and** 和 **or** 關鍵字結合使用。例如，以下 API 請求將檢索 2019 年 8 月 26 日之後特定端口交易的所有交易日誌中繼資料：

`http://mydomain.com:8001/api.rsc/transactions?$filter=timestamp gt 2019-08-26 and connectorid eq myConnector`

系統 API 也支援 OData 過濾器中的以下函式：

* `startswith(property, 'value')`：僅傳回指定屬性以指定值開頭的資源
* `endswith(property, 'value')`：僅傳回指定屬性以指定值結尾的資源
* `contains(property, 'value')`：僅傳回指定屬性包含指定值的資源

例如，以下 API 請求用於檢索應用程式處理的所有 XML 檔案的交易日誌中繼資料：

`GET http://mydomain.com:8001/api.rsc/transactions?$filter=contains(filepath,'.xml')`

## 選擇指定欄位

除了 `$filter` 查詢參數之外，還可設定 `$select` 查詢參數來限制回應中傳回的特定欄位。此參數應設定為需要檢索的屬性的逗號分隔清單。例如，以下 API 請求用於檢索每個已配置端口的名稱和工作區，但不檢索這些端口的其他配置資訊：

`GET http://mydomain.com:8001/api.rsc/connectors?$select=connectorid,workspace`

API 還支援從單個資源中檢索單個值。例如，以下 API 請求傳回指定端口的工作區：

`http://localhost:8001/api.rsc/connectors('myConnector')/workspace/$value`

### 選擇特定端口類型的屬性

預設的 OData 回應格式只傳回端口資源結構描述中宣告的屬性（例如 `connectorid`、`workspaceid` 和 `connectortype`）。特定端口類型的屬性（例如 AS2 端口的 `as2identifier`、AS2 和 HTTP 端口的 `url`，或 SFTP 端口的 `remotehost`）未在結構描述中宣告，因此在預設格式下使用 `$select` 時會被靜默略過。

要在 `$select` 查詢中包含特定端口類型的屬性，請在請求中加入 `@json`：

`GET http://mydomain.com:8001/api.rsc/connectors?@json&$select=connectorid,as2identifier`

如果某個特定端口類型的屬性不適用於某種端口類型，則回應中該端口的資料列不會包含此屬性。這是預期行為，而不是錯誤。例如，`as2identifier` 會出現在 AS2 端口的資料列中，但不會出現在 SFTP 或 FTP 端口的資料列中。

可以在同一個 `$select` 清單中組合標準屬性和特定端口類型的屬性：

`GET http://mydomain.com:8001/api.rsc/connectors?@json&$select=connectorid,workspaceid,as2identifier`

## 排序

除了 `$filter` 和 `$select` 之外，還可設定 `$orderby` 查詢參數用於將結果按照特定順序排序。此參數用以下語法指定：

`$orderby=columnName sortDirection`

其中，**columnName** 是用於排序的列（例如 filename、connectorId、timestamp），**sortDirection** 為 *asc*（升序）或 *desc*（降序）。

例如，以下 API 請求用於檢索應用程式處理的所有 XML 檔案的交易日誌中繼資料，然後根據檔案是 **sent** 還是 **received** 對結果進行分組：

`GET http://mydomain.com:8001/api.rsc/transactions?$filter=contains(filepath,'.xml')&$orderby=status asc`

透過將 **\$orderby** 參數設定為逗號分隔清單，可指定多個排序條件。清單中靠前的條件優先於清單中靠後的條件。例如，下列 API 請求與前一個請求檢索相同的資料，但在 **sent** 或 **received** 組中，檔案按大小從大到小列出：

`GET http://mydomain.com:8001/api.rsc/transactions?$filter=contains(filepath,'.xml')&$orderby=status asc, filesize desc`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.