Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /V1.0/InvoicePDF to Swagger update Get-AutotaskAPIResource to allow PDF invoice downloading #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

PSGetModuleInfo.xml
2 changes: 1 addition & 1 deletion AutoTaskAPI.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = '.\AutoTaskAPI.psm1'

# Version number of this module.
ModuleVersion = '1.2.2'
ModuleVersion = '1.2.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
13 changes: 12 additions & 1 deletion Public/Get-AutotaskAPIResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 @{
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Public/Set-AutotaskAPIResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
89 changes: 89 additions & 0 deletions v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": {
Expand Down