Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hello,
We are currently migrating Power BI embedded dashboards from one Dynamics 365 CRM tenant to another. The process involves creating a new Power BI report within a workspace. Since the Dynamics 365 Solution does not support the inclusion of Power BI reports within unmanaged solutions, we have resorted to using PowerShell scripting to manage the migration.
During this migration, we encountered an issue where the report IDs from the original environment remained linked when moving the Power BI embedded dashboards to the new environment. To address this, we have utilized Environment Variables to map the new report and workspace IDs appropriately.
However, we are facing an issue when attempting to edit the Data Source Credentials using PowerShell scripting. Specifically, we are receiving a "Bad Request" error, as shown in the screenshot below.
Here is the PowerShell code we are currently using to edit the Data Source Credentials:
Connect-PowerBIServiceAccount
$accesstoken = Get-PowerBIAccessToken
$patchBody = '"credentialDetails": {
"credentials": {"accessToken":"'+$($accesstoken)+'"},
"encryptedConnection": "Encrypted",
"encryptionAlgorithm": "None",
"privacyLevel": "Organizational",
"useEndUserOAuth2Credentials": true
}'
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/gateways/9eaed562-e9c2-46e4-91cf-276ed0947b41/datasources/f118185..." -Method Patch -Body $patchBody
We would greatly appreciate any guidance or suggestions on resolving this error in the PowerShell scripting process for updating the Data Source Credentials.
Thanks!
Solved! Go to Solution.
Hi,
Thanks so much for all your help and suggestions. After trying the different recommendations, we followed these steps, and it resolved the issue:
$body = @{
"credentialDetails" = @{
"credentialType" = "OAuth2"
"encryptedConnection" = "Encrypted"
"encryptionAlgorithm" = "None"
"privacyLevel" = "Organizational"
"useCallerAADIdentity" = $true
}
}
# Convert the body to JSON format
$jsonBody = $body | ConvertTo-Json -Depth 5
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/gateways/$($datasource.GatewayId)/datasources/$($datasource.Datas..." -Method PATCH -Body $jsonBody
I appreciate the time you all took to assist me.
Thanks!
Hi,
Thanks so much for all your help and suggestions. After trying the different recommendations, we followed these steps, and it resolved the issue:
$body = @{
"credentialDetails" = @{
"credentialType" = "OAuth2"
"encryptedConnection" = "Encrypted"
"encryptionAlgorithm" = "None"
"privacyLevel" = "Organizational"
"useCallerAADIdentity" = $true
}
}
# Convert the body to JSON format
$jsonBody = $body | ConvertTo-Json -Depth 5
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/gateways/$($datasource.GatewayId)/datasources/$($datasource.Datas..." -Method PATCH -Body $jsonBody
I appreciate the time you all took to assist me.
Thanks!
Hi @SamInogic ,
Could you please provide the following info for the further troubleshooting?
Whether the gateway and data source IDs used in the endpoint URL are correct and accessible within the new tenant?
Whether the account you are using has the necessary permissions for updating data source credential?
# Connect to the Power BI Service # Get Access Token # Construct the request body # Convert the request body to JSON # API Endpoint (replace with your specific gateway and data source ID) # Send the PATCH request |
Best Regards
That's patching the credentials for the gateway connection, not for the semantic model?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
12 | |
3 | |
3 | |
2 | |
2 |