Windchill Navigate API > 使用 API > 检索数据 > 定义 API 的结果集
定义 API 的结果集
许多 API 都支持您定义希望在结果集中返回的属性。请参阅搜索中的“属性输入”部分。本主题介绍如何填充这些 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"
}
这对您有帮助吗?