How to Access Power BI REST APIs Programmatically

Cody Schneider••7 min read

Tackling repetitive manual tasks in Power BI can be draining. The Power BI REST API is your key to automating workflows, embedding content, and managing your Power BI environment at a larger scale. This article guides you step-by-step through setting up access, authenticating programmatically, and making your first API calls with practical examples.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Why Bother with the Power BI REST API?

Working directly in the Power BI Service web interface is perfect for building reports and interacting with dashboards, but certain tasks become tedious when done at scale. The API opens the door to powerful automation and integration possibilities that are simply not feasible through the user interface.

Here’s what you can achieve with programmatic access:

  • Automate Administrative Tasks: Imagine automatically updating user permissions across dozens of workspaces after an organizational change or archiving old reports without clicking through hundreds of menus. You can programmatically manage workspaces, users, datasets, and admin settings.
  • Integrate with Your Workflows: You can trigger a Power BI dataset refresh from an external process. For example, after your nightly data warehouse ETL job successfully completes, a script can automatically kick off a dataset refresh, ensuring your reports always have the latest data.
  • Embed Content in Custom Applications: Go beyond standard sharing and embed interactive Power BI reports, dashboards, and tiles directly into your own internal portals or customer-facing applications, creating a seamless user experience.
  • Automate Deployment: Create scripts to handle your development lifecycle (dev, test, prod). You can programmatically deploy new PBIX files, update connection parameters, and manage different versions of reports across multiple workspaces.

In short, the API transforms Power BI from a standalone BI tool into an integrated and extensible component of your data ecosystem.

Step 1: Register Your Application in Microsoft Entra ID

Before you can write a line of code, you need to tell Microsoft’s identity platform about your application. This is done by registering an "app" in Microsoft Entra ID (formerly known as Azure Active Directory). This registration gives your application a unique identity that Power BI can trust.

The best method for backend automation is using a Service Principal. Think of a service principal as a non-human 'robot' identity for your application. It can be granted its own permissions, independent of any user, to perform tasks on your behalf at any time.

Registering the App

  1. Navigate to the Azure Portal and sign in.
  2. Search for and select Microsoft Entra ID.
  3. From the left navigation pane, select App registrations, then click + New registration.
  4. Fill out the registration form:
  5. Click Register.

Once created, you'll be taken to your app's main page. Immediately copy these two critical values and save them securely:

  • Application (client) ID
  • Directory (tenant) ID

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Creating a Client Secret

A client secret is essentially the password for your newly created application identity. It is highly sensitive and should be treated like any other credential.

  1. In your App registration, navigate to Certificates & secrets from the left menu.
  2. Click + New client secret.
  3. Provide a description (e.g., "Automation Secret") and choose an expiration period. Note: For security best practices, avoid "Never."
  4. Click Add.
  5. Immediately copy the "Value" field. This is your only chance to see the full secret. Once you leave this page, it will be hidden forever. Store it securely with your Client ID and Tenant ID.

Step 2: Grant Your Application Access to Power BI

Just because your application exists doesn't mean it can interact with Power BI. You now need to grant it permissions to do so. This is a two-part process.

Configure API Permissions in Azure

This step tells Microsoft Entra ID what actions your app is allowed to attempt within the Power BI ecosystem.

  1. Navigate back to your App registration in Azure Portal.
  2. Go to API permissions from the left menu.
  3. Click + Add a permission and select Power BI Service from the list of APIs.
  4. When asked for the type of permission, choose Application permissions. This is for the service principal (app-only access) workflow.
  5. A list of permissions will appear. Check the ones you need. It's best practice to grant only the minimum permissions required (Principle of Least Privilege). Some common ones for automation include:
  6. After adding permissions, you will see a status that says "Not granted for..." for your new permissions. An admin must approve them. Click the Grant admin consent for [Your Tenant Name] button and confirm. The status should update to a green checkmark.

Enable Service Principal Access in the Power BI Admin Portal

This is a critical and often-missed step. You must explicitly allow service principals to use the Power BI APIs in your Power BI tenant settings.

  1. Log in to app.powerbi.com with an account that has a Power BI Administrator role.
  2. Click the Settings gear icon and select Admin portal.
  3. Go to Tenant settings and scroll down to the Developer settings section.
  4. Find the setting titled "Allow service principals to use Power BI APIs."
  5. Enable this setting. For enhanced security, it's highly recommended to apply this to a specific security group rather than the entire organization. You can create a security group in Microsoft Entra ID, add your application's service principal to it, and then specify that group here.

Step 3: Programmatically Getting an Access Token

With the setup complete, you can now write code to authenticate. The goal is to send your credentials (Tenant ID, Client ID, and Client Secret) to the Microsoft identity endpoint. In return, you'll receive a temporary bearer token (also called an access token), which acts as your security key for making actual API calls.

This token must be included in the "Authorization" header of every subsequent API request you make to Power BI.

Python Example using the MSAL Library

Using a library like Microsoft Authentication Library (MSAL) simplifies this process significantly. First, install the necessary libraries:

pip install msal requests

Then, use the following script to obtain your access token:

import msal import requests import json

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Configuration from your Azure App Registration

TENANT_ID = 'your_tenant_id_here' CLIENT_ID = 'your_client_id_here' CLIENT_SECRET = 'your_client_secret_value_here'

Power BI API scope

POWER_BI_SCOPE = ['https://analysis.windows.net/powerbi/api/.default']

Set up the MSAL confidential client application

authority = f"https://login.microsoftonline.com/{TENANT_ID}" app = msal.ConfidentialClientApplication( client_id=CLIENT_ID, client_credential=CLIENT_SECRET, authority=authority )

Acquire the token

result = app.acquire_token_for_client(scopes=POWER_BI_SCOPE)

access_token = None if 'access_token' in result: access_token = result['access_token'] print("Access token acquired successfully!") else: print("Failed to acquire token.") print(result.get("error")) print(result.get("error_description"))

Now, you're ready to use the token

if access_token: print("Ready to make API calls!")

Step 4: Making API Calls to Power BI

Once you have the access token, you can start interacting with the Power BI REST API. Every request will go to a base URL of https://api.powerbi.com/v1.0/myorg/ plus the specific endpoint for the resource you want to access.

Example: Get a List of All Workspaces

This simple request retrieves a list of workspaces your service principal can access. Notice how the access_token is included in the authorization header.

if access_token: api_url = "https://api.powerbi.com/v1.0/myorg/groups" headers = { 'Authorization': f'Bearer {access_token}' }

response = requests.get(api_url, headers=headers)

if response.status_code == 200:
    workspaces = response.json()
    print("Successfully retrieved workspaces:")
    for ws in workspaces['value']:
        print(f"- {ws['name']} (ID: {ws['id']})")
else:
    print(f"Error calling API: {response.status_code}")
    print(response.text)

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Example: Trigger a Dataset Refresh

This is a more practical automation task. To trigger a refresh, you need the ID of the workspace (called a groupId) and the ID of the dataset. You send a POST request to the refresh endpoint.

if access_token: # Replace with your actual workspace and dataset IDs workspace_id = 'your-actual-workspace-id' dataset_id = 'your-actual-dataset-id'

api_url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/refreshes"
headers = {
    'Authorization': f'Bearer {access_token}'
}

response = requests.post(api_url, headers=headers)

# A 202 'Accepted' status code means the refresh was successfully triggered
if response.status_code == 202:
    print(f"Dataset refresh successfully requested for dataset ID: {dataset_id}")
else:
    print(f"Error triggering refresh: {response.status_code}")
    print(response.text)

Final Thoughts

Connecting to the Power BI REST API unlocks a vast range of possibilities for automation and integration that can save you significant time and effort. By registering an app in Microsoft Entra ID and following the correct authentication flow to obtain a bearer token, you can begin to programmatically script nearly any repetitive task in your Power BI environment.

We know that even with the flexibility of REST APIs, connecting multiple marketing and sales data sources is often just the first step in a long analysis process. If your goal is to quickly create dashboards without wrestling with API limits and coding, we've built Graphed to simplify this entire workflow. By connecting your platforms with a few clicks, you can use natural language to build dashboards, get instant answers from your data, and turn hours of data prep into seconds of conversation.

Related Articles