Resources/RelatedItems.ps1
function New-ITGlueRelatedItems { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', ` 'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')] [string]$resource_type, [Parameter(Mandatory = $true)] [int64]$resource_id, [Parameter(Mandatory = $true)] $data ) $resource_uri = ('/{0}/{1}/relationships/related_items' -f $resource_type, $resource_id) $body = @{} $body += @{'data'= $data} $body = ConvertTo-Json -InputObject $body -Depth $ITGlue_JSON_Conversion_Depth try { $ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password) $rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers ` -body $body -ErrorAction Stop -ErrorVariable $web_error } catch { Write-Error $_ } finally { [void] $ITGlue_Headers.Remove('x-api-key') # Quietly clean up scope so the API key doesn't persist } $data = @{} $data = $rest_output return $data } function Set-ITGlueRelatedItems { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', ` 'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')] [string]$resource_type, [Parameter(Mandatory = $true)] [int64]$resource_id, [Parameter(Mandatory = $true)] [int64]$id, [Parameter(Mandatory = $true)] $data ) $resource_uri = ('/{0}/{1}/relationships/related_items/{2}' -f $resource_type, $resource_id, $id) $body = @{} $body += @{'data' = $data} $body = ConvertTo-Json -InputObject $body -Depth $ITGlue_JSON_Conversion_Depth try { $ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password) $rest_output = Invoke-RestMethod -method 'PATCH' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers ` -body $body -ErrorAction Stop -ErrorVariable $web_error } catch { Write-Error $_ } finally { [void] $ITGlue_Headers.Remove('x-api-key') # Quietly clean up scope so the API key doesn't persist } $data = @{} $data = $rest_output return $data } function Remove-ITGlueRelatedItems { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', ` 'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')] [string]$resource_type, [Parameter(Mandatory = $true)] [int64]$resource_id, [Parameter(Mandatory = $true)] $data ) $resource_uri = ('/{0}/{1}/relationships/related_items' -f $resource_type, $resource_id) $body = @{} $body += @{'data' = $data} $body = ConvertTo-Json -InputObject $body -Depth $ITGlue_JSON_Conversion_Depth try { $ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password) $rest_output = Invoke-RestMethod -method 'DELETE' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers ` -body $body -ErrorAction Stop -ErrorVariable $web_error } catch { Write-Error $_ } finally { [void] $ITGlue_Headers.Remove('x-api-key') # Quietly clean up scope so the API key doesn't persist } $data = @{} $data = $rest_output return $data } |