I am using a custom function that imports data using an API. The function requires several different parameters, which I am currently defining with one $Params hashtable. From there I am adding other parameters that may or may not be added based on certain conditions. I have noticed that storing all parameters in the hashtable is not working properly, but will only work if particularly specified in the function call.
A basic version of the code that does not currently work is:
$ExtraParam = 'ccc'
$Params = @{
Par1 = 'aaa'
Par2 = 'bbb'
}
$Params.Par3 = $ExtraParam
Import-APIData @Params
The API is returning the following error message:
{"errorId":"error.request.invalidRepresentation.malformed","errorCode":0,"message":"Invalid parameter value was specified."}
However, if I run the following code it works perfectly fine:
$ExtraParam = 'abc'
$Params = @{
Par1 = '123'
Par2 = '456'
}
Import-APIData @Params -Par3 $ExtraParam
I have verified that the parameters coming into the function are all of the correct type. The custom function I am calling is proprietary so I cannot share the entire function, but I was just wondering if there was anything that would reformat the parameters in the hashtable as opposed to explicitly calling it in the function call. Given that the two chunks of code are essentially the same I am hoping someone can point out some fundamental difference that may cause the top portion to not work.
Per a request of a commenter, here is the actual function. The _CallAPI function at the bottom is what actually calls the API. I will not be able to share that, but using the $Params
output right above it (commented out in the code) may hopefully be enough to troubleshoot.
function Update-ICUser {
<#
.SYNOPSIS
Updates user on a Gensys ICWS server.
.PARAMETER ICSession
string ICSession. ICSession to update a user.
.PARAMETER Id
string Id. Id of the user to update.
.PARAMETER InputObject
object InputObject. Full IC User is needed.
.PARAMETER Argument
string Argument. Any query string parameters associated with the Api call.
.Example
$ICSession = New-ICSession -ComputerName server1 -Credential $Credential
Get-ICUser -Id user1 -Full |Update-ICUser -ICSession $ICsession -Extension 1234
Example 1: Update a user's extension.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory,
Position = 0)]
[ICSession]$ICSession,
[Parameter(Mandatory,
ValueFromPipeline,
ParameterSetName = 'InputObject',
Position = 1)]
[object]$InputObject,
[Parameter(Mandatory,
ParameterSetName = 'Manual',
Position = 2)]
[string]$Id,
[Parameter(ParameterSetName = 'Manual',
Position = 3)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$DisplayName,
[Parameter(ParameterSetName = 'Manual',
Position = 4)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$OutboundAni,
[Parameter(ParameterSetName = 'Manual',
Position = 5)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$Title,
[Parameter(ParameterSetName = 'Manual',
Position = 6)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$OfficeLocation,
[Parameter(ParameterSetName = 'Manual',
Position = 7)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$Notes,
[Parameter(ParameterSetName = 'Manual',
Position = 8)]
[Parameter(ParameterSetName = 'InputObject')]
[int]$Cost = 0,
[Parameter(ParameterSetName = 'Manual',
Position = 9)]
[Parameter(ParameterSetName = 'InputObject')]
[bool]$AutoAnswerAcdInteractions = $false,
[Parameter(ParameterSetName = 'Manual',
Position = 10)]
[Parameter(ParameterSetName = 'InputObject')]
[bool]$AutoAnswerNonAcdInteractions = $true,
[Parameter(ParameterSetName = 'Manual',
Position = 11)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$ApplicationId = 'InteractionDesktop',
[Parameter(ParameterSetName = 'Manual',
Position = 12)]
[Parameter(ParameterSetName = 'InputObject')]
[bool]$ExcludeFromDirectory = $false,
[Parameter(ParameterSetName = 'Manual',
Position = 13)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$Extension,
[Parameter(ParameterSetName = 'Manual',
Position = 14)]
[Parameter(ParameterSetName = 'InputObject')]
[bool]$FaxCapability = $false,
[Parameter(ParameterSetName = 'Manual',
Position = 15)]
[Parameter(ParameterSetName = 'InputObject')]
[bool]$OutlookIntegrationEnabled = $false,
[Parameter(ParameterSetName = 'Manual',
Position = 16)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$FirstName,
[Parameter(ParameterSetName = 'Manual',
Position = 17)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$LastName,
[Parameter(ParameterSetName = 'Manual',
Position = 18)]
[Parameter(ParameterSetName = 'InputObject')]
[string[]]$WorkgroupList,
[Parameter(ParameterSetName = 'Manual',
Position = 19)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$DepartmentName,
[Parameter(ParameterSetName = 'Manual',
Position = 20)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$City,
[Parameter(ParameterSetName = 'Manual',
Position = 21)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$PostalCode,
[Parameter(ParameterSetName = 'Manual',
Position = 22)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$State,
[Parameter(ParameterSetName = 'Manual',
Position = 23)]
[Parameter(ParameterSetName = 'InputObject')]
[string]$StreetAddress,
[Parameter(ParameterSetName = 'Manual',
Position = 24)]
[Parameter(ParameterSetName = 'InputObject')]
[int]$HomeSite,
[Parameter(ParameterSetName = 'Manual',
Position = 25)]
[Parameter(ParameterSetName = 'InputObject')]
[string[]]$LicenseList,
[Parameter(ParameterSetName = 'Manual',
Position = 26)]
[Parameter(ParameterSetName = 'InputObject')]
[string[]]$RoleList
)
Try {
if ($InputObject) {
$User = $InputObject
$Id = $InputObject.configurationId.id
}
else {
$User = Get-ICUser -ICSession $ICSession -Id $Id -Full
}
'Id','InputObject','ICSession' |Foreach-Object {
$PSBoundParameters.Remove($PSItem) |Out-Null
}
$PSBoundParameters.GetEnumerator() |Foreach-Object {
if ($PSItem.Key -in ('Title','DepartmentName','City','State','StreetAddress','FirstName','LastName','Notes')) {
if ($PSItem.Key -in ('State','FirstName','LastName')) {
$Key = switch ($PSItem.Key) {
'State' {'stateOrProvince'}
'FirstName' {'givenName'}
'LastName' {'surName'}
}
}
else {
$Key = $PSItem.Key
}
$User.personalInformationProperties.$Key = $PSItem.Value
}
elseif ($PSItem.Key -in ('WorkgroupList','LicenseList','RoleList')) {
$Key = $PSItem.Key
if ($Key = 'WorkgroupList' -and $WorkgroupList) {
[array]$Value = Get-ICWorkgroup -ICSession $SessionKey -Id $WorkgroupList
$User.Workgroups = $Value
}
if ($Key = 'LicenseList' -and $LicenseList) {
$Value = @((Get-ICLicenseAllocation -ICSession $SessionKey -Id $LicenseList).configurationId)
if ($User.licenseProperties.PSobject.Properties.name -match 'additionalLicenses') {
$User.licenseProperties.additionalLicenses = $Value
}
else {
$User.licenseProperties | Add-Member -MemberType NoteProperty -Name 'additionalLicenses' -Value $Value -Force
}
}
if ($Key = 'RoleList' -and $RoleList) {
[array]$Value = Get-ICRole -ICSession $SessionKey -Id $RoleList
if ($User.roles.PSobject.Properties.name -match 'actualValue') {
$User.Roles.actualValue = $Value
}
else {
$User.roles | Add-Member -MemberType NoteProperty -Name 'actualValue' -Value $Value -Force
}
}
}
else {
$Key = $PSItem.Key
$Value = $PSItem.Value
$User |Add-Member -MemberType NoteProperty -Name $Key -Value $Value -Force
}
}
$Body = $User |ConvertTo-Json -Depth 5
$Params = @{
Area = $Configuration.Area.Configuration
Resource = $Configuration.Resource.Users
ICSession = $ICSession
Id = $Id
Method = 'Put'
ContentType = 'application/json'
Body = $Body
}
# $Params
_CallApi @Params
}
Catch {
_ExceptionError
}
}
I will also provide everything on the console. In this example the $AutoAnswerAcd
parameter is the one that is failing, but I have gotten it to fail and work by adding/removing other parameters. I have not detected a pattern that makes it fail yet, other than that it always works outside of the splat. You can see this pattern below.
PS C:\> $SessionKey = New-ICSession -ComputerName $server -Credential $Credential
PS C:\> $Params = @{
>> ICSession = $SessionKey
>> Id = 'tautomation'
>> WorkgroupList = "MultiSite-UserSpan"
>> RoleList = "Business User"
>> LicenseList = "I3_ACCESS_RECORDER"
>> DepartmentName = "Infr & Ops"
>> Title = "Process Automation Engineer"
>> OfficeLocation = "Remote"
>> AutoAnswerAcdInteractions = $true
>> }
PS C:\> Update-ICUser @Params
Exception: C:\Repos\ICTools\Code\Private\_ExceptionError.ps1:10
Line |
10 | throw "$($Exception)`n$($Exception.Exception.Message)"
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| {"errorId":"error.request.invalidRepresentation.malformed","errorCode":0,"message":"Invalid parameter value was specified."} Response status code does not indicate
| success: 400 (Bad Request). {"errorId":"error.request.invalidRepresentation.malformed","errorCode":0,"message":"Invalid parameter value was specified."} Response status
| code does not indicate success: 400 (Bad Request).
PS C:\> $Params = @{
>> ICSession = $SessionKey
>> Id = 'tautomation'
>> WorkgroupList = "MultiSite-UserSpan"
>> RoleList = "Business User"
>> LicenseList = "I3_ACCESS_RECORDER"
>> DepartmentName = "Infr & Ops"
>> Title = "Process Automation Engineer"
>> OfficeLocation = "Remote"
>> }
PS C:\> Update-ICUser @Params
id uri
-- ---
tautomation /configuration/users/tautomation
PS C:\> Update-ICUser @Params -AutoAnswerAcdInteractions $true
id uri
-- ---
tautomation /configuration/users/tautomation
PS C:\>
Thanks!