Forum Discussion
Help In Editing Data Source Credentials in PowerShell for Power BI Embedded Dashboards in D365 CRM
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/f1181856-de29-4a9a-a555-a0e181cd7898" -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!
Inogic Professional Services: Power Platform/Dynamics 365 CRM
An expert technical extension for your techno-functional business needs
Drop an email at email address removed for privacy reasons
Service: https://www.inogic.com/services/
Tips and Tricks: https://www.inogic.com/blog/
1 Reply
- Andres-BohrenSteel Contributor
Hi Sam_Kumar
https://stackoverflow.com/questions/77939584/how-to-do-the-authentication-to-run-power-bi-rest-api-in-an-azure-function-powe
Login-PowerBIServiceAccountInvoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/admin/dataflows' -Method GET
or if you have the Access Token use it in the Headers
$headers = @{ Authorization = "Bearer $accessToken" }
$Result = Invoke-WebRequest -Uri $Url -Method GET -Headers $headers
Kind Regards
Andres