Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
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! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
10 | |
4 | |
3 | |
2 | |
2 |