Resources/Locations.ps1
function New-ITGlueLocations { Param ( [Parameter(Mandatory = $true)] [Int64]$org_id, [Parameter(Mandatory = $true)] $data ) $resource_uri = ('/organizations/{0}/relationships/locations/' -f $org_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 Get-ITGlueLocations { [CmdletBinding(DefaultParameterSetName = 'index')] Param ( [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [Parameter(ParameterSetName = 'show')] [Nullable[Int64]]$org_id = $null, [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [Nullable[Int64]]$filter_id = '', [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [String]$filter_name = '', [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [String]$filter_city = '', [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [Nullable[Int64]]$filter_region_id = '', [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [Nullable[Int64]]$filter_country_id = '', [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa', Mandatory = $true)] [ValidateSet('manage', 'autotask', 'tigerpaw', 'kaseya-bms', 'pulseway-psa', 'vorex')] [String]$filter_psa_integration_type = '', [Parameter(ParameterSetName = 'index_psa')] [String]$filter_psa_id = '', [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [ValidateSet( 'name', 'id', 'created_at', 'updated_at', ` '-name', '-id', '-created_at', '-updated_at')] [String]$sort = '', [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [Nullable[Int64]]$page_number = $null, [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [Nullable[int64]]$page_size = $null, [Parameter(ParameterSetName = 'show')] [Nullable[Int64]]$id = $null, [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'index_psa')] [Parameter(ParameterSetName = 'show')] [String]$include = '' ) $resource_uri = ('/locations/{0}' -f $id) if ($org_id) { $resource_uri = ('/organizations/{0}/relationships' -f $org_id) + $resource_uri } $body = @{} if (($PSCmdlet.ParameterSetName -eq 'index') -or ($PSCmdlet.ParameterSetName -eq 'index_psa')) { if ($filter_id) { $body += @{'filter[id]' = $filter_id} } if ($filter_name) { $body += @{'filter[name]' = $filter_name} } if ($filter_city) { $body += @{'filter[city]' = $filter_city} } if ($filter_region_id) { $body += @{'filter[region_id]' = $filter_region_id} } if ($filter_country_id) { $body += @{'filter[country_id]' = $filter_country_id} } if ($filter_psa_integration_type) { $body += @{'filter[psa_integration_type]' = $filter_psa_integration_type} } if ($sort) { $body += @{'sort' = $sort} } if ($page_number) { $body += @{'page[number]' = $page_number} } if ($page_size) { $body += @{'page[size]' = $page_size} } } if ($PSCmdlet.ParameterSetName -eq 'index_psa') { $body += @{'filter[psa_id]' = $filter_psa_id} } if($include) { $body += @{'include' = $include} } 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 'GET' -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-ITGlueLocations { [CmdletBinding(DefaultParameterSetName = 'update')] Param ( [Parameter(ParameterSetName = 'update')] [Nullable[Int64]]$id = $null, [Parameter(ParameterSetName = 'update')] [Nullable[Int64]]$org_id = $null, [Parameter(ParameterSetName = 'bulk_update')] [Nullable[Int64]]$filter_id = $null, [Parameter(ParameterSetName = 'bulk_update')] [String]$filter_name = '', [Parameter(ParameterSetName = 'bulk_update')] [String]$filter_city = '', [Parameter(ParameterSetName = 'bulk_update')] [Nullable[Int64]]$filter_region_id = $null, [Parameter(ParameterSetName = 'bulk_update')] [Nullable[Int64]]$filter_country_id = $null, [Parameter(ParameterSetName = 'update')] [Parameter(ParameterSetName = 'bulk_update')] [Parameter(Mandatory = $true)] $data ) $resource_uri = ('/locations/{0}' -f $id) if ($org_id) { $resource_uri = ('organizations/{0}/relationships/locations/{1}' -f $org_id, $id) } $body = @{} if ($PSCmdlet.ParameterSetName -eq 'bulk_update') { if($filter_id) { $body += @{'filter[id]' = $filter_id} } if($filter_name) { $body += @{'filter[name]' = $filter_name} } if($filter_city) { $body += @{'filter[city]' = $filter_city} } if($filter_region_id) { $body += @{'filter[region_id]' = $filter_region_id} } if($filter_country_id) { $body += @{'filter[country_id]' = $filter_country_id} } } $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-ITGlueLocations { [CmdletBinding(DefaultParameterSetName = 'bulk_destroy')] Param ( [Parameter(ParameterSetName = 'bulk_destroy')] [Nullable[Int64]]$filter_id = $null, [Parameter(ParameterSetName = 'bulk_destroy')] [String]$filter_name = '', [Parameter(ParameterSetName = 'bulk_destroy')] [String]$filter_city = '', [Parameter(ParameterSetName = 'bulk_destroy')] [Nullable[Int64]]$filter_region_id = $null, [Parameter(ParameterSetName = 'bulk_destroy')] [Nullable[Int64]]$filter_country_id = $null, [Parameter(ParameterSetName = 'update')] [Parameter(ParameterSetName = 'bulk_destroy')] [Parameter(Mandatory = $true)] $data ) $resource_uri = ('/locations/') $body = @{} if ($PSCmdlet.ParameterSetName -eq 'bulk_destroy') { if($filter_id) { $body += @{'filter[id]' = $filter_id} } if($filter_name) { $body += @{'filter[name]' = $filter_name} } if($filter_city) { $body += @{'filter[city]' = $filter_city} } if($filter_region_id) { $body += @{'filter[region_id]' = $filter_region_id} } if($filter_country_id) { $body += @{'filter[country_id]' = $filter_country_id} } } $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 } |