3

I am new come to the python, but I need to invoke Power BI REST API with python to publish my pbix file in my repo to the workspace.

Based on this document, I could successfully authenticated and get the workspace:

import json, requests, pandas as pd
try:
    from azure.identity import ClientSecretCredential
except Exception:
     !pip install azure.identity
     from azure.identity import ClientSecretCredential

# --------------------------------------------------------------------------------------#
# String variables: Replace with your own
tenant = 'Your-Tenant-ID'
client = 'Your-App-Client-ID'
client_secret = 'Your-Client-Secret-Value' # See Note 2: Better to use key vault
api = 'https://analysis.windows.net/powerbi/api/.default'
# --------------------------------------------------------------------------------------#

# Generates the access token for the Service Principal
auth = ClientSecretCredential(authority = 'https://login.microsoftonline.com/',
                                                        tenant_id = tenant,
                                                        client_id = client,
                                                        client_secret = client_secret)
access_token = auth.get_token(api)
access_token = access_token.token

print('\nSuccessfully authenticated.') 

But I do not know how to publish my pbix to one of my workspace and with parameter overwrite by using REST API with python. And if the pbix already existed in the workspace, provide the parameter to overwrite it.

Any advice would be greatly appreciated and a sample will be greate.

Joy
  • 1,171
  • 9
  • 15
  • I think there is an alternative thread on the Power BI community forum: https://community.powerbi.com/t5/Desktop/Power-BI-Rest-API/m-p/2285812. It discusses the uploads of templates, but if you look at the answer (pointing towards this import-POST-request: https://learn.microsoft.com/en-us/rest/api/power-bi/imports/post-import), you'll see they're discussing your very problem (at least the first of the two concerning the publishing of .pbix's). Hope, that helps! – abbasador Oct 05 '22 at 08:16
  • Oh, and even better, here's a Node.js and Pythonic way (you'll need to scroll down a bit) to solve this issue: https://community.powerbi.com/t5/Developer/Uploading-a-PBIX-file-using-the-import-API/m-p/357386 – abbasador Oct 05 '22 at 08:19

0 Answers0