Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Aethen2
New Member

UpdateDetails: Must be a non-empty collection

Hello everyone, im trying to update the datasource on some datasets, but i get the error in the title, it happens when i try to send a petition to this endpoint:

https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}/Default.UpdateDatasources
 
Im doing this with Powershell, and im constructing the json as an object first and then transforming it as a json, i created the file and passed it through jsonlint and it was okay, i've also checked the field UpdateDetails and its obviously not empty, to be honest, im kind of lost because there's also almost 0 information about this on the network.
 
This is my code:

Spoiler
Import-Module powershell-yaml
$AccessTokenParams = @{grant_type='refresh_token';refresh_token='my_refresh_token';client_id='my_app_client_id';client_secret='my_app_secret';scope='https://analysis.windows.net/powerbi/api/.default'}
$AccessToken = @{Authorization='Bearer ' + (Invoke-WebRequest -Uri https://login.microsoftonline.com/common/oauth2/v2.0/token -Method Post -Body $AccessTokenParams | ConvertFrom-Json).access_token}

$datasetIdList = ((((Invoke-WebRequest -Uri https://api.powerbi.com/v1.0/myorg/groups/{groupid}/reports -Method Get -Headers $AccessToken).Content) | ConvertFrom-Yaml).value).datasetId
foreach ($dataset in $datasetIdList)
{
$datasource = ((Invoke-WebRequest -Uri https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/$dataset/datasources -Method Get -Headers $AccessToken).Content)
if (-Not ($datasource -like "*unwantedsourcetochange1*") -And -Not ($datasource -like "*unwantedsourcetochange2*") -And -Not ([string]::IsNullOrEmpty(($datasource | ConvertFrom-Yaml).value))) {
$datasource = $datasource.replace('oldstring','newstring')
$updateDetails= @()
$connectionList = ($datasource | ConvertFrom-Yaml).value.connectionDetails
foreach ($connection in $connectionList){
$server = $connection.server
$path = $connection.path
$connectionObject = [PSCustomObject]@{
"server" = $server
"path" = $path
}
$datasourceSelector = [PSCustomObject]@{
"datasourceSelector" = @{
"datasourceType" = "AzureDataLakeStorage"
"connectionDetails" = $connectionObject
}
}
$connectionDetails = [PSCustomObject]@{
"connectionDetails" = $connectionObject
}
$updateDetails += $datasourceSelector
$updateDetails += $connectionDetails
}
$json = [PSCustomObject]@{
"updateDetails" = @($updateDetails)
}
$json = $json | ConvertTo-Json -Depth 100
if ($dataset -eq "specific-datasetid-i-want-to-change-for-testing-purposes") {
Invoke-WebRequest -Uri https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{specific datasetid}/Default.UpdateDatasources -Method Post -Body $json -Headers $AccessToken
}
}
}
0 REPLIES 0

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.