[この記事はプレリリース ドキュメントであり、変更されることがあります。]
Power Platform API を使用して、さまざまな詳細やメタデータをMicrosoft Power Platform 環境から Microsoft Dataverse データベースを使用する、しないにかかわらず抽出できます。 API は、PowerShell などの現在利用可能なさまざまなクライアントが内部で使用しています。
このチュートリアルで学習する内容は次のとおりです。
- Power Platform API で認証する Power Automate または Logic Apps ワークフロー (Azure) または PowerShell スクリプトを作成します。
- 環境を一覧表示するエンドポイントを呼び出して、Microsoft Power Platform 環境の詳細を取得します。
- 容量オブジェクトを反復処理して、実際の消費量を取得します。
- 消費データをテーブルに保存して表示します。
このシナリオの例として、顧客は、部門ごとのテナントの総容量の割り当てをよりよく理解できるように、容量の消費量を把握しようとしています。 これにより、顧客は、各部門が利用可能な総容量をどれだけ消費しているかに基づいて、内部コスト計算機能やチャージバックを実行できるようになります。 この顧客は、環境の説明を使用して、各環境を所有する部署を呼び出しています。
重要
Power Platform API はプレビュー段階です。 ホスト名とデータ コントラクトは、エンドポイントが一般に使用可能になるまでに変更される可能性があります。
接続と変数の設定
プログラムで Power Platform に接続するには、次の詳細を使用します。 AzureエクスペリエンスまたはPowerShellスクリプトを選択できます。
ワークフローを作成し、変数を設定する
まず、このチュートリアルではLogic Appsワークフローを使用します。 Power Automate フローと、会社が自動化に使用することを好む他のオーケストレーション エンジンも受け入れられます。 データを取得するためのすべての呼び出しはRESTful APIを使用するため、RESTをサポートするツールはすべてこのチュートリアルで使用できます。
Azure ポータルにアクセスし、新しいロジック アプリを作成して、名前を付けます。
プロビジョニングが完了したら、デザイナーを使用してワークフローを編集し、毎日実行するように繰り返しトリガーを設定します。
次に、5つの変数を初期化する必要があります。
- SPN-Id – これはサービス プリンシパルのClientIDです。 これは、後でサービス プリンシパル コンテキストで認証を実行するために使用されます。 ユーザー名/パスワード コンテキストを使用している場合は、この変数をスキップできます。
- DBCapacity – これは、消費されたデータベース容量 (メガバイト単位) を表すFloat変数です。
- FileCapacity – これは、消費されたファイル容量 (メガバイト単位) を表すFloat変数です。
- LogCapacity – これは消費されたログ容量(メガバイト単位)を表すFloat変数です。
- SimplifiedEnvironmentArray-Init – これは、いくつかの 環境 プロパティを入力する配列変数です。 これにより、最終的な HTML テーブル レポートの出力が大幅に簡素化されます。
次に、 Microsoft Entra 認証して、 Power Platform APIを呼び出すためのトークンを取得します。 Microsoft Entra セットアップをまだ完了していない場合、認証 - レガシーを参照してください。
このチュートリアルでは、Key Vault を使用してサービス プリンシパル シークレット値を保存しています。 このようにして IT 管理者は、この値をワークフローで安全に使用できるようにすることができます。 次に、トークンを取得するために、POST呼び出しでこれが入力されます。 Microsoft Entra
次に、Microsoft Entra 'Parse JSON' アクションでこの JSON スキーマを使用して、型指定されたオブジェクトへのトークン応答を解析します。
{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "integer"
},
"ext_expires_in": {
"type": "integer"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}
環境のフェッチ
このセクションでは、管理している 環境 リストを取得します。 これは、API と PowerShell を使用して実行できます。
環境を一覧表示するエンドポイントを呼び出す
ここで、Power Platform API を呼び出します。 すべての環境とそのメタデータを取得するには、List Environmentsエンドポイント を使用します。具体的には、容量の $expandパラメータを使用します。 これは、前のセクションで Microsoft Entra ID から受け取ったベアラー トークンの承認ヘッダーも使用します。 ユーザー名/パスワードのコンテキストを使用した場合は、このステップでもそのベアラー トークンを入力できます。
次に、このJSONスキーマと「JSONの解析」アクションを使用して、 Power Platform API応答 を型付きオブジェクトに解析します。
{
"properties": {
"value": {
"items": {
"properties": {
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"location": {
"type": "string"
},
"name": {
"type": "string"
},
"properties": {
"properties": {
"addons": {
"type": "array"
},
"azureRegion": {
"type": "string"
},
"capacity": {
"items": {
"properties": {
"actualConsumption": {
"type": "number"
},
"capacityType": {
"type": "string"
},
"capacityUnit": {
"type": "string"
},
"ratedConsumption": {
"type": "number"
},
"updatedOn": {
"type": "string"
}
},
"required": [
"capacityType",
"actualConsumption",
"ratedConsumption",
"capacityUnit",
"updatedOn"
],
"type": "object"
},
"type": "array"
},
"clientUris": {
"properties": {
"admin": {
"type": "string"
},
"maker": {
"type": "string"
}
},
"type": "object"
},
"cluster": {
"properties": {
"category": {
"type": "string"
},
"number": {
"type": "string"
}
},
"type": "object"
},
"connectedGroups": {
"type": "array"
},
"createdBy": {
"properties": {
"displayName": {
"type": "string"
},
"id": {
"type": "string"
},
"type": {
"type": "string"
}
},
"type": "object"
},
"createdTime": {
"type": "string"
},
"creationType": {
"type": "string"
},
"databaseType": {
"type": "string"
},
"displayName": {
"type": "string"
},
"environmentSku": {
"type": "string"
},
"isDefault": {
"type": "boolean"
},
"linkedEnvironmentMetadata": {
"properties": {
"backgroundOperationsState": {
"type": "string"
},
"baseLanguage": {
"type": "number"
},
"createdTime": {
"type": "string"
},
"domainName": {
"type": "string"
},
"friendlyName": {
"type": "string"
},
"instanceApiUrl": {
"type": "string"
},
"instanceState": {
"type": "string"
},
"instanceUrl": {
"type": "string"
},
"platformSku": {
"type": "string"
},
"resourceId": {
"type": "string"
},
"scaleGroup": {
"type": "string"
},
"uniqueName": {
"type": "string"
},
"version": {
"type": "string"
}
},
"type": "object"
},
"protectionStatus": {
"properties": {
"keyManagedBy": {
"type": "string"
}
},
"type": "object"
},
"provisioningState": {
"type": "string"
},
"retentionDetails": {
"properties": {
"backupsAvailableFromDateTime": {
"type": "string"
},
"retentionPeriod": {
"type": "string"
}
},
"type": "object"
},
"retentionPeriod": {
"type": "string"
},
"runtimeEndpoints": {
"properties": {
"microsoft.ApiManagement": {
"type": "string"
},
"microsoft.BusinessAppPlatform": {
"type": "string"
},
"microsoft.CommonDataModel": {
"type": "string"
},
"microsoft.Flow": {
"type": "string"
},
"microsoft.PowerApps": {
"type": "string"
},
"microsoft.PowerAppsAdvisor": {
"type": "string"
}
},
"type": "object"
},
"states": {
"properties": {
"management": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
},
"runtime": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"updateCadence": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"type": {
"type": "string"
}
},
"required": [
"id",
"type",
"location",
"name",
"properties"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
容量オブジェクトを反復処理する
これは、チュートリアルの最も複雑な部分です。 ここでは、ループ内のループを使用して、リスト 環境 応答, 内の各 環境 を反復処理します。各 環境 には、同様に反復処理される容量詳細の配列があります。 これにより、容量レポート テーブルの各 環境 行に必要な情報を取得できます。
For-each と解析
順を追って見ていきましょう。 まず、Parse-List-Response出力の「値」を使用してFor Eachコントロールを使用します。
次に、このJSONスキーマを使用して、この単一の 環境 を型付きオブジェクトに解析します。
{
"properties": {
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"location": {
"type": "string"
},
"name": {
"type": "string"
},
"properties": {
"properties": {
"addons": {
"type": "array"
},
"azureRegion": {
"type": "string"
},
"capacity": {
"items": {
"properties": {
"actualConsumption": {
"type": "number"
},
"capacityType": {
"type": "string"
},
"capacityUnit": {
"type": "string"
},
"ratedConsumption": {
"type": "number"
},
"updatedOn": {
"type": "string"
}
},
"required": [
"capacityType",
"actualConsumption",
"ratedConsumption",
"capacityUnit",
"updatedOn"
],
"type": "object"
},
"type": "array"
},
"clientUris": {
"properties": {
"admin": {
"type": "string"
},
"maker": {
"type": "string"
}
},
"type": "object"
},
"cluster": {
"properties": {
"number": {
"type": "string"
}
},
"type": "object"
},
"connectedGroups": {
"type": "array"
},
"createdBy": {
"properties": {
"displayName": {
"type": "string"
},
"id": {
"type": "string"
},
"type": {
"type": "string"
}
},
"type": "object"
},
"createdTime": {
"type": "string"
},
"creationType": {
"type": "string"
},
"databaseType": {
"type": "string"
},
"displayName": {
"type": "string"
},
"environmentSku": {
"type": "string"
},
"isDefault": {
"type": "boolean"
},
"linkedEnvironmentMetadata": {
"properties": {
"backgroundOperationsState": {
"type": "string"
},
"baseLanguage": {
"type": "integer"
},
"createdTime": {
"type": "string"
},
"domainName": {
"type": "string"
},
"friendlyName": {
"type": "string"
},
"instanceApiUrl": {
"type": "string"
},
"instanceState": {
"type": "string"
},
"instanceUrl": {
"type": "string"
},
"resourceId": {
"type": "string"
},
"scaleGroup": {
"type": "string"
},
"uniqueName": {
"type": "string"
},
"version": {
"type": "string"
}
},
"type": "object"
},
"protectionStatus": {
"properties": {
"keyManagedBy": {
"type": "string"
}
},
"type": "object"
},
"provisioningState": {
"type": "string"
},
"retentionDetails": {
"properties": {
"backupsAvailableFromDateTime": {
"type": "string"
},
"retentionPeriod": {
"type": "string"
}
},
"type": "object"
},
"retentionPeriod": {
"type": "string"
},
"runtimeEndpoints": {
"properties": {
"microsoft.ApiManagement": {
"type": "string"
},
"microsoft.BusinessAppPlatform": {
"type": "string"
},
"microsoft.CommonDataModel": {
"type": "string"
},
"microsoft.Flow": {
"type": "string"
},
"microsoft.PowerApps": {
"type": "string"
},
"microsoft.PowerAppsAdvisor": {
"type": "string"
}
},
"type": "object"
},
"states": {
"properties": {
"management": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
},
"runtime": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"updateCadence": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"type": {
"type": "string"
}
},
"type": "object"
}
次に、Parse-CurrentItem出力の「容量」を使用して別のFor Eachコントロールを使用します。 次に、次のJSONスキーマを使用して、これを型指定されたオブジェクトに解析します。
これで、Parse-Capacity 出力から CapacityType プロパティの Switch コントロールを使用できます。 これは、「データベース」、「ファイル」、または「ログ」のいずれかの値です。 各 switch ケースで、関連する 「actualConsumption」 プロパティを関連する変数にキャプチャします。 次の例では、データベース容量を取得していることがわかります。
「環境ごと」ループの最後のステップとして、レポートのこの行の環境の詳細をキャプチャできるようになりました。 配列変数に追加のコントロールを使用して、次の JSON スキーマを使用します。
{
"properties": {
"actualConsumption": {
"type": "number"
},
"capacityType": {
"type": "string"
},
"capacityUnit": {
"type": "string"
},
"ratedConsumption": {
"type": "number"
},
"updatedOn": {
"type": "string"
}
},
"type": "object"
}
レポート テーブルを作成する
おめでとうございます、これで簡単になりました! 完全に実装され、簡略化された環境容量配列ができたので、表形式で表示できます。
HTML テーブル コネクタを使用する
ロジック アプリを実行すると、HTML テーブル レポートの出力が表示されます。
この例では、原価会計の目的でレポートを関係者に電子メールで送信するか、データをデータベースに保存してさらに分析し、過去の傾向を把握することができます。