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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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