Help with REST API values

I am seeing an inconsistency in my New-UdCharts, when populating with values from REST API calls. Now this may be a general REST API issue, but hoping someone can point me in the right direction.

I am creating a pie chart with the following code

New-UDColumn -Size 4 -Content {
            New-UDChart -Title "Storage - DB"  -Type Doughnut -AutoRefresh -RefreshInterval 60 -BackgroundColor $BackgroundColor -FontColor $FontColor -Endpoint {
                $storage = @();
                $storage += [PSCustomObject] @{ "Space" = "TotalSize"; "Count" = [Math]::round(((Invoke-RestMethod -headers $session -method GET -uri $dbFree).value.data[1]) / 1GB)}
                $storage += [PSCustomObject] @{ "Space" = "Used"; "Count" = [Math]::round(((Invoke-RestMethod -headers $session -method GET -uri $dbUsed).value.data[1]) / 1GB)}
                $storage | Out-UDChartData -LabelProperty Space -Dataset @(New-UDChartDataset -DataProperty Count -Label "GB" -BackgroundColor @("#24ad1d", "#4085ed") -HoverBackgroundColor @("#24ad1d", "#4085ed"))
            } -Options @{cutoutPercentage = 50}
        }

sometimes the chart displays correctly, but other times there is no data. So I checked the variable for say $dbfree and it was returning


10181944

so it looked like there was a space being returned in there somewhere, so i used

$storage += [PSCustomObject] @{ "Space" = "TotalSize"; "Count" = [Math]::round(((Invoke-RestMethod -headers $session -method GET -uri $dbFree).value.data[1]) / 1GB)}

but the chart is still not displaying the data, on reload.

Any suggestions?

.Trim()

can help with that. It will remove every new line, tab or space in front or the back of a string.
It should look like this

[Math]::round(((Invoke-RestMethod -headers $session -method GET -uri $dbUsed).value.data[1]).Trim() / 1GB)

thanks for that, very useful. But it does look like a bug with API source, waiting on confirmation. In the meantime .Trim() it is :slight_smile: