通过


Power Platform 清单 API

通过清单 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"
  }
}

属性

资产 类型 必选 Description
TableName 字符串 是的 要查询的目标表/资源类型(即“PowerPlatformResources”)
Clauses 数组 是的 定义要执行操作的查询子句数组
Options 对象 Azure Resource Graph查询选项用于分页和结果控制

查询选项

Options 对象支持Azure Resource Graph查询参数实现分页和结果控制。 有关详细信息,请参阅 ResourceQueryRequestOptions 文档

支持的查询子句

该 API 通过多态 JSON 序列化支持本节强调的子句类型: 每个子句类型对应于 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')

Project 子句

从结果中选择特定字段。 转换为 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

Order by 子句

按指定字段对结果进行排序。 转换为 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

Count 子句

返回匹配记录的计数。 转换为 KQL count 运算符

{
  "$type": "count"
}

转换为 KQL:| count

Summarize 子句

使用计数或 argmax 操作来聚合数据。 转换为 KQL summarize 运算符

{
  "$type": "summarize",
  "SummarizeClauseExpression": {
    "OperatorName": "count|argmax",
    "OperatorFieldName": "string",
    "FieldList": ["field1", "field2"]
  }
}

支持的运算符:

  • count count() → - 对按指定字段分组的记录进行计数。
  • argmaxarg_max() - 获取指定字段中具有最大值的记录。

计数示例:

{
  "$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

Extend 子句

将计算列添加到结果。 转换为 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

示例:简单画布应用查询

获取带基本筛选和投影的画布应用:

{
  "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
  ]
}