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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
alexz56
Regular Visitor

Rdl import via API 400 Bad Request

Hi,

 

I have an application where you can upload .pbix and .rdl reports to PowerBI.

 

I can successfully import .pbix reports via API. Hovewer, when I run import for .rdl file on the API, I am getting an error - 400 Bad Request RequestedFileIsEncryptedOrCorrupted.

 

PowerBI setup is proper and I have a premium account, the token is proper as well.

 

 

string importURL = string.Format("{0}/groups/{1}/imports?datasetDisplayName={2}&nameConflict=Overwrite", PowerBiServiceRootUrl, GroupId, datasetDisplayName);

var importResponse = ImportPBI(FileName, importURL);


public string ImportPBI(string pbiFilePath, string url)
        {
            // create REST URL with import name in quer string
            string restUrlImportPbi = url;

            // load PBI file into StreamContent object
            var pbiBodyContent = new StreamContent(File.Open(pbiFilePath, FileMode.Open));

            // add headers for request bod content
            pbiBodyContent.Headers.Add("Content-Type", "application/octet-stream");
            pbiBodyContent.Headers.Add("Content-Disposition",
                                         @"form-data; name=""file""; filename=""" + pbiFilePath + @"""");

            // load PBI content into body using multi-part form datas
            MultipartFormDataContent requestBody = new MultipartFormDataContent(Guid.NewGuid().ToString());
            requestBody.Add(pbiBodyContent);

            // create and configure HttpClient
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

            // post request
            var response = client.PostAsync(restUrlImportPbi, requestBody).Result;

            // check for success
            return response.StatusCode.ToString();

        }

 

 

Thank you and looking forward to hearing back from you.

Cheers.

1 REPLY 1
xhead
Helper II
Helper II

This happened to me recently, and the problem was that the file I was attempting to upload had an ampersand (&) in the file name. For example, the file named "My charts & graphs.rdl" will cause this error, but the file named "My Charts and graphs.rdl" will not. 

 

I've also seen it occur with text in the RDL file that had special characters, like the (c), (r) or (tm) characters.  

 

Mike

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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