cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
fgroenev Frequent Visitor
Frequent Visitor

Uploading a PBIX file using the import API

Hello,

 

I am stuck trying to programmatically upload a .pbix file using the import API, making use of the request-promise library which is imported as "rp" here.

 

I am currently trying the following (in Node.js), which results in HTTP error 400:

let url = 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports';
		
let options = {
	method: 'POST',
	headers: {
		'Content-Type': 'multipart/form-data',
		'authorization': 'Bearer ' + accessToken
	},
	body: fs.createReadStream(__dirname + '/Report.pbix'),
	url: 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports'
};

rp(options)
	.then(function (body) {
	console.log('success! ', body);
})
	.catch(function (err) {
	console.log('error', err);
});

I also haven't had any success uploading the file using postman, where I have tried it with and without having set the Content-Type header. 

 

What could I be doing wrong? What headers are necessary to upload this file and make a proper request?

1 ACCEPTED SOLUTION

Accepted Solutions
fgroenev Frequent Visitor
Frequent Visitor

Re: Uploading a PBIX file using the import API

I figured out what I did wrong. Apparently you need a datasetDisplayName which is part of the url. 

 

Therefore this problem can be solved by appending the datasetDisplayName field to the url like this:

 

url: 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports?datasetDisplayName=' + reportName

View solution in original post

2 REPLIES 2
fgroenev Frequent Visitor
Frequent Visitor

Re: Uploading a PBIX file using the import API

I figured out what I did wrong. Apparently you need a datasetDisplayName which is part of the url. 

 

Therefore this problem can be solved by appending the datasetDisplayName field to the url like this:

 

url: 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports?datasetDisplayName=' + reportName

View solution in original post

Majid Frequent Visitor
Frequent Visitor

Re: Uploading a PBIX file using the import API

This is Python equivalant to upload a .pbix local file into PowerBI server

 

import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

groupId = "your workspace ID"
reportName = "reportName that you choose to appear on the server"
accessToken = "xx"

url = 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports?datasetDisplayName=' + reportName
headers = {
'Content-Type': 'multipart/form-data',
'authorization': 'Bearer ' + accessToken
}
file_location = '/xx.pbix'
# you need this dictionary to convert a binary file into form-data format
# None here means we skip the filename and file content is important
files = {'value': (None, open(file_location, 'rb'), 'multipart/form-data')}

mp_encoder = MultipartEncoder(fields=files)

r = requests.post(
url=url,
data=mp_encoder, # The MultipartEncoder is posted as data, don't use files=...!
# The MultipartEncoder provides the content-type header with the boundary:
headers=headers
)


 

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Kudoed Authors