Product: PowerShell Universal
Version: 3.3.6
I’m trying to set an array variable’s value through a POST to the /api/v1/variable and having minimal luck. Every time I do it the value gets reset to System.Collections.ArrayList and the type gets reset to String.
I’ve also noticed that the GET method requires you to run it through a PowerShell CLI XML converter (i.e. ConvertFrom-PSFClixml).
Can the variable endpoint be updated to be more REST API-like?
# Example of retrieving an array value
$previousParams = @{
Uri = 'https://localhost/api/v1/variable/teams'
Headers = $adminHeaders
}
$teams = Invoke-RestMethod @previousParams | Select-Object -ExpandProperty value | ConvertFrom-PSFClixml
# How I would expect to have to interact with this (no ConvertFrom-PSFClixml)
$previousParams = @{
Uri = 'https://localhost/api/v1/variable/teams'
Headers = $adminHeaders
}
$teams = Invoke-RestMethod @previousParams | Select-Object -ExpandProperty value
# example of TRYING to update, but unable to do so successfully -
# the string value matches the retrieved value when the set through the UI
$resetParams = @{
Uri = 'https://localhost/api/v1/variable'
Method = 'PUT'
Body = @{
name = 'Teams'
value = ([Object[]]@('a', 'b', 'c') | ConvertTo-PSFClixml -NoCompression)
type = 'Object[]'
} | ConvertTo-Json
ContentType = 'application/json'
Headers = $adminHeaders
}
Invoke-RestMethod @resetParams
# How I would expect to interact with this
$resetParams = @{
Uri = 'https://localhost/api/v1/variable/teams'
Method = 'PUT'
Body = @{
value = @('a', 'b', 'c')
}
Headers = $adminHeaders
}
Invoke-RestMethod @resetParams