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

Don'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.

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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.