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
Anonymous
Not applicable

How to upload a locally created PBIX file to the PBI server using REST API? (with postman)

Dear Community,

 

I want to upload a locally created PBIX file to my pro account workspace. As I understand locally created files, cannot be imported to the workspace directly. It should be first go to one drive business and then to PBI server??!! 

 

I am quite confused at this moment. I want to automate these tasks using REST APIs:

 

1) Upload the locally created dashboard / report to a workspace.

2) Publish the report / dashboard from a workspace to an APP.

3) Share the APP with some specific users.

 

So, the goal is to share a locally created report/ dashboard with some users.

 

At this moment I'm doing research on how with REST APIs of PBI that would be possible. I use at this moment Postman and I found resources quite ambiguis. any hint will be highly appreciated. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, I am really appreciative of your reply. But I was looking for some REST API solution rather than Powershell.

 

Here is the solution:

 

 

groupId = "1c56b7fd-ea49-41db-8b96-xxx"
reportName = "yyy"
url = 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports?datasetDisplayName=' + reportName
headers = {
'Content-Type': 'multipart/form-data',
'authorization': 'Bearer ' + accessToken
}
file_location = './myreport.pbix'

# the second parameter is a tuple
# None means the filename is skipped (so the first parameter is the filename 🙂
# the second parameter is the file (in Nodejs shoubd be fs.createReadStream )
# and third parmeter is the format
files = {'value': (None, open(file_location, 'rb'), 'multipart/form-data')}
# we cannot send binary file to the server
# it needs to be converted to form-data using this function
mp_encoder = MultipartEncoder(fields=files)
# data parameters shows that is a dashboard / binary file
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
)

@mwegener 

View solution in original post

4 REPLIES 4

Hi @Anonymous,


If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

Hi, I am really appreciative of your reply. But I was looking for some REST API solution rather than Powershell.

 

Here is the solution:

 

 

groupId = "1c56b7fd-ea49-41db-8b96-xxx"
reportName = "yyy"
url = 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports?datasetDisplayName=' + reportName
headers = {
'Content-Type': 'multipart/form-data',
'authorization': 'Bearer ' + accessToken
}
file_location = './myreport.pbix'

# the second parameter is a tuple
# None means the filename is skipped (so the first parameter is the filename 🙂
# the second parameter is the file (in Nodejs shoubd be fs.createReadStream )
# and third parmeter is the format
files = {'value': (None, open(file_location, 'rb'), 'multipart/form-data')}
# we cannot send binary file to the server
# it needs to be converted to form-data using this function
mp_encoder = MultipartEncoder(fields=files)
# data parameters shows that is a dashboard / binary file
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
)

@mwegener 

Hi @Anonymous ,

please mark your post as solution, this will also help others.
Please give Kudos for support.

 

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Hi @Anonymous ,

 

look at this.

Microsoft Power BI Cmdlets for Windows PowerShell and PowerShell Core

https://docs.microsoft.com/en-us/powershell/power-bi/overview?view=powerbi-ps

 

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

 

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


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.