Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
rdini8
Helper I
Helper I

Publish a report to workspace using import api endpoint

Hi, I am trying to publish a report to my workspace using import api in python. This is the code at the moment:

#Import necessary libraries

import msal
import requests
import json
import pandas as pd

 

#Set parameters

client_id = "<myclientid>" 
client_secret = "<myclientsecret>" 
tenant_name = "<mytenantname>"

authority_url = "https://login.microsoftonline.com/" + tenant_name
scope = ["https://analysis.windows.net/powerbi/api/.default"]


#Use MSAL to grab token

app = msal.ConfidentialClientApplication(client_id, authority=authority_url, client_credential=client_secret)
result = app.acquire_token_for_client(scopes=scope)

access_token = result['access_token']

 

pbix_file_path = r'C:\Users\abc\Desktop\publish_trial.pbix'
publish_url = 'https://api.powerbi.com/v1.0/myorg/groups/7e63865a-39fd-4a58-9274-cc6558a75a25/imports?datasetDispla...'

 

headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'multipart/form-data'
}

 

with open(pbix_file_path, 'rb') as pbix_file:
       pbix_content = pbix_file.read()

 

response = requests.post(publish_url, headers=headers, data=pbix_content)

response.text

 

I'm getting the error :

{"error":{"code":"UnknownError","pbi.error":{"code":"UnknownError","parameters":{},"details":[],"exceptionCulprit":1}}}

 

Is there something I'm missing?

1 REPLY 1
lbendlin
Super User
Super User

Does it work in the REST API sandbox?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors