maikvandergaag / msft-extensions

Repository for extensions mainly used for Azure DevOps Extensions
https://msftplayground.com
MIT License
125 stars 80 forks source link

Upload new report: Operation returned an invalid status code 'Unauthorized' #519

Open zhunipingan opened 10 months ago

zhunipingan commented 10 months ago

Describe the issue I have created the SP, and enabled the SP to access to PowerBI API in tenant settings, and set the SP as the admin of the workspace, but failed in uploading new .pbix report. The other operations such as 'create workspace, assign one user to the workspace and delete report' can be executed successfully. image image

image image

Extension

To Reproduce Steps to reproduce the behavior:

  1. Every time run the command will fail

Expected behavior I can upload the report use the service principle.

caiocesarrg commented 10 months ago

I'm experiencing the same issue, it works while creating a new workspace (even though nothing is created in my power bi portal). But when it comes to publishing a new or existing report, returns "Unalthorized" error

maikvandergaag commented 10 months ago

What permissions does the SP have on the Power BI Api's?

caiocesarrg commented 10 months ago

Hi, Maik

I gave these permissions to my Service Principal:

image

And these are the permissions I gave inside Power BI Admin Portal:

image

image

My Service Principal also has Admin role in my workspace:

image

I've ran many different tests to see if my Service Principal is really not configured the right way, but it's seems to be configured correctly. The Power BI Actions Task can create workspaces and refresh datasets without issues. However, I noticed it can upload the report only if the dataset is within the pbix file, because when I try to upload a report connected to a published dataset the task will show me this Unauthorized error message.

maikvandergaag commented 10 months ago

Ohh, now I understand. So you are trying to upload a report that is connected to another dataset. That is a situation I have never tested before so that could be the case.

I would have to test out this scenario. As I am not a Power BI Guru I will see If I can set up a scenario.

maikvandergaag commented 10 months ago

Can you maybe offer help?

caiocesarrg commented 10 months ago

Ohh, now I understand. So you are trying to upload a report that is connected to another dataset. That is a situation I have never tested before so that could be the case.

I would have to test out this scenario. As I am not a Power BI Guru I will see If I can set up a scenario.

That's correct!

I first uploaded a dataset and then deleted the report that's auto created by the portal so I can have only the semantic model on my workspace.

Then I connected a local pbix file to this dataset online and tried to publish it by cmdlet. Everything within the same workspace

caiocesarrg commented 10 months ago

Can you maybe offer help?

Sure! Let me know which tests you want to run

maikvandergaag commented 10 months ago

Would love some insights how to set up a scenario like that.

caiocesarrg commented 10 months ago

Would love some insights how to set up a scenario like that.

  1. Open a new PBIX file and create a data model from scratch without any visuals, only importing tables. In my case I imported 4 tables from my One Drive
  2. Upload this new semantic model (dataset) to the Power BI portal via Power BI Desktop interface, and delete the report create automatically
  3. Open a new PBIX file and connect it to this semantic model (dataset) you just created. Create some sample visuals and save the file
  4. Publish the "report PBIX" file to the Power BI portal via Power BI Powershell cmdlet (Here is where I'm getting that error message)

I'm seeing the same error message when using your extension on Azure DevOps or when using the Power BI Powershell cmdlet import command