Windchill Navigate API > 使用 API > 擷取資料 > 定義 API 的結果集
定義 API 的結果集
我們的許多 API 都支援定義您要在結果集中傳回的屬性。請參閱Search中的「屬性輸入」部份。此主題描述如何填入這些 API 的輸入。
您可以配置 API 服務的輸入,使其傳回所需資料。所有「資料擷取」API 服務的輸入參數都包括名為 "attributes" 的內容。此內容至少包含一個 "object type",例如 "PTC.ProdMgmt.Part"。"object type" 值以名稱陣列表示,對應於服務將從 Windchill 中擷取的欄位。
Search 服務上,以下是 "inputs":
{
"inputs": {
"filter": "(contains(Name, 'wagon'))"
},
"attributes": {
"PTC.ProdMgmt.Part": [
"Number",
"Version",
"ID",
"Name",
"State#Display"
]
},
"version": "1"
}
在此,輸入指定了 Search 服務將傳回下列 5 個欄位:"Number"、"Version"、"ID"、"Name" 與 "State#Display",如下所示:
{
"timeStamp": "2025-03-04 14:16:00.291",
"data": [
{
"Item ListsData": [
{
"metadata": {
"Number": {
"label": "Number",
"type": "STRING"
},
"Version": {
"label": "Version",
"type": "STRING"
},
"ID": {
"label": "ID",
"type": "STRING"
},
"Name": {
"label": "Name",
"type": "STRING"
},
"State#Display": {
"refType": "PTC.EnumType",
"label": "State",
"type": "STRING"
}
},
"items": [
{
"Number": {
"value": "0000000022.ASM"
},
"Version": {
"value": "A.6 (Design)"
},
"ID": {
"value": "OR:wt.part.WTPart:988412"
},
"Name": {
"value": "Wagon Example"
},
"State#Display": {
"value": "Released"
}
},
{
"Number": {
"value": "A0000000307"
},
"Version": {
"value": "A.2 (Design)"
},
"ID": {
"value": "OR:wt.part.WTPart:399199"
},
"Name": {
"value": "Wagon Example (DEVQA)"
},
"State#Display": {
"value": "In Work"
}
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.VOps.WCOperationAdapter"
}
}
],
"statusMessage": "OK",
"status": "200"
}
在這裡,"items" 陣列包含 2 個元素,每個元素有 5 個欄位作為指定的 "inputs"。如果我們再新增一個欄位到 "inputs",Search 服務將會傳回 6 個欄位。
在下面的範例中,讓我們將新欄位 "ModifiedBy" 新增至 "inputs"。
{
"inputs": {
"filter": "(contains(Name, 'wagon'))"
},
"attributes": {
"PTC.ProdMgmt.Part": [
"Number",
"Version",
"ID",
"Name",
"State#Display",
"ModifiedBy"
]
},
"version": "1"
}
Search 的結果如下:
{
"timeStamp": "2025-03-04 14:22:52.698",
"data": [
{
"Item ListsData": [
{
"metadata": {
"Number": {
"label": "Number",
"type": "STRING"
},
"Version": {
"label": "Version",
"type": "STRING"
},
"ID": {
"label": "ID",
"type": "STRING"
},
"ModifiedBy": {
"label": "Modified By",
"type": "STRING"
},
"Name": {
"label": "Name",
"type": "STRING"
},
"State#Display": {
"refType": "PTC.EnumType",
"label": "State",
"type": "STRING"
}
},
"items": [
{
"Number": {
"value": "0000000022.ASM"
},
"Version": {
"value": "A.6 (Design)"
},
"ID": {
"value": "OR:wt.part.WTPart:988412"
},
"ModifiedBy": {
"value": "Site, Administrator"
},
"Name": {
"value": "Wagon Example"
},
"State#Display": {
"value": "Released"
}
},
{
"Number": {
"value": "A0000000307"
},
"Version": {
"value": "A.2 (Design)"
},
"ID": {
"value": "OR:wt.part.WTPart:399199"
},
"ModifiedBy": {
"value": "Site, Administrator"
},
"Name": {
"value": "Wagon Example (DEVQA)"
},
"State#Display": {
"value": "In Work"
}
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.VOps.WCOperationAdapter"
}
}
],
"statusMessage": "OK",
"status": "200"
}
這是否有幫助?