Forum Discussion
fgroenev
8 years agoRegular 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 foll...
- 8 years ago
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
Anonymous
6 years agoNot applicable
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
)