Get Publish-to-Web & Org. share links from Power BI API with Python
Data Goblins · May, MO · 1 mo ago
Business DevelopmentFull-time
About the role
This article provides a Python-based solution to retrieve publish-to-web and organization-wide share links from the Power BI Admin API. The code demonstrates how to authenticate using Azure Service Principal and fetch widely shared artifacts for governance and administration purposes.
Responsibilities
- Retrieve publish-to-web links created within your Power BI organization using Python.
- Fetch links shared to the entire organization (e.g., for Reports and Dashboards).
- Process and analyze the retrieved data using pandas DataFrames.
- Implement secure authentication via Azure Service Principal.
Requirements
- Python environment (e.g., Google Colab Notebook).
- Azure Service Principal with appropriate permissions for Power BI Admin API access.
- Libraries: requests, pandas, azure.identity.
- Power BI Admin API access enabled in your tenant.
Setup Instructions
Follow these steps to configure the solution:
- Replace placeholder values (Your-Tenant-ID, Your-App-Client-ID, Your-Client-Secret-Value) with your Azure AD tenant and Service Principal details.
- For enhanced security, use Azure Key Vault to manage client secrets (see Microsoft documentation).
- Install required Python packages if not already present: !pip install azure.identity
Code Implementation
The provided Python script performs the following actions:
- Authenticates using Azure Service Principal to obtain an access token for the Power BI API.
- Queries the Power BI Admin API to retrieve:
- All publish-to-web artifacts (limited to 5000 workspaces).
- All links shared to the entire organization.
- Processes the API response and converts it into a pandas DataFrame for analysis.
- Handles errors gracefully, such as missing data or authentication failures.
Example Output
The script generates a DataFrame containing publish-to-web reports or organization-wide shared links, including metadata such as artifact IDs, access details, and sharing status.
Notes
- The code is designed for use in Google Colab but can be adapted for other Python environments.
- The Power BI Admin API requires a $top=n parameter to function; the example uses $top=5000 to cover large environments.
- No guarantees or warranties are provided with this code; it is shared as a quick reference for governance tasks.