Forum Discussion
Dataset refresh error Service principal
- 6 years ago
Hi Anonymous ,
The gateway used here is a deafult gateway which internally microsoft using for all the dataset. First use the below script in your local and use the fiddler to catch the exact error message. There are several reasons for bad reqeust. Find what is the reason for the bad request from the fiddler.
$applicationId = "" # Need to pass the clientid from devops variable $clientsec = "" | ConvertTo-SecureString -AsPlainText -Force # Need to pass from devops secret variable $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "" # Need to pass from devops variable $workspacename="PowerBI_CICD_PROD" $datasetname="AdventureReports" ## user credentials $username= "sadmin" $password= "Password@123" # Need to pass from devops secret variable ##Getworksapce $workspace =Get-PowerBIWorkspace -Name $workspacename # GetDataSets $DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json # Get DataSet $datasets = $DatasetResponse.value foreach($dataset in $datasets){ if($dataset.name -eq $datasetname){ $datasetid= $dataset.id; break; } } ## Take Over DataSet Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.TakeOver" -Method Post ## update data source credentials $BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json $UpdateUserCredential = @{ credentialType ="Basic" basicCredentials = @{ username= $username password=$password } } | ConvertTo-Json Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $UpdateUserCredential | ConvertFrom-Json
Hi Anonymous ,
Once you deployed your dataset in powerbi service. You have to modify the sql credentails in order to do the refresh.
Please see my below article, where i explained in sequence order on how to do that
https://community.powerbi.com/t5/Community-Blog/PowerBI-CICD-using-Azure-DevOps/ba-p/769244
Jayendran i did a try to update the credentials with your script and my parameters, but i always receive the error message:
"Message : Response status code does not indicate success: 400 (Bad Request).
StackTrace : at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.<InvokeRestMethod>d__31.MoveNext()
Exception : System.Net.Http.HttpRequestException
"
Is it possible to change the credentails when you use a connection to Azure sql database, because you don't use a gateway for that?
The strange thing is that when i manually take over the dataset, i can manually refresh the dataset. And also the service principal can do a refresh, after i have been take over the dataset.
- Jayendran6 years agoSolution Sage
Hi Anonymous ,
The gateway used here is a deafult gateway which internally microsoft using for all the dataset. First use the below script in your local and use the fiddler to catch the exact error message. There are several reasons for bad reqeust. Find what is the reason for the bad request from the fiddler.
$applicationId = "" # Need to pass the clientid from devops variable $clientsec = "" | ConvertTo-SecureString -AsPlainText -Force # Need to pass from devops secret variable $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "" # Need to pass from devops variable $workspacename="PowerBI_CICD_PROD" $datasetname="AdventureReports" ## user credentials $username= "sadmin" $password= "Password@123" # Need to pass from devops secret variable ##Getworksapce $workspace =Get-PowerBIWorkspace -Name $workspacename # GetDataSets $DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json # Get DataSet $datasets = $DatasetResponse.value foreach($dataset in $datasets){ if($dataset.name -eq $datasetname){ $datasetid= $dataset.id; break; } } ## Take Over DataSet Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.TakeOver" -Method Post ## update data source credentials $BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json $UpdateUserCredential = @{ credentialType ="Basic" basicCredentials = @{ username= $username password=$password } } | ConvertTo-Json Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $UpdateUserCredential | ConvertFrom-Json- Anonymous6 years agoNot applicable
thanks for the fiddler tip.
The update with the credentails is working now. and i can refresh with the service principal.
It is strange that when i did a take over with my account i can refresh the dataset without entering the credentials. But it is solved.
Thank you.
- markharing5 years agoFrequent Visitor
Hi Jayendran,
I have read your blog and answer above but I still have no idea what to do next;
(BTW: your script is not available anymor in the gallery so I cant get it there; https://gallery.technet.microsoft.com/AzureDevOps-CICD-for-fefd58b8)
- xli629b4 years agoHelper II
I'm also trying to update credentials for a cloud data source as a service principal. I tried finding the default gateway (the one that isn't one of my own on-premises gateways) which was used by the data source. However, when I call Updata Datasource on this default gateway with the new credentials, I always get:
{ "error": { "code": "DM_GWPipeline_Gateway_DataSourceAccessError", "pbi.error": { "code": "DM_GWPipeline_Gateway_DataSourceAccessError", "parameters": {}, "details": [], "exceptionCulprit": 1 } } }
However, Update Datasource works fine if I use it on a data source on an actual on-premises gateway. I'm wondering if this is an inherent limitation of cloud data sources because I see that this says "Cloud data sources and their corresponding credentials are managed at the user level."