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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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