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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
LukaP
Frequent Visitor

Error: MultipartRequestBodyParseError

Hello, so i am trying to upload files using POST Import API request. So far I have successfully uploaded a PBIX file to my workspace with the API call, but when i try and upload an XLSX file with the same function i get

 

{"error":{"code":"MultipartRequestBodyParseError","pbi.error":{"code":"MultipartRequestBodyParseError","parameters":{},"details":[]}}}

 

The function that i use to upload the file is:

 

def import_file(token,datasetDisplayName,file):
    url = f"https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName={datasetDisplayName}"
    header = {
        "Authorization": f"Bearer {token}",
        "Content-type": "multipart/form-data"
    }
    payload = {
        "filePath": file,
    }
    r = requests.post(url, headers=header, files=payload)
    response = r
    print(response)
    print(response.text)

file_path = "test_file.xlsx"
file_contents = open("test_file.xlsx", "rb")
import_file(token,"Melbourne.xlsx", file_contents)

 

 

2 REPLIES 2
Anonymous
Not applicable

Hi @LukaP ,

Where did the file hosts? If it was store in sharepoint or onedrive online, please set the context-type to 'application/json'.
If you are work with a local file, I'd like to suggest you to use the absolute path instead to relative path to help requests correctly find the pending upload files.

Imports - Post Import - REST API (Power BI Power BI REST APIs) | Microsoft Learn

Regards,

Xiaoxin Sheng

Hello,

The files are on my local machine; i have tried using the aboslute path but the result is the same, I still get the "MultipartRequestBodyParseError".

I have also tried reading the entire file and trying to upload that variable, however nothing changed. I also tried switching content-type to "json" just to see if it works and then it gave me response code 400, without any errors this time

 

Honestly, at this point i have no idea what is going wrong

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.