Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hi all,
I am trying to automate the powerbi deployments using TFS 2019. In which I need to check in the .pbix file then after deploying to different environments like QA, UAT, PROD, I need to update the connection string of the data source. For this purpose, I have created one Service principal in the Azure portal and added it to the TFS 2019. So all report\dataset deployments will be done by this service principal. This part is working fine. Now I need to create Power shell scripts to execute the PowerBI APIs. I can connect, login to the powerbi account using my service principal. I have registered an app in the Azure portal and provided all permission. I also created a security group in azure and added this service principal to this security group. In the power BI admin portal, I am using this security group to restrict the permissions. Now I can perform all GET methods without any exception. But when I try to update the dataset connection string and update the gateway using the powerBI API post method, I am getting the 403 (forbidden) exception or "Cannot add value because header 'Authorization' does not support multiple values.".
As per the API document (), Dataset.ReadWrite.All are required to execute the API. Is it required to get the auth token specifically for this scope? How can I get the auth code for this particular scope?
Code to get the token
$clientId ='my client Id';
$clientSecret = ConvertTo-SecureString "my client secret" -AsPlainText -Force ;
$spCredentials =New-Object System.Management.Automation.PSCredential($clientId, $clientSecret);
$account = Login-PowerBI -ServicePrincipal -TenantId $tenantId -Credential $spCredentials -ErrorAction: Stop;
Code to update the gateway binding
$bindToDSUrl= ' https://api.powerbi.com/v1.0/myorg/datasets/{datasetid}/Default.BindToGateway'
$bindToDSData = '{
"gatewayObjectId": "gateway object id",
"datasourceObjectIds": [
"{datasourceId}"
]
}';
$headers = @{
'Authorization' = (Get-PowerBIAccessToken -AsString);
}
$res = Invoke-PowerBIRestMethod -Url:$bindToDSUrl -Method:Post -Headers: $headers -Body:$bindToDSData -ContentType 'application/json; charset=utf-8' -Verbose -ErrorAction:Stop
now getting the following exception
Cannot add value because header 'Authorization' does not support multiple values.
code to update the datasource
$dsSourceUrl = 'datasets/{datasetid}/Default.UpdateDatasources';
$dsDataJson = '{"updateDetails": [{"datasourceSelector": {"datasourceType": "Sql","connectionDetails": {"server": "newDBServer","database": "TestDB"}},"connectionDetails": {"server": "newDBServer","database": "TestDB_Prod"}}]}';
$rr= Invoke-PowerBIRestMethod -Url:$dsSourceUrl -Method:Post -Body:$dsDataJson -Headers:$headers -ContentType:'application/json; charset=utf-8' -Verbose
now getting 403 exceptions.
Can you please help me if there is any update on this?
Hi @Anonymous ,
It seems the access token in http requesct has issue, Could you please check the format of Authorization in Header, it should be "Bear: XXXXXXX". Or you can try to verify it by posting this request with a constant pre-genrate access token.
Best regards,
Hi v-lid-msft,
The auth token is proper. Please find the attached files. How can I get the "pre-genrate access token"403 issue
Auth token
Was there a solution to this as I am facing the same issue. Thanks.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 8 | |
| 8 | |
| 7 |