Inventory API 允許你使用 POST 請求,並在請求主體中指定查詢,對 Azure Resource Graph 執行結構化查詢。 API 會將您的查詢規格轉譯成 Kusto 查詢語言 (KQL), 以針對 Azure Resource Graph 執行。 資源的庫存 API 是 Power Platform API 參考文件的一部分。 欲了解完整的資源類型與可查詢欄位,請參閱 Power Platform 庫存結構參考。
API 端點
POST {PowerPlatformAPI url}/resourcequery/resources/query?api-version=2024-10-01
要求本文
要求內文必須包含符合下列結構的查詢規範:
查詢要求結構
{
"TableName": "string",
"Clauses": [
{
"$type": "clause_type",
// clause-specific properties
}
],
"Options": {
"Top": 100,
"Skip": 0,
"SkipToken": "string"
}
}
屬性
| 房產 | 類型 | Required | Description |
|---|---|---|---|
TableName |
字串 | Yes | 要查詢的目標資料表/資源類型 (亦即 “PowerPlatformResources”) |
Clauses |
陣列 | Yes | 定義要執行之作業的查詢子句陣列 |
Options |
物件 | No | Azure Resource Graph 分頁與結果控制的查詢選項 |
查詢選項
物件 Options 支援分頁和結果控制的 Azure Resource Graph 查詢參數。 請參閱 ResourceQueryRequestOptions 文件 以進一步了解。
支援的查詢子句
API 透過多態 JSON 序列化支援本節中指定的句型類型。 每個子句類型都會對應至 KQL 運算子,如 KQL 參考 中所記載:
Where 子句
根據欄位條件篩選資料。 轉譯為 KQL where 運算子。
{
"$type": "where",
"FieldName": "string",
"Operator": "string",
"Values": ["string1", "string2"]
}
支援的運算子: API 支援所有標準 KQL 比較和字串運算子。 如需可用運算子的完整清單,請參閱 KQL 字串運算子 和 數值運算子 檔。
Example:
{
"$type": "where",
"FieldName": "type",
"Operator": "in~",
"Values": ["'microsoft.powerapps/canvasapps'", "'microsoft.copilotstudio/agents'"]
}
轉換為 KQL:| where type in~ ('microsoft.powerapps/canvasapps', 'microsoft.copilotstudio/agents')
專案條款
從結果中選取特定欄位。 轉譯為 KQL project 運算子。
{
"$type": "project",
"FieldList": ["field1", "field2", "field3"]
}
Example:
{
"$type": "project",
"FieldList": [
"name",
"properties.displayName",
"environmentId = tostring(properties.environmentId)",
"createdDate = properties.createdAt"
]
}
轉換為 KQL:| project name, properties.displayName, environmentId = tostring(properties.environmentId), createdDate = properties.createdAt
Take 子句
限制傳回的結果數目。 轉譯為 KQL take 運算子。
{
"$type": "take",
"TakeCount": 50
}
轉換為 KQL:| take 50
按條款排序
依指定欄位排序結果。 轉譯為 KQL sort 運算子。
{
"$type": "orderby",
"FieldNamesAscDesc": {
"field1": "asc",
"field2": "desc"
}
}
Example:
{
"$type": "orderby",
"FieldNamesAscDesc": {
"tostring(properties.createdAt)": "desc",
"properties.displayName": "asc"
}
}
轉換為 KQL:| sort by tostring(properties.createdAt) desc, properties.displayName asc
Distinct 子句
傳回指定欄位的唯一值。 轉譯為 KQL distinct 運算子。
{
"$type": "distinct",
"FieldList": ["field1", "field2"]
}
轉換為 KQL:| distinct field1, field2
計數條款
返回匹配記錄的數量。 轉譯為 KQL count 運算子。
{
"$type": "count"
}
轉換為 KQL:| count
摘要條款
使用 count 或 argmax 運算彙總資料。 轉譯為 KQL summarize 運算子。
{
"$type": "summarize",
"SummarizeClauseExpression": {
"OperatorName": "count|argmax",
"OperatorFieldName": "string",
"FieldList": ["field1", "field2"]
}
}
支援的運算子:
計數範例:
{
"$type": "summarize",
"SummarizeClauseExpression": {
"OperatorName": "count",
"OperatorFieldName": "resourceCount",
"FieldList": ["resourceGroup", "type"]
}
}
轉換為 KQL:| summarize resourceCount = count() by resourceGroup, type
ArgMax 範例:
{
"$type": "summarize",
"SummarizeClauseExpression": {
"OperatorName": "argmax",
"OperatorFieldName": "createdTime",
"FieldList": ["resourceGroup"]
}
}
轉換為 KQL:| summarize arg_max(createdTime, *) by resourceGroup
延展條款
將計算資料行新增至結果。 轉譯為 KQL extend 運算子。
{
"$type": "extend",
"FieldName": "newFieldName",
"Expression": "KQL_EXPRESSION"
}
Example:
{
"$type": "extend",
"FieldName": "environmentId",
"Expression": "tostring(properties.environmentId)"
}
轉換為 KQL:| extend environmentId = tostring(properties.environmentId)https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalarfunctions) 以取得可用功能。
Join 子句
與另一個表或子查詢進行聯結。 轉譯為 KQL join 運算子。
{
"$type": "join",
"RightTable": {
"TableName": "string",
"Clauses": []
},
"JoinKind": "string",
"LeftColumnName": "string",
"RightColumnName": "string"
}
支援的聯結種類: API 支援所有 KQL 聯結種類。 如需可用聯結類型及其行為的完整清單,請參閱 KQL 聯結運算子檔。
範例 (將 Power Platform 資源與環境資訊聯結):
{
"$type": "join",
"JoinKind": "leftouter",
"RightTable": {
"TableName": "PowerPlatformResources",
"Clauses": [
{
"$type": "where",
"FieldName": "type",
"Operator": "==",
"Values": ["'microsoft.powerplatform/environments'"]
},
{
"$type": "project",
"FieldList": [
"environmentId = name",
"environmentName = properties.displayName",
"environmentRegion = location",
"environmentType = properties.environmentType",
"isManagedEnvironment = properties.isManaged"
]
}
]
},
"LeftColumnName": "environmentId",
"RightColumnName": "environmentId"
}
轉換為 KQL:| join kind=leftouter (PowerPlatformResources | where type == 'microsoft.powerplatform/environments' | project environmentId = name, environmentName = properties.displayName, environmentRegion = location, environmentType = properties.environmentType, isManagedEnvironment = properties.isManaged) on $left.environmentId == $right.environmentId
完整的查詢範例
範例:基本 Power Platform 資源查詢(Power Platform 管理中心預設模式)
取得所有帶有環境資訊的 Power Platform 資源——這是 Power Platform 管理中心的預設查詢。
{
"Options": {
"Top": 1000,
"Skip": 0,
"SkipToken": ""
},
"TableName": "PowerPlatformResources",
"Clauses": [
{
"$type": "extend",
"FieldName": "joinKey",
"Expression": "tolower(tostring(properties.environmentId))"
},
{
"$type": "join",
"JoinKind": "leftouter",
"RightTable": {
"TableName": "PowerPlatformResources",
"Clauses": [
{
"$type": "where",
"FieldName": "type",
"Operator": "==",
"Values": ["'microsoft.powerplatform/environments'"]
},
{
"$type": "project",
"FieldList": [
"joinKey = tolower(name)",
"environmentName = properties.displayName",
"environmentRegion = location",
"environmentType = properties.environmentType",
"isManagedEnvironment = properties.isManaged"
]
}
]
},
"LeftColumnName": "joinKey",
"RightColumnName": "joinKey"
},
{
"$type": "where",
"FieldName": "type",
"Operator": "in~",
"Values": [
"'microsoft.powerapps/canvasapps'",
"'microsoft.powerapps/modeldrivenapps'",
"'microsoft.powerautomate/cloudflows'",
"'microsoft.copilotstudio/agents'",
"'microsoft.powerautomate/agentflows'",
"'microsoft.powerapps/codeapps'"
]
},
{
"$type": "orderby",
"FieldNamesAscDesc": {
"tostring(properties.createdAt)": "desc"
}
}
]
}
對等的 KQL:
PowerPlatformResources
| extend joinKey = tolower(tostring(properties.environmentId))
| join kind=leftouter (
PowerPlatformResources
| where type == 'microsoft.powerplatform/environments'
| project joinKey = tolower(name), environmentName = properties.displayName, environmentRegion = location, environmentType = properties.environmentType, isManagedEnvironment = properties.isManaged
) on $left.joinKey == $right.joinKey
| where type in~ ('microsoft.powerapps/canvasapps', 'microsoft.powerapps/modeldrivenapps', 'microsoft.powerautomate/cloudflows', 'microsoft.copilotstudio/agents', 'microsoft.powerautomate/agentflows', 'microsoft.powerapps/codeapps')
| order by tostring(properties.createdAt) desc
範例:依類型與地點統計 Power Platform 資源
{
"TableName": "PowerPlatformResources",
"Clauses": [
{
"$type": "summarize",
"SummarizeClauseExpression": {
"OperatorName": "count",
"OperatorFieldName": "resourceCount",
"FieldList": ["type", "location"]
}
},
{
"$type": "orderby",
"FieldNamesAscDesc": {
"resourceCount": "desc"
}
}
]
}
對等的 KQL:
PowerPlatformResources
| summarize resourceCount = count() by type, location
| sort by resourceCount desc
範例:簡單 Canvas 應用程式查詢
取得具有基礎篩選和投影功能的畫布應用程式:
{
"TableName": "PowerPlatformResources",
"Clauses": [
{
"$type": "where",
"FieldName": "type",
"Operator": "==",
"Values": ["'microsoft.powerapps/canvasapps'"]
},
{
"$type": "project",
"FieldList": [
"name",
"location",
"properties.displayName",
"properties.createdAt",
"properties.environmentId"
]
},
{
"$type": "take",
"TakeCount": 100
}
]
}
對等的 KQL:
PowerPlatformResources
| where type == 'microsoft.powerapps/canvasapps'
| project name, location, properties.displayName, properties.createdAt, properties.environmentId
| take 100
範例:依環境與日期範圍篩選資源
{
"TableName": "PowerPlatformResources",
"Clauses": [
{
"$type": "where",
"FieldName": "type",
"Operator": "==",
"Values": ["'microsoft.powerapps/canvasapps'"]
},
{
"$type": "where",
"FieldName": "properties.environmentId",
"Operator": "==",
"Values": ["your-environment-id"]
},
{
"$type": "extend",
"FieldName": "createdDate",
"Expression": "todatetime(properties.createdAt)"
},
{
"$type": "where",
"FieldName": "createdDate",
"Operator": ">=",
"Values": ["datetime(2024-01-01)"]
},
{
"$type": "project",
"FieldList": [
"name",
"properties.displayName",
"properties.createdAt",
"properties.createdBy",
"properties.ownerId"
]
},
{
"$type": "orderby",
"FieldNamesAscDesc": {
"createdDate": "desc"
}
}
]
}
轉換為 KQL:
PowerPlatformResources
| where type == 'microsoft.powerapps/canvasapps'
| where properties.environmentId == "your-environment-id"
| extend createdDate = todatetime(properties.createdAt)
| where createdDate >= datetime(2024-01-01)
| project name, properties.displayName, properties.createdAt, properties.createdBy, properties.ownerId
| sort by createdDate desc
回應格式
API 會從 Azure Resource Graph SDK 傳回 ResourceQueryResult 物件。 此物件包含查詢結果和查詢執行的相關中繼資料。
回應結構:
{
"totalRecords": 1250,
"count": 50,
"resultTruncated": 1,
"skipToken": "string_for_next_page",
"data": [
// Array of result objects based on your query
]
}