maikvandergaag / msft-extensions

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

PowerBIActions UpdateParameters returns InvalidRequest #358

Closed romosandarius closed 2 years ago

romosandarius commented 2 years ago

We've been working on implementing the UpdateParameters task and it returns InvalidRequest. So either we are configuring it incorrectly or there is a bug in it. Can anyone help?

Below you can see our yaml definition:

- task: PowerBIActions@5
    inputs:
      PowerBIServiceEndpoint: 'bcea-dp-svcPowerBI-dev'
      Action: 'UpdateParameters'
      WorkspaceName: '$(workspace_dev)'
      DatasetName: 'Value and Volume monitor'
      ParameterInput: "[{'name':'server_host_name', 'newValue':'adb1'}]"

When we run the task, we get the following after enabling system.debug=true and obfuscating the group and dataset ID.

Trying to update the dataset parameters
Getting Power BI Workspace properties; Payment Insights DEV
##[debug]1:55:36 PM - Get-PowerBIWorkspace begin processing with ParameterSet Name.
##[debug]1:55:36 PM - Cmdlet version: 1.0.896.0
##[debug]Request Uri: https://api.powerbi.com/v1.0/myorg/groups?$filter=tolower(name) eq 'payment insights dev'&$top=100
##[debug]Status Code: OK (200)
##[debug]1:55:36 PM - Get-PowerBIWorkspace end processing.
##[debug]Processed: ##vso[task.setvariable variable=PowerBIActions.WorkspaceId]<value-obfuscated>
##[debug]1:55:36 PM - Get-PowerBIAccessToken begin processing with ParameterSet __AllParameterSets.
##[debug]1:55:36 PM - Cmdlet version: 1.0.896.0
##[debug]1:55:36 PM - Get-PowerBIAccessToken end processing.
##[debug]Trying to invoke api: https://api.powerbi.com/v1.0/myorg/groups/<value-obfuscated>/datasets
##[debug]GET https://api.powerbi.com/v1.0/myorg/groups/<value-obfuscated>/datasets with 0-byte payload
##[debug]received -1-byte response of content type application/json; odata.metadata=minimal; odata.streaming=true
##[debug]Trying to find dataset 'Value and Volume monitor'
Processing dataset - Value and Volume monitor
##[debug]1:55:37 PM - Get-PowerBIAccessToken begin processing with ParameterSet __AllParameterSets.
##[debug]1:55:37 PM - Cmdlet version: 1.0.896.0
##[debug]1:55:37 PM - Get-PowerBIAccessToken end processing.
##[debug]Trying to invoke api: https://api.powerbi.com/v1.0/myorg/groups/<value-obfuscated>/datasets/<value-obfuscated>/parameters
##[debug]GET https://api.powerbi.com/v1.0/myorg/groups/<value-obfuscated>/datasets/<value-obfuscated>/parameters with 0-byte payload
##[debug]received -1-byte response of content type application/json; odata.metadata=minimal; odata.streaming=true
##[debug]1:55:37 PM - Get-PowerBIAccessToken begin processing with ParameterSet __AllParameterSets.
##[debug]1:55:37 PM - Cmdlet version: 1.0.896.0
##[debug]1:55:37 PM - Get-PowerBIAccessToken end processing.
##[debug]Trying to invoke api: https://api.powerbi.com/v1.0/myorg/groups/<value-obfuscated>/datasets/<value-obfuscated>/Default.UpdateParameters
##[debug]POST https://api.powerbi.com/v1.0/myorg/groups/<value-obfuscated>/datasets/<value-obfuscated>/Default.UpdateParameters with -1-byte payload
Done processing Power BI Actions
##[debug]Caught exception from task script.
##[debug]Error record:
##[debug]Invoke-API : InvalidRequest
##[debug]At D:\a\_tasks\PowerBIActions_d5b7fec6-2b25-4742-905b-0dad97687df5\5.4.25\ps_modules\PowerBI\PowerBI.psm1:238 char:9
##[debug]+         Invoke-API -Url $url -Method "Post" -Body $body -ContentType  ...
##[debug]+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[debug]    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
##[debug]    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-API
##[debug] 
##[debug]Script stack trace:
##[debug]at Invoke-API, D:\a\_tasks\PowerBIActions_d5b7fec6-2b25-4742-905b-0dad97687df5\5.4.25\ps_modules\PowerBI\PowerBI.psm1: line 307
##[debug]at Update-PowerBIDatasetParameter, D:\a\_tasks\PowerBIActions_d5b7fec6-2b25-4742-905b-0dad97687df5\5.4.25\ps_modules\PowerBI\PowerBI.psm1: line 238
##[debug]at Update-PowerBIDatasetParameters, D:\a\_tasks\PowerBIActions_d5b7fec6-2b25-4742-905b-0dad97687df5\5.4.25\ps_modules\PowerBI\PowerBI.psm1: line 261
##[debug]at <ScriptBlock><Process>, D:\a\_tasks\PowerBIActions_d5b7fec6-2b25-4742-905b-0dad97687df5\5.4.25\run.ps1: line 196
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]at <ScriptBlock>, <No file>: line 22
##[debug]at <ScriptBlock>, <No file>: line 18
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]Microsoft.PowerShell.Commands.WriteErrorException: InvalidRequest
##[error]InvalidRequest
##[debug]Processed: ##vso[task.logissue type=error]InvalidRequest
##[debug]Processed: ##vso[task.complete result=Failed]

If we take the same json payload and run on the PowerBI REST API documentation page, it succeeds with return code 200: Link: https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/update-parameters-in-group image

And then the parameter is updated: image

maikvandergaag commented 2 years ago

Hi,

The extension it self has some checks on existing parameters and then extends it. Could you tell me with what you are doing the action via the task en manually.

Besides that are you running on a hosted agent?

romosandarius commented 2 years ago

Hi,

Our flow looks like:

  1. Upload the PowerBI report using the Publish action
  2. Update existing parameters which can be empty or might have some values already. But the parameters are predefined on the dataset.

We are running on a hosted agent (windows-latest).

maikvandergaag commented 2 years ago

Is it done my a service principal or user account

romosandarius commented 2 years ago

We are using a service principal. We've followed the instructions from Azure docs to set it up: https://docs.microsoft.com/en-us/power-bi/admin/service-premium-service-principal

maikvandergaag commented 2 years ago

The test with what account did you perform that?

romosandarius commented 2 years ago

I used my own account to test from https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/update-parameters-in-group

maikvandergaag commented 2 years ago

Ok, then there can be a difference for what the Service Principal can do and what you user account can do. Did you try to perform the powershell scripts locally?

romosandarius commented 2 years ago

No, I haven't. I'll give it a go and write back tomorrow.

romosandarius commented 2 years ago

I managed to run the code locally after a few edits in the scripts and now it fails at the step before doing the POST to Default.UpdateParameters. The GET on .../parameters fails with InvalidRequest. image

TimEllens commented 2 years ago

@romosandarius I had the same issue and wanted to comment here to get an answer as well. But I figured it out in the meantime.

Two issues blocked it for me:

Providing Ownership of the datasets in the workspace to the service principal + changing the parameter to a text value without any lists behind it made it work for me.

romosandarius commented 2 years ago

@TimEllens, thank you for sharing the info! It actually worked as you suggested where I managed to update the parameters with the following two actions:

                displayName: 'Taking dataset ownership'
                inputs:
                  PowerBIServiceEndpoint: 'bcea-dp-svcPowerBI-dev'
                  Action: 'TakeOwnership'
                  WorkspaceName: '$(workspace_dev)'
                  DatasetName: 'Client Value and Volume'
              - task: PowerBIActions@5
                displayName: 'Updating parameters for Client Value and Volumne'
                inputs:
                  PowerBIServiceEndpoint: 'bcea-dp-svcPowerBI-dev'
                  Action: 'UpdateParameters'
                  WorkspaceName: '$(workspace_dev)'
                  DatasetName: "Client Value and Volume"
                  ParameterInput: "{'name':'server_host_name', 'newValue':'adb2'}"

The challenge is though that we have another ongoing issue where we need a normal Active Directory user (irrespective of MFA setup) to own the dataset, otherwise we're hit by the below error: image

@maikvandergaag, do you have any ideas why we cannot update the parameters even though the service principal is Admin on the dataset's workspace?

maikvandergaag commented 2 years ago

Not sure, then we would have to dive deeper into your specific request. @mattias-de-coninck: do you have an idea

mattias-de-coninck commented 2 years ago

@romosandarius could you perhaps show us what the Show Details link points to?

romosandarius commented 2 years ago

@mattias-de-coninck , it points to the front page of the PowerBI service so there's no useful information, unfortunately.