Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Power Platform API can be used to extract various details and metadata from your Microsoft Power Platform environments with or without a Microsoft Dataverse database. The API is used internally by various clients available today such as PowerShell.
In this tutorial, you learn how to:
- Create a Power Automate or Logic Apps workflow (Azure) or PowerShell script that authenticates with the Power Platform API.
- Call the List Environments endpoint to retrieve your Microsoft Power Platform environment details.
- Iterate through the capacity object to retrieve the actual consumption.
- Save the consumption data into a table for display.
- Compare the consumption with your tenant's total capacity.
As an example of this scenario, a customer is looking to get a handle on their capacity consumption so that they can better understand the allocation of their total tenant capacity by department. This helps the customer to perform some internal cost accounting functions and charge backs based on how much each department is consuming of the total available capacity. This customer is using the environment Description to call out the department that owns each environment.
Connect and variable setup
Use the following details on getting connected to the Power Platform programmatically. You can choose between an Azure experience or PowerShell scripts.
Create the workflow and set up the variables
To start off, in this tutorial we use a Logic Apps workflow. A Power Automate flow is also acceptable, and any other orchestration engine that your company prefers to use for automation. All of the calls to retrieve the data use RESTful APIs so any tooling that supports REST works with this tutorial.
Visit the Azure portal, and then create a new logic app and give it a name:

After that finishes provisioning, edit the workflow using the Designer and set up a Recurrence trigger to run daily:

Next, we need to initialize five variables:
- SPN-Id – This is your service principal ClientID. It's used later to perform the authentication in a service principal context. If you're using username/password context, you can skip this variable.
- DBCapacity – This is a Float variable for the consumed database capacity in megabytes.
- FileCapacity – This is a Float variable for the consumed file capacity in megabytes.
- LogCapacity – This is a Float variable for the consumed log capacity in megabytes.
- SimplifiedEnvironmentArray – This is an array variable that we populate with a few environment properties. This drastically simplifies the final HTML table report output. In the following screenshot, the action that initializes this variable is named SimplifiedEnvironmentArray-Init.

Next, we authenticate with Microsoft Entra and retrieve a token for calling the Power Platform API. If you haven’t completed your Microsoft Entra setup, see Authentication - legacy.
In this tutorial, we're using a key vault to store our service principal secret value. In this way, an IT administrator can make this value securely available for your workflow. This is then populated in the POST call to Microsoft Entra to retrieve the token. Use an HTTP action to send the following request, where <client-id> is the value of the SPN-Id variable and <client-secret> is the secret from your key vault:
POST https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
client_id=<client-id>&scope=https://service.powerapps.com//.default&client_secret=<client-secret>&grant_type=client_credentials
We then parse the Microsoft Entra token response into a typed object using this JSON schema in the 'Parse JSON' action:
{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "integer"
},
"ext_expires_in": {
"type": "integer"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}

Fetch environments
In this section, we fetch the environment list that you administer. This can be done via API and PowerShell.
Call the List Environments endpoint
Now is the time to call the Power Platform API. Use the List Environments endpoint to retrieve all of our environments and their metadata, specifically with the $expand parameter for capacity. This also uses the Authorization header with the Bearer Token we received in the previous section from Microsoft Entra ID. If you used username/password context, you can also enter that Bearer Token at this step as well. For more information about this endpoint, see List environments.
GET https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments?api-version=2020-10-01&$expand=properties.capacity,properties.addons
Authorization: Bearer <access-token>

We then parse the Power Platform API response into a typed object using this JSON schema with the 'Parse JSON' action:
{
"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"
}

Iterate through the Capacity object
This is the most complex part of the tutorial. Here we use a loop inside of a loop to iterate each environment in the List Environment response, and each environment has an array of capacity details that we iterate as well. This lets us capture the necessary information for each environment row in our capacity report table.
For-each and parsing
Let’s take this step by step. First, we use a For Each control using the ‘value’ of the Parse-List-Response output:

Then we parse this single environment into a typed object using this JSON schema:
{
"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"
}
Next, we use another For Each control using the ‘capacity’ of the Parse-CurrentItem output. Then we add a Parse JSON action named Parse-Capacity that parses the current capacity item into a typed object using this JSON schema:
{
"properties": {
"actualConsumption": {
"type": "number"
},
"capacityType": {
"type": "string"
},
"capacityUnit": {
"type": "string"
},
"ratedConsumption": {
"type": "number"
},
"updatedOn": {
"type": "string"
}
},
"type": "object"
}

Now we can use the Switch control on the CapacityType property from the Parse-Capacity output. This is either the value of ‘Database’, ‘File’, or ‘Log’. Under each switch case, capture the related ‘actualConsumption’ property into the related variable. In the following case, you see we're capturing Database capacity:

As the last step in the ‘For each environment’ loop, we now can capture the environment details for this row in the report. Add an Append to array variable action that appends to the SimplifiedEnvironmentArray variable. For the value, enter a JSON object with the following properties, and select the matching variable or dynamic content for each one:
| Property | Value |
|---|---|
DBCapacityConsumedMB |
The DBCapacity variable |
DisplayName |
displayName from the Parse-CurrentItem output |
EnvironmentId |
name from the Parse-CurrentItem output |
EnvironmentType |
environmentSku from the Parse-CurrentItem output |
FileCapacityConsumedMB |
The FileCapacity variable |
LogCapacityConsumedMB |
The LogCapacity variable |

Build report table
Congratulations, you’ve now made it to the easy part! Now that we have our fully populated and simplified environment capacity array, we can display it in tabular format.
Use the HTML Table connector

Running the logic app, we can now see the output of the HTML table report:

The report could be optionally emailed to stakeholders in this example for Cost Accounting purposes, or the data could be saved into a database for further analysis and historical trending.
Compare consumption with total tenant capacity
The List Environments response shows how much capacity each environment consumes, but it doesn't show your tenant's total capacity. To compare consumption with your tenant's total Database, File, and Log capacity, use the Get Tenant Capacity Details operation of Power Platform API:
GET https://api.powerplatform.com/licensing/tenantCapacity?api-version=2024-10-01
Authorization: Bearer <access-token>
This request uses a token for Power Platform API, with the scope https://api.powerplatform.com/.default, not the token that you got earlier in this tutorial. To set up authentication for Power Platform API, see Authentication.
The response includes a tenantCapacities array with one entry for each capacity type. Each entry includes these properties:
capacityType: The type of capacity, such asDatabase,File, orLog.capacityUnits: The unit of measure, such asMB.totalCapacity: Your tenant's total capacity of this type.consumption: Your tenant's consumption of this type. Theactualproperty contains the actual consumption.
You can also get these details by using the pac licensing get-tenant-capacity-details command in the Power Platform CLI. This command is in preview.