Power Platform 인벤토리 API

인벤토리 API를 사용하면 요청 본문의 쿼리 사양이 있는 POST 요청을 사용하여 Azure Resource Graph에 대해 구조화된 쿼리를 실행할 수 있습니다. API는 Azure Resource Graph에 대해 실행하기 위해 쿼리 사양을 KQL(Kusto Query Language) 으로 변환합니다. 리소스용 인벤토리 API는 Power Platform API 참조 설명서의 일부입니다. 리소스 종류 및 쿼리 가능한 필드의 전체 목록은 Power Platform 인벤토리 스키마 참조를 참조하세요.

Authentication

인벤토리 API는 현재 위임된 사용자 인증만 지원합니다. API를 호출하기 전에 로그인한 사용자에 대한 전달자 토큰을 가져옵니다.

Important

API는 서비스 주체 또는 관리 ID를 통한 앱 전용 인증을 지원하지 않습니다. 이러한 ID를 사용하는 요청은 HTTP 403 사용할 수 없음을 반환합니다.

토큰 설정 지침은 인증 을 참조하고 위임된 사용자 흐름을 사용합니다. 해당 문서에 설명된 서비스 주체 흐름은 인벤토리 API에 적용되지 않습니다.

Power Platform CLI 사용(미리 보기)

미리 보기 pac resource-query query-resources 명령을 사용하여 터미널에서 인벤토리 리소스 쿼리를 실행할 수 있습니다. 이 명령은 직접 또는 파일에서 JSON 쿼리 요청 본문을 수락합니다.

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

속성

속성 Type 필수 Description
TableName 문자열 Yes 쿼리할 대상 테이블/리소스 유형(예: "PowerPlatformResources")
Clauses 배열 Yes 수행할 작업을 정의하는 쿼리 절 배열
Options object No Azure Resource Graph의 페이지네이션 및 결과 제어를 위한 쿼리 옵션

쿼리 옵션

Options 개체는 페이지 매김 및 결과 컨트롤에 대한 Azure Resource Graph 쿼리 매개 변수를 지원합니다. 자세한 내용은 설명서를 참조ResourceQueryRequestOptions하세요.

지원되는 쿼리 절

API는 다형 JSON serialization을 통해 이 섹션에서 강조 표시된 절 형식을 지원합니다. 각 절 형식은 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

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

요약 조항

count 또는 argmax 작업을 사용하여 데이터를 집계합니다. KQL summarize 연산자로 변환합니다.

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

지원되는 연산자:

  • count count() → - 지정된 필드별로 그룹화된 레코드 개수입니다.
  • argmax arg_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'",
        "'microsoft.powerapps/apps'"
      ]
    },
    {
      "$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', 'microsoft.powerapps/apps')
| 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
  ]
}