diff --git a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 index 4fedbef..5f66bdf 100644 --- a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 +++ b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 @@ -35,7 +35,6 @@ } #To support images "image" property have be handled before this - if($Body) { $body = $Body | ConvertTo-Json } $_headers = @{ "Authorization" = "Bearer $($token)" @@ -60,9 +59,24 @@ Headers = $_headers UseBasicParsing = $true ErrorAction = 'SilentlyContinue' + Proxy = 'http://localhost:8080' } - if ($Body) {$splatParameters["Body"] = [System.Text.Encoding]::UTF8.GetBytes($Body)} + #Place holder for intended image manipulation + # if and when snipe it API gets support for images + if($null -ne $body -and $Body.Keys -contains 'image' ){ + if($PSVersionTable.PSVersion -ge 7){ + $Body['image'] = get-item $body['image'] + $splatParameters["Form"] = $Body + } else { + write-warning "Setting images is supported only with powershell version 7 or greater" + $Body.Remove('image') + } + } + + if ($Body -and $splatParameters.Keys -notcontains 'Form') { + $splatParameters["Body"] = $Body | Convertto-Json + } $script:PSDefaultParameterValues = $global:PSDefaultParameterValues @@ -72,7 +86,7 @@ try { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Invoking method $Method to URI $URi" Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoke-WebRequest with: $($splatParameters | Out-String)" - $webResponse = Invoke-WebRequest @splatParameters + $webResponse = Invoke-RestMethod @splatParameters } catch { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server" @@ -84,27 +98,27 @@ if ($webResponse) { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Status code: $($webResponse.StatusCode)" - if ($webResponse.Content) { - Write-Verbose $webResponse.Content + if ($webResponse) { + Write-Verbose $webResponse # API returned a Content: lets work wit it try{ - $response = ConvertFrom-Json -InputObject $webResponse.Content - if ($response.status -eq "error") { + if ($webResponse.status -eq "error") { Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received from; resolving" # This could be handled nicely in an function such as: # ResolveError $response -WriteError - Write-Error $($response.messages | Out-String) + Write-Error $($webResponse.messages | Out-String) } else { - $result = $response - if (($response) -and ($response | Get-Member -Name payload)) - { - $result = $response.payload + + if ($webResponse.payload){ + $result = $webResponse.payload } - elseif (($response) -and ($response | Get-Member -Name rows)) { - $result = $response.rows + elseif ($webResponse.rows) { + $result = $webResponse.rows + } else { + $result = $webResponse } $result diff --git a/SnipeitPS/Public/Set-SnipeitAccessory.ps1 b/SnipeitPS/Public/Set-SnipeitAccessory.ps1 index 2a10a2c..4f9ce41 100644 --- a/SnipeitPS/Public/Set-SnipeitAccessory.ps1 +++ b/SnipeitPS/Public/Set-SnipeitAccessory.ps1 @@ -38,24 +38,12 @@ Cost of item being purchased. .PARAMETER purchase_date Date accessory was purchased -.PARAMETER order_number -Order number for this accessory. - -.PARAMETER purchase_cost -Cost of item being purchased. - -.PARAMETER purchase_date -Date accessory was purchased - .PARAMETER supplier_id ID number of the supplier for this accessory .PARAMETER location_id ID number of the location the accessory is assigned to -.PARAMETER min_qty -Min quantity of the accessory before alert is triggered - .PARAMETER url URL of Snipeit system, can be set using Set-SnipeitInfoeItInfo command @@ -100,6 +88,8 @@ function Set-SnipeitAccessory() { [Nullable[System.Int32]]$supplier_id, + [Nullable[System.Int32]]$location_id, + [parameter(mandatory = $true)] [string]$url, diff --git a/docs/Set-SnipeitAccessory.md b/docs/Set-SnipeitAccessory.md index 9adeae2..433351a 100644 --- a/docs/Set-SnipeitAccessory.md +++ b/docs/Set-SnipeitAccessory.md @@ -16,7 +16,7 @@ Updates accessory on Snipe-It system Set-SnipeitAccessory [-id] [[-name] ] [[-qty] ] [[-category_id] ] [[-company_id] ] [[-manufacturer_id] ] [[-model_number] ] [[-order_number] ] [[-purchase_cost] ] [[-purchase_date] ] [[-min_amt] ] [[-supplier_id] ] - [-url] [-apiKey] [-WhatIf] [-Confirm] [] + [[-location_id] ] [-url] [-apiKey] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -40,7 +40,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 14 +Position: 15 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -91,6 +91,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -location_id +ID number of the location the accessory is assigned to + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 13 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -manufacturer_id ID number of the manufacturer for this accessory. @@ -235,7 +250,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 13 +Position: 14 Default value: None Accept pipeline input: False Accept wildcard characters: False