Merge pull request #191 from PetriAsi/feature/support-images

Starting adding support for images and cleaning up requests generation
This commit is contained in:
Petri Asikainen 2021-06-21 10:46:45 +03:00 committed by GitHub
commit 44a5886f09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 130 additions and 166 deletions

View file

@ -17,7 +17,7 @@
# Body of the request # Body of the request
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string]$Body, [Hashtable]$Body,
[string] $Token, [string] $Token,
@ -34,6 +34,8 @@
Throw $exception Throw $exception
} }
#To support images "image" property have be handled before this
$_headers = @{ $_headers = @{
"Authorization" = "Bearer $($token)" "Authorization" = "Bearer $($token)"
'Content-Type' = 'application/json; charset=utf-8' 'Content-Type' = 'application/json; charset=utf-8'
@ -57,19 +59,34 @@
Headers = $_headers Headers = $_headers
UseBasicParsing = $true UseBasicParsing = $true
ErrorAction = 'SilentlyContinue' 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 $script:PSDefaultParameterValues = $global:PSDefaultParameterValues
Write-Debug $Body Write-Debug "$($Body | ConvertTo-Json)"
# Invoke the API # Invoke the API
try { try {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Invoking method $Method to URI $URi" Write-Verbose "[$($MyInvocation.MyCommand.Name)] Invoking method $Method to URI $URi"
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoke-WebRequest with: $($splatParameters | Out-String)" Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoke-WebRequest with: $($splatParameters | Out-String)"
$webResponse = Invoke-WebRequest @splatParameters $webResponse = Invoke-RestMethod @splatParameters
} }
catch { catch {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server" Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server"
@ -81,30 +98,43 @@
if ($webResponse) { if ($webResponse) {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Status code: $($webResponse.StatusCode)" Write-Verbose "[$($MyInvocation.MyCommand.Name)] Status code: $($webResponse.StatusCode)"
if ($webResponse.Content) { if ($webResponse) {
Write-Verbose $webResponse.Content Write-Verbose $webResponse
# API returned a Content: lets work wit it # API returned a Content: lets work wit it
try{ 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" Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received from; resolving"
# This could be handled nicely in an function such as: # This could be handled nicely in an function such as:
# ResolveError $response -WriteError # ResolveError $response -WriteError
Write-Error $($response.messages | Out-String) Write-Error $($webResponse.messages | Out-String)
} }
else { else {
$result = $response #update operations return payload
if (($response) -and ($response | Get-Member -Name payload)) if ($webResponse.payload){
{ $result = $webResponse.payload
$result = $response.payload
} }
elseif (($response) -and ($response | Get-Member -Name rows)) { #Search operations return rows
$result = $response.rows elseif ($webResponse.rows) {
$result = $webResponse.rows
}
#Remove operations returns status and message
elseif ($webResponse.status -eq 'success'){
$result = $webResponse.payload
}
#get operations with id returns just one object
else {
$result = $webResponse
} }
Write-Verbose "Status: $($webResponse.status)"
Write-Verbose "Messages: $($webResponse.messages)"
$result $result
} }
} }
catch { catch {

View file

@ -221,7 +221,6 @@ function Get-SnipeitAsset() {
'Assets with component id' {$apiurl = "$url/api/v1/components/$component_id/assets"} 'Assets with component id' {$apiurl = "$url/api/v1/components/$component_id/assets"}
} }
$Parameters = @{ $Parameters = @{
Uri = $apiurl Uri = $apiurl
Method = 'Get' Method = 'Get'

View file

@ -118,12 +118,10 @@ function New-SnipeitAccessory() {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/accessories" Uri = "$url/api/v1/accessories"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -137,12 +137,10 @@ function New-SnipeitAsset()
$Values += $customfields $Values += $customfields
} }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/hardware" Uri = "$url/api/v1/hardware"
Method = 'Post' Method = 'Post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -81,20 +81,19 @@ function New-SnipeitAssetMaintenance() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['start_date']) { if ($Values['start_date']) {
$values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd") $Values['start_date'] = $Values['start_date'].ToString("yyyy-MM-dd")
} }
if ($values['completion_date']) { if ($Values['completion_date']) {
$values['completion_date'] = $values['completion_date'].ToString("yyyy-MM-dd") $Values['completion_date'] = $Values['completion_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/maintenances" Uri = "$url/api/v1/maintenances"
Method = 'Post' Method = 'Post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -48,12 +48,10 @@ function New-SnipeitAudit()
$Values += @{"asset_tag" = $tag} $Values += @{"asset_tag" = $tag}
} }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/hardware/audit" Uri = "$url/api/v1/hardware/audit"
Method = 'Post' Method = 'Post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -68,8 +68,6 @@ function New-SnipeitCategory()
} }
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process { process {
@ -77,7 +75,7 @@ function New-SnipeitCategory()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/categories" Uri = "$url/api/v1/categories"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -41,12 +41,10 @@ function New-SnipeitCompany()
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/companies" Uri = "$url/api/v1/companies"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -76,16 +76,14 @@ function New-SnipeitComponent() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) { if ($Values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/components" Uri = "$url/api/v1/components"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -114,18 +114,16 @@ function New-SnipeitConsumable()
begin { begin {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) { if ($Values['purchase_date']) {
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
} }
process { process {
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/consumables" Uri = "$url/api/v1/consumables"
Method = 'Post' Method = 'Post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -83,12 +83,10 @@ function New-SnipeitCustomField()
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/fields" Uri = "$url/api/v1/fields"
Method = 'post' Method = 'post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }
} }

View file

@ -57,12 +57,10 @@ function New-SnipeitDepartment() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/departments" Uri = "$url/api/v1/departments"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -128,24 +128,22 @@ function New-SnipeitLicense() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['expiration_date']) { if ($Values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") $Values['expiration_date'] = $Values['expiration_date'].ToString("yyyy-MM-dd")
} }
if ($values['purchase_date']) { if ($Values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
if ($values['termination_date']) { if ($Values['termination_date']) {
$values['termination_date'] = $values['termination_date'].ToString("yyyy-MM-dd") $Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/licenses" Uri = "$url/api/v1/licenses"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -89,12 +89,10 @@ function New-SnipeitLocation() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/locations" Uri = "$url/api/v1/locations"
Method = 'post' Method = 'post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -42,13 +42,10 @@ function New-SnipeitManufacturer()
"name" = $Name "name" = $Name
} }
#Convert Values to JSON format
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/manufacturers" Uri = "$url/api/v1/manufacturers"
Method = 'post' Method = 'post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -73,12 +73,11 @@ function New-SnipeitModel()
if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) } if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) }
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) } if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/models" Uri = "$url/api/v1/models"
Method = 'post' Method = 'post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -120,12 +120,10 @@ function New-SnipeitUser() {
$Values['password_confirmation'] = $password $Values['password_confirmation'] = $password
} }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/users" Uri = "$url/api/v1/users"
Method = 'post' Method = 'post'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitAccessory ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/accessories/$accessory_id" Uri = "$url/api/v1/accessories/$accessory_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -42,7 +42,6 @@ function Remove-SnipeitAsset ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/hardware/$asset_id" Uri = "$url/api/v1/hardware/$asset_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -46,7 +46,6 @@ function Remove-SnipeitAssetMaintenance {
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/maintenances/$maintenance_id" Uri = "$url/api/v1/maintenances/$maintenance_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitCategory ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/categories/$category_id" Uri = "$url/api/v1/categories/$category_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitCompany ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/companies/$company_id" Uri = "$url/api/v1/companies/$company_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitComponent ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/components/$component_id" Uri = "$url/api/v1/components/$component_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -42,7 +42,6 @@ function Remove-SnipeitConsumable ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/consumables/$consumable_id" Uri = "$url/api/v1/consumables/$consumable_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitCustomField ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/fields/$field_id" Uri = "$url/api/v1/fields/$field_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitDepartment ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/departments/$department_id" Uri = "$url/api/v1/departments/$department_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitLicense ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/licenses/$license_id" Uri = "$url/api/v1/licenses/$license_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitLocation ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/locations/$asset_id" Uri = "$url/api/v1/locations/$asset_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitManufacturer ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/manufacturers/$manufacturer_id_id" Uri = "$url/api/v1/manufacturers/$manufacturer_id_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitModel ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/models/$model_id" Uri = "$url/api/v1/models/$model_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -41,7 +41,6 @@ function Remove-SnipeitUser ()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/users/$user_id" Uri = "$url/api/v1/users/$user_id"
Method = 'Delete' Method = 'Delete'
Body = '{}'
Token = $apiKey Token = $apiKey
} }

View file

@ -46,7 +46,7 @@ function Reset-SnipeitAccessoryOwner()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/accessories/$assigned_pivot_id/checkin" Uri = "$url/api/v1/accessories/$assigned_pivot_id/checkin"
Method = 'Post' Method = 'Post'
Body = '{}' Body = @{}
Token = $apiKey Token = $apiKey
} }

View file

@ -57,12 +57,10 @@ function Reset-SnipeitAssetOwner() {
if ($PSBoundParameters.ContainsKey('location_id')) { $Values.Add("location_id", $location_id) } if ($PSBoundParameters.ContainsKey('location_id')) { $Values.Add("location_id", $location_id) }
if ($PSBoundParameters.ContainsKey('status_id')) { $Values.Add("status_id", $status_id) } if ($PSBoundParameters.ContainsKey('status_id')) { $Values.Add("status_id", $status_id) }
$Body = $Values | ConvertTo-Json;
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/hardware/$id/checkin" Uri = "$url/api/v1/hardware/$id/checkin"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -38,24 +38,12 @@ Cost of item being purchased.
.PARAMETER purchase_date .PARAMETER purchase_date
Date accessory was purchased 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 .PARAMETER supplier_id
ID number of the supplier for this accessory ID number of the supplier for this accessory
.PARAMETER location_id .PARAMETER location_id
ID number of the location the accessory is assigned to ID number of the location the accessory is assigned to
.PARAMETER min_qty
Min quantity of the accessory before alert is triggered
.PARAMETER url .PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfoeItInfo command 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]]$supplier_id,
[Nullable[System.Int32]]$location_id,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -112,20 +102,18 @@ function Set-SnipeitAccessory() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) { if ($Values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
Write-Verbose "Body: $Body"
} }
process { process {
foreach($accessory_id in $id){ foreach($accessory_id in $id){
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/accessories/$accessory_id" Uri = "$url/api/v1/accessories/$accessory_id"
Method = 'Put' Method = 'Patch'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -46,8 +46,6 @@ function Set-SnipeitAccessoryOwner()
) )
begin{ begin{
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process { process {
@ -55,7 +53,7 @@ function Set-SnipeitAccessoryOwner()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/accessories/$accessory_id/checkout" Uri = "$url/api/v1/accessories/$accessory_id/checkout"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -136,8 +136,8 @@ function Set-SnipeitAsset()
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) { if ($Values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
if ($customfields) if ($customfields)
@ -145,7 +145,6 @@ function Set-SnipeitAsset()
$Values += $customfields $Values += $customfields
} }
$Body = $Values | ConvertTo-Json;
} }
process { process {
@ -153,7 +152,7 @@ function Set-SnipeitAsset()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/hardware/$asset_id" Uri = "$url/api/v1/hardware/$asset_id"
Method = $RequestType Method = $RequestType
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -71,11 +71,11 @@ function Set-SnipeitAssetOwner()
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($Values['expected_checkin']) { if ($Values['expected_checkin']) {
$Values['expected_checkin'] = $values['expected_checkin'].ToString("yyyy-MM-dd") $Values['expected_checkin'] = $Values['expected_checkin'].ToString("yyyy-MM-dd")
} }
if ($Values['checkout_at']) { if ($Values['checkout_at']) {
$Values['checkout_at'] = $values['checkout_at'].ToString("yyyy-MM-dd") $Values['checkout_at'] = $Values['checkout_at'].ToString("yyyy-MM-dd")
} }
switch ($checkout_to_type) switch ($checkout_to_type)
@ -88,8 +88,6 @@ function Set-SnipeitAssetOwner()
#This can be removed now #This can be removed now
if($Values.ContainsKey('assigned_id')){$Values.Remove('assigned_id')} if($Values.ContainsKey('assigned_id')){$Values.Remove('assigned_id')}
$Body = $Values | ConvertTo-Json;
} }
process{ process{
@ -97,7 +95,7 @@ function Set-SnipeitAssetOwner()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/hardware/$asset_id/checkout" Uri = "$url/api/v1/hardware/$asset_id/checkout"
Method = 'POST' Method = 'POST'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -66,8 +66,6 @@ function Set-SnipeitCategory()
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process { process {
@ -75,7 +73,7 @@ function Set-SnipeitCategory()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/categories/$category_id" Uri = "$url/api/v1/categories/$category_id"
Method = 'Put' Method = 'Put'
Body = $Body Body = $values
Token = $apiKey Token = $apiKey
} }

View file

@ -45,9 +45,7 @@ function Set-SnipeitCompany()
) )
begin{ begin{
$values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $values | ConvertTo-Json;
} }
process{ process{
@ -55,7 +53,7 @@ function Set-SnipeitCompany()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/companies/$company_id" Uri = "$url/api/v1/companies/$company_id"
Method = 'Patch' Method = 'Patch'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -82,13 +82,11 @@ function Set-SnipeitComponent()
begin { begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) { if ($Values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
$Body = $values | ConvertTo-Json;
} }
process { process {
@ -96,7 +94,7 @@ function Set-SnipeitComponent()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/components/$component_id" Uri = "$url/api/v1/components/$component_id"
Method = 'Patch' Method = 'Patch'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -126,7 +126,6 @@ function Set-SnipeitConsumable()
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
} }
process { process {
@ -134,7 +133,7 @@ function Set-SnipeitConsumable()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/consumables/$consumable_id" Uri = "$url/api/v1/consumables/$consumable_id"
Method = 'Put' Method = 'Put'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -82,9 +82,6 @@ function Set-SnipeitCustomField()
} }
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process{ process{
@ -92,7 +89,7 @@ function Set-SnipeitCustomField()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/fields/$field_id" Uri = "$url/api/v1/fields/$field_id"
Method = 'Put' Method = 'Put'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -61,8 +61,6 @@ function Set-SnipeitDepartment() {
begin { begin {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process { process {
@ -70,7 +68,7 @@ function Set-SnipeitDepartment() {
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/departments/$department_id" Uri = "$url/api/v1/departments/$department_id"
Method = 'Put' Method = 'Put'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -133,19 +133,18 @@ function Set-SnipeitLicense() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['expiration_date']) { if ($Values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") $Values['expiration_date'] = $Values['expiration_date'].ToString("yyyy-MM-dd")
} }
if ($values['purchase_date']) { if ($Values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
if ($values['termination_date']) { if ($Values['termination_date']) {
$values['termination_date'] = $values['termination_date'].ToString("yyyy-MM-dd") $Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd")
} }
$Body = $Values | ConvertTo-Json;
} }
process { process {
@ -153,7 +152,7 @@ function Set-SnipeitLicense() {
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/licenses/$license_id" Uri = "$url/api/v1/licenses/$license_id"
Method = 'PUT' Method = 'PUT'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -50,8 +50,10 @@ function Set-SnipeitLicenseSeat()
[int]$seat_id, [int]$seat_id,
[Alias('assigned_id')] [Alias('assigned_id')]
[Nullable[System.Int32]]$assigned_to, [Nullable[System.Int32]]$assigned_to,
[Nullable[System.Int32]]$asset_id, [Nullable[System.Int32]]$asset_id,
[string]$note, [string]$note,
@ -65,8 +67,6 @@ function Set-SnipeitLicenseSeat()
begin{ begin{
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process{ process{
@ -74,7 +74,7 @@ function Set-SnipeitLicenseSeat()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/licenses/$license_id/seats/$seat_id" Uri = "$url/api/v1/licenses/$license_id/seats/$seat_id"
Method = 'Patch' Method = 'Patch'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -99,8 +99,6 @@ function Set-SnipeitLocation() {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process{ process{
@ -108,7 +106,7 @@ function Set-SnipeitLocation() {
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/locations/$location_id" Uri = "$url/api/v1/locations/$location_id"
Method = 'PUT' Method = 'PUT'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -69,14 +69,13 @@ function Set-SnipeitModel() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
} }
process { process {
foreach ($model_id in $id) { foreach ($model_id in $id) {
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/models/$model_id" Uri = "$url/api/v1/models/$model_id"
Method = 'put' Method = 'put'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -62,7 +62,6 @@ function Set-SnipeitStatus()
begin { begin {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json
} }
process { process {
@ -70,7 +69,7 @@ function Set-SnipeitStatus()
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/statuslabels/$status_id" Uri = "$url/api/v1/statuslabels/$status_id"
Method = 'Put' Method = 'Put'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -122,7 +122,6 @@ function Set-SnipeitUser() {
$Values['password_confirmation'] = $password $Values['password_confirmation'] = $password
} }
$Body = $Values | ConvertTo-Json;
} }
process{ process{
@ -130,7 +129,7 @@ function Set-SnipeitUser() {
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/users/$user_id" Uri = "$url/api/v1/users/$user_id"
Method = 'PATCH' Method = 'PATCH'
Body = $Body Body = $Values
Token = $apiKey Token = $apiKey
} }

View file

@ -16,7 +16,7 @@ Updates accessory on Snipe-It system
Set-SnipeitAccessory [-id] <Int32[]> [[-name] <String>] [[-qty] <Int32>] [[-category_id] <Int32>] Set-SnipeitAccessory [-id] <Int32[]> [[-name] <String>] [[-qty] <Int32>] [[-category_id] <Int32>]
[[-company_id] <Int32>] [[-manufacturer_id] <Int32>] [[-model_number] <String>] [[-order_number] <String>] [[-company_id] <Int32>] [[-manufacturer_id] <Int32>] [[-model_number] <String>] [[-order_number] <String>]
[[-purchase_cost] <Single>] [[-purchase_date] <DateTime>] [[-min_amt] <Int32>] [[-supplier_id] <Int32>] [[-purchase_cost] <Single>] [[-purchase_date] <DateTime>] [[-min_amt] <Int32>] [[-supplier_id] <Int32>]
[-url] <String> [-apiKey] <String> [-WhatIf] [-Confirm] [<CommonParameters>] [[-location_id] <Int32>] [-url] <String> [-apiKey] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@ -40,7 +40,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: True Required: True
Position: 14 Position: 15
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -91,6 +91,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False 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 ### -manufacturer_id
ID number of the manufacturer for this accessory. ID number of the manufacturer for this accessory.
@ -235,7 +250,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: True Required: True
Position: 13 Position: 14
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False