Public/Set-JoinableCollection.ps1
|
<# .SYNOPSIS Updates an existing joinable collection in the Fortytwo Collections API. .DESCRIPTION This function updates an existing joinable collection in the Fortytwo Collections API. #> function Set-JoinableCollection { [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [System.Collections.Hashtable]$Collection, [Parameter(Mandatory = $false)] [string]$Id = $null ) process { # Test that the collection has members if (!$Collection.ContainsKey("id") -or [string]::IsNullOrEmpty($Collection.id)) { if ([string]::IsNullOrEmpty($Id)) { throw "The collection object must contain a valid 'id' property or the 'Id' parameter must be provided." } else { $Collection["id"] = $Id } } $URI = $Script:APIRoot -f "collections-joinable", "/$($Collection.id)" $Body = $Collection | Select-Object -ExcludeProperty id | ConvertTo-Json -Depth 10 Write-Verbose "Updating Joinable Collection with at URI: $URI" $Result = Invoke-RestMethod -Method Put -Uri $URI -Headers (Get-CollectionHeader) -Body $Body -ContentType "application/json" if ($Result.IsSuccess) { Write-Verbose "Successfully updated Joinable Collection" } else { if (!$Result.Errors) { if ($StatusCode -eq 403) { throw "Access denied. Please ensure that your access token has the necessary permissions to access Fortytwo Collections." } else { throw "Failed to update Joinable Collections object. StatusCode: $StatusCode" } } throw $($Result.Errors -join '; ') } } } |