The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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?
Does it work in the REST API sandbox?