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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
luanlopes
Frequent Visitor

"BadRequestException: The request was denied, it contains illegal input: ''"

Hello everyone,

I am trying to upload and import a PBIX file programmatically to a Power BI workspace using the Power BI REST API with the new "createTemporaryUploadLocation" method. The process is:

  1. Acquire Azure AD token using @Azure/msal-node

  2. Request a temporary upload URL from the API

  3. Upload the PBIX file directly to the given Azure Blob Storage URL using an HTTP PUT request

  4. Call the Power BI import API with the fileUrl pointing to the uploaded blob

The upload itself completes successfully (status 201), but when I call the import API, I receive the following error:

 

{
"code": "BadRequestException",
"message": "The request was denied, it contains illegal input: ''"
}

The full error details show a 400 Bad Request, but no indication of what input is illegal.

const axios = require('axios');
const { ConfidentialClientApplication } = require('@azure/msal-node');
const path = require('path');
const fs = require('fs');

const TENANT_ID = 'xxxx-xxxx-xxxx-xxxx';
const CLIENT_ID = 'xxxx-xxxx-xxxx-xxxx';
const CLIENT_SECRET = 'xxxxxx';
const GROUP_ID = 'xxxx-xxxx-xxxx-xxxx';
const FILE_PATH = '/path/to/file.pbix';

const POWERBI_API_BASE_URL = 'https://api.powerbi.com/v1.0/myorg';
const TEMP_UPLOAD_LOCATION_URL = `${POWERBI_API_BASE_URL}/groups/${GROUP_ID}/imports/createTemporaryUploadLocation`;

async function importLargePBIX() {
try {
const cca = new ConfidentialClientApplication({
auth: { clientId: CLIENT_ID, authority: `https://login.microsoftonline.com/${TENANT_ID}`, clientSecret: CLIENT_SECRET },
});
const tokenResponse = await cca.acquireTokenByClientCredential({
scopes: ['https://analysis.windows.net/powerbi/api/.default'],
});
const accessToken = tokenResponse.accessToken;
const headers = { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' };

// Get temporary upload URL
const tempLocationResponse = await axios.post(TEMP_UPLOAD_LOCATION_URL, {}, { headers });
const uploadUrl = tempLocationResponse.data.url;

// Upload PBIX file to the blob storage URL
const fileBuffer = fs.readFileSync(FILE_PATH);
await axios.put(uploadUrl, fileBuffer, {
headers: { 'Content-Type': 'application/octet-stream', 'x-ms-blob-type': 'BlockBlob' },
maxContentLength: Infinity,
maxBodyLength: Infinity,
});

// Import dataset referencing uploaded PBIX URL
const importApiUrl = `${POWERBI_API_BASE_URL}/groups/${GROUP_ID}/imports?datasetDisplayName=MyDataset&nameConflict=Overwrite`;
const bodyPost = { fileUrl: uploadUrl };

const importResponse = await axios.post(importApiUrl, bodyPost, { headers });
console.log('Import successful:', importResponse.data);
} catch (error) {
console.error('Import error:', error.response ? error.response.data : error.message);
}
}

importLargePBIX();

Question:

  • Has anyone encountered this "illegal input: ''" error when importing PBIX via fileUrl?

  • Is there any missing or malformed data in the import API call?

  • Is the fileUrl supposed to be the exact temporary upload URL received, or does it need some modification?

  • Any suggestions on how to resolve this?

Thanks in advance for your help!

3 REPLIES 3
Nasif_Azam
Solution Specialist
Solution Specialist

Hey @luanlopes ,

This error typically indicates that the Power BI REST API is receiving a missing or incorrectly formatted parameter but unfortunately, the message doesn’t specify which one. Here's a thorough breakdown of possible issues and how to resolve them.

 

What Might Be Causing the Issue

1. fileUrl Must Be the sasUri (Not url)

Power BI's createTemporaryUploadLocation response returns an object that includes sasUri and fileUploadState. You must use the sasUri in the import call:

const uploadUrl = tempLocationResponse.data.sasUri;

You're currently using tempLocationResponse.data.url, which is likely incorrect or empty hence the illegal input: '' error.

 

2. Body Format Must Match Expected Schema

When calling the import API with a fileUrl, your body must include:

{
  "fileUrl": "<SAS URL>",
  "datasetDisplayName": "MyDataset",
  "nameConflict": "Overwrite"
}

But in your current code, you're passing datasetDisplayName and nameConflict as query parameters, not in the body.

 

Fix:

const importApiUrl = `${POWERBI_API_BASE_URL}/groups/${GROUP_ID}/imports`;
const bodyPost = {
  fileUrl: uploadUrl,
  datasetDisplayName: "MyDataset",
  nameConflict: "Overwrite"
};
const importResponse = await axios.post(importApiUrl, bodyPost, { headers });

 

Updated Code Fixes

// Get temporary upload URL
const tempLocationResponse = await axios.post(TEMP_UPLOAD_LOCATION_URL, {}, { headers });
const uploadUrl = tempLocationResponse.data.sasUri; // use sasUri instead of url

// Upload PBIX file
await axios.put(uploadUrl, fileBuffer, {
  headers: {
    'Content-Type': 'application/octet-stream',
    'x-ms-blob-type': 'BlockBlob'
  },
  maxContentLength: Infinity,
  maxBodyLength: Infinity,
});

// Call Import API
const importApiUrl = `${POWERBI_API_BASE_URL}/groups/${GROUP_ID}/imports`;
const bodyPost = {
  fileUrl: uploadUrl,
  datasetDisplayName: 'MyDataset',
  nameConflict: 'Overwrite'
};

const importResponse = await axios.post(importApiUrl, bodyPost, { headers });
console.log('Import successful:', importResponse.data);

 

In Short:

Using url instead of sasUri (Replace tempLocationResponse.data.url with .sasUri)

Passing parameters in URL (Pass datasetDisplayName and nameConflict in the request body)

Empty string error (Likely due to fileUrl being '' or malformed)

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam

Hey @Nasif_Azam, thank you very much for the response!


1. When I call the endpoint

${POWERBI_API_BASE_URL}/groups/${GROUP_ID}/imports/createTemporaryUploadLocation

to create a temporary upload location, the response is:

Creating temporary upload location...
Complete tempLocationResponse: {
  "@odata.context": "https://api.powerbi.com/v1.0/myorg/groups/*****/$metadata#Microsoft.PowerBI.ServiceContracts.Api.temporaryUploadLocation",
  "url": "https://*******",
  "expirationTime": "2025-06-18T22:11:38.0591596Z"
}

but I don’t receive a sasUri parameter to use afterward.

2. Regarding datasetDisplayName and nameConflict, I’m using them as query parameters because I was following the documentation. I also tested sending them in the body, but it still didn’t work.

 

here the full log:

Access token obtained successfully.
Creating temporary upload location...
Complete tempLocationResponse: {
  "@odata.context": "https://api.powerbi.com/v1.0/myorg/groups/*********/$metadata#Microsoft.PowerBI.ServiceContracts.Api.temporaryUploadLocation",
  "url": "https://wabibrasbppbiv2.blob.core.windows.net/{container}/{folder}/Import/{fileId}?skoid=***&sktid=***&skt=2025-06-18T21:11:38Z&ske=2025-06-19T21:11:38Z&sks=b&skv=2024-08-04&sv=2024-08-04&se=2025-06-18T22:11:38Z&sr=b&sp=w&sig=***"",
  "expirationTime": "2025-06-18T22:11:38.0591596Z"
}
Starting PBIX file upload...
File size: 43.97 MB
Upload progress: 0%
Upload progress: 100%
PBIX file upload completed successfully!
Upload status: 201
Waiting for file processing...
Starting dataset import in Power BI...
An error occurred during the import process: {
  code: 'BadRequestException',
  message: "The request was denied, it contains illegal input: ''"
}
Error status: 400
Error headers: {
  'content-length': '96',
  'content-type': 'application/json; charset=utf-8',
  ...
}
Complete error data: {
  "code": "BadRequestException",
  "message": "The request was denied, it contains illegal input: ''"
}

i tried executing the steps you mentioned, but they aren’t working for me. I have some screenshots and context, but it’s a bit strange.

I'm using this documentation to create a temporary location: https://learn.microsoft.com/pt-br/rest/api/power-bi/imports/create-temporary-upload-location-in-grou...

best regards,

Hey @luanlopes ,

Thanks for the detailed. You're right your url is the correct SAS URL. They’ve renamed sasUri to url in the latest API). The issue is likely with how you're passing parameters.

 

Try this minimal fix:

const importApiUrl = `${POWERBI_API_BASE_URL}/groups/${GROUP_ID}/imports`;
const bodyPost = {
  fileUrl: uploadUrl, // from tempLocationResponse.data.url
  datasetDisplayName: "MyDataset",
  nameConflict: "Overwrite"
};

const importResponse = await axios.post(importApiUrl, bodyPost, {
  headers: {
    ...headers,
    'Content-Type': 'application/json' // ensure this is set for POST body
  }
});

Don’t use query params for datasetDisplayName or nameConflict.

 

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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