From ac2876ab4bda8692e22a95ea4b8352c8dcbd6ce7 Mon Sep 17 00:00:00 2001 From: dszp Date: Mon, 1 Apr 2024 13:28:24 -0400 Subject: [PATCH] Add /V1.0/InvoicePDF to Swagger and Get-AutotaskAPIResource to download invoice PDFs Edits to allow request of Invoice PDF file format from Autotask, which used to be documented in the Autotask REST API docs and seems to have been removed, but still works. Was not listed in Swagger file, and required some changes to Get-AutotaskAPIResource to add functionality. Bumped version to 1.2.3 to compile and run locally where this has been used for over a year successfully. PSGetModuleInfo.xml file also exists locally with new version number but has been added to .gitignore to avoid pushing with commit. --- .gitignore | 2 + AutoTaskAPI.psd1 | 2 +- Public/Get-AutotaskAPIResource.ps1 | 13 ++++- Public/Set-AutotaskAPIResource.ps1 | 2 +- v1.json | 89 ++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9cbe5c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +PSGetModuleInfo.xml diff --git a/AutoTaskAPI.psd1 b/AutoTaskAPI.psd1 index 4ffc067..10bf64f 100644 --- a/AutoTaskAPI.psd1 +++ b/AutoTaskAPI.psd1 @@ -12,7 +12,7 @@ RootModule = '.\AutoTaskAPI.psm1' # Version number of this module. - ModuleVersion = '1.2.2' + ModuleVersion = '1.2.3' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/Public/Get-AutotaskAPIResource.ps1 b/Public/Get-AutotaskAPIResource.ps1 index bf84938..43d76f1 100644 --- a/Public/Get-AutotaskAPIResource.ps1 +++ b/Public/Get-AutotaskAPIResource.ps1 @@ -46,6 +46,8 @@ function Get-AutotaskAPIResource { $Script:Index = $Script:Queries | Group-Object Index -AsHashTable -AsString $ResourceURL = @(($Script:Index[$resource] | Where-Object { $_.Get -eq $resource }))[0] $ResourceURL.name = $ResourceURL.name.replace("/query", "/{PARENTID}") + # Fix path to InvoicePDF URL, must be unique vs. /Invoices in Swagger file + $ResourceURL.name = $ResourceURL.name.replace("V1.0/InvoicePDF", "V1.0/Invoices/{id}/InvoicePDF") if ($SimpleSearch) { $SearchOps = $SimpleSearch -split ' ' $SearchQuery = ConvertTo-Json @{ @@ -73,12 +75,21 @@ function Get-AutotaskAPIResource { if ($SearchQuery) { $ResourceURL = ("$($ResourceURL.name)/query?search=$SearchQuery" -replace '{PARENTID}', '') } - $SetURI = "$($Script:AutotaskBaseURI)/$($ResourceURL)" + # Write-Host "ResourceURL BEFORE IF:" $ResourceURL + if ($resource -eq "InvoicePDF" -and $ID) { + $ResourceURL = ("$($ResourceURL)" -replace '{id}', "$($ID)") + } + $SetURI = "$($Script:AutotaskBaseURI)$($ResourceURL)" # Removed separating / as it was doubling in output (but worked) + # Write-Host "Final SetURI:" $SetURI try { do { $items = Invoke-RestMethod -Uri $SetURI -Headers $Headers -Method Get $SetURI = $items.PageDetails.NextPageUrl #[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([datetime]::UtcNow, (get-timezone).id) + # Returns blank unless $items itself is returned for InvoicePDF function + if($resource -eq "InvoicePDF") { + return $items + } if ($items.items) { foreach ($item in $items.items) { diff --git a/Public/Set-AutotaskAPIResource.ps1 b/Public/Set-AutotaskAPIResource.ps1 index 39a27c8..fb595a7 100644 --- a/Public/Set-AutotaskAPIResource.ps1 +++ b/Public/Set-AutotaskAPIResource.ps1 @@ -60,7 +60,7 @@ function Set-AutotaskAPIResource { if ($ID) { $MyBody | Add-Member -NotePropertyMembers @{id=$ID} } - $PSBoundParameters.body.PSObject.properties | Where-Object {$null -ne $_.Value} | ForEach-Object {Add-Member -InputObject $MyBody -NotePropertyMembers @{$_.Name=$_.Value}} + $PSBoundParameters.body.PSObject.properties | Where-Object {$null -ne $_.Value} | ForEach-Object {Add-Member -Force -InputObject $MyBody -NotePropertyMembers @{$_.Name=$_.Value}} try { # Iterating through the property names above produces an array of n MyBody objects, all the same, diff --git a/v1.json b/v1.json index e72af1f..aaa2b2c 100644 --- a/v1.json +++ b/v1.json @@ -65879,6 +65879,72 @@ } } }, + "/V1.0/InvoicePDF": { + "get": { + "tags": [ + "InvoicePDF" + ], + "operationId": "InvoicePDF_QueryItem", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json", + "text/json" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "integer", + "format": "int64" + }, + { + "name": "ApiIntegrationCode", + "in": "header", + "description": "API Integration Code", + "required": true, + "type": "string" + }, + { + "name": "UserName", + "in": "header", + "description": "User Name", + "required": true, + "type": "string" + }, + { + "name": "Secret", + "in": "header", + "description": "Secret", + "required": true, + "type": "string" + }, + { + "name": "ImpersonationResourceId", + "in": "header", + "description": "Impersonation Resource Key", + "required": false, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/InvoicePDFModel" + } + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + } + } + } + }, "/V1.0/Invoices/query/count": { "get": { "tags": [ @@ -144133,6 +144199,29 @@ } } }, + "InvoicePDFModel": { + "type": "object", + "properties": { + "Id": { + "format": "int64", + "type": "integer" + }, + "contentType": { + "type": "string" + }, + "fileName": { + "type": "string" + }, + "fileSize": { + "format": "int64", + "type": "integer" + }, + "data": { + "format": "byte", + "type": "string" + } + } + }, "OpportunityModel": { "type": "object", "properties": {