Using Power BI REST API – Comprehensive Guide
Power BI REST API allows developers to interact programmatically with Power BI service, automate tasks, embed reports, manage workspaces, and more. This guide provides a detailed, step-by-step walkthrough of using the Power BI REST API.
🔹 Prerequisites
Before working with Power BI REST API, ensure you have the following:
- Power BI Pro or Premium License
- Required for accessing API endpoints.
- Azure Active Directory (Azure AD) Application
- Used for authentication.
- Power BI Service Account
- An account with access to Power BI reports and workspaces.
- API Permissions
- Permissions must be granted for API access in Azure AD.
- Power BI Workspace and Reports
- The API will interact with workspaces, datasets, reports, etc.
🔹 Step 1: Register an Azure AD App for Power BI API Access
Power BI REST API requires authentication via an Azure AD app. Follow these steps to register an app in Azure Portal.
1️⃣ Register the App in Azure AD
- Go to Azure Portal.
- Navigate to Azure Active Directory → App registrations.
- Click New Registration.
- Enter the app name (e.g.,
PowerBI-API-App
). - Choose Accounts in this organizational directory only.
- Click Register.
2️⃣ Generate Client Secret
- Open your registered app in Azure AD.
- Navigate to Certificates & Secrets → Click New Client Secret.
- Set expiration (e.g., 1 year, 2 years, etc.).
- Click Add, then Copy the Secret Value.
3️⃣ Assign API Permissions
- Open API Permissions in the Azure app.
- Click Add a permission → APIs my organization uses.
- Search for Power BI Service and select it.
- Add the following Delegated Permissions:
Dashboard.ReadWrite.All
Dataset.ReadWrite.All
Report.ReadWrite.All
Workspace.ReadWrite.All
Content.Create
- Click Grant Admin Consent to enable permissions.
4️⃣ Capture App Credentials
Save the following details for API requests:
- Tenant ID: Found in Azure AD Overview.
- Client ID: Found in App Overview.
- Client Secret: Generated earlier.
🔹 Step 2: Authenticate Using Power BI REST API
Power BI REST API uses OAuth 2.0 Authentication. Follow these steps:
1️⃣ Get Access Token
Use the following API request to get a token:
Request (POST)
https://login.microsoftonline.com/{tenant-id}/oauth2/token
Headers
Content-Type: application/x-www-form-urlencoded
Body (Form-Data)
grant_type=client_credentials
client_id={your-client-id}
client_secret={your-client-secret}
resource=https://graph.microsoft.com/
Response (Example)
{
"token_type": "Bearer",
"expires_in": 3600,
"access_token": "eyJ0eXA... (truncated)"
}
Save the access_token, as it is required for API calls.
🔹 Step 3: Using Power BI REST API
Once authenticated, you can perform actions like managing workspaces, reports, datasets, and more.
📌 Example 1: Get List of Workspaces
Request (GET)
https://api.powerbi.com/v1.0/myorg/groups
Headers
Authorization: Bearer {access_token}
Content-Type: application/json
Response
{
"value": [
{
"id": "group-id",
"name": "Sales Workspace",
"isReadOnly": false
}
]
}
📌 Example 2: Get Reports in a Workspace
Request (GET)
https://api.powerbi.com/v1.0/myorg/groups/{workspace-id}/reports
Response
{
"value": [
{
"id": "report-id",
"name": "Sales Report",
"webUrl": "https://app.powerbi.com/groups/report-id"
}
]
}
📌 Example 3: Embed a Report
Request (GET)
https://api.powerbi.com/v1.0/myorg/groups/{workspace-id}/reports/{report-id}
Response
{
"id": "report-id",
"name": "Sales Report",
"embedUrl": "https://app.powerbi.com/reportEmbed?reportId=report-id"
}
Use embedUrl
in SharePoint or Teams for embedding.
📌 Example 4: Refresh Dataset
Request (POST)
https://api.powerbi.com/v1.0/myorg/groups/{workspace-id}/datasets/{dataset-id}/refreshes
Response
{
"id": "refresh-id",
"status": "InProgress"
}
📌 Example 5: Create a New Workspace
Request (POST)
https://api.powerbi.com/v1.0/myorg/groups
Body
{
"name": "New Workspace"
}
Response
{
"id": "new-workspace-id",
"name": "New Workspace"
}
🔹 Automating Power BI Tasks
You can automate: ✅ Dataset Refreshing – Schedule using Power Automate.
✅ User Management – Assign roles via API.
✅ Embedding Reports – Automate dashboards in SharePoint or Teams.
✅ Workspace Management – Create, delete, and modify workspaces.
🔹 Power BI REST API Best Practices
✔ Use Service Principal – Instead of user authentication.
✔ Cache Access Tokens – Tokens last for 1 hour, avoid frequent requests.
✔ Monitor API Limits – Power BI API has rate limits (100 requests per minute).
✔ Secure Credentials – Never expose client secret in frontend apps.
✔ Use Power Automate – To trigger API calls automatically.
🔹 Common Errors and Troubleshooting
Error | Solution |
---|---|
401 Unauthorized | Ensure access token is valid and permissions are granted. |
403 Forbidden | Check if the user has Power BI Pro license and API permissions. |
404 Not Found | Verify the workspace/report ID is correct. |
429 Too Many Requests | API rate limit exceeded. Use retry logic. |
Conclusion
Power BI REST API is a powerful tool for automating data management, embedding reports, and enhancing Power BI functionality. With proper authentication and API calls, you can efficiently integrate Power BI with custom applications, SharePoint, and Teams.
Now you can start automating and embedding Power BI like a pro!