Skip to content

Commit d0e2a10

Browse files
committed
reverting New-HaloPSATicket to upstream
1 parent 9fa79bd commit d0e2a10

File tree

1 file changed

+57
-46
lines changed

1 file changed

+57
-46
lines changed

Modules/CippExtensions/Public/Halo/New-HaloPSATicket.ps1

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,68 @@ function New-HaloPSATicket {
1818
if ($ExistingTicket) {
1919
Write-Information "Ticket already exists in HaloPSA: $($ExistingTicket.TicketID)"
2020

21-
$Ticket = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Tickets/$($ExistingTicket.TicketID)?includedetails=true&includelastaction=false&nocache=undefined&includeusersassets=false&isdetailscreen=true" -ContentType 'application/json; charset=utf-8' -Method Get -Headers @{Authorization = "Bearer $($token.access_token)" }
22-
if (!$Ticket.hasbeenclosed) {
23-
Write-Information 'Ticket is still open, adding new note'
24-
<#$Object = [PSCustomObject]@{
25-
ticket_id = $ExistingTicket.TicketID
26-
outcome = 'Private Note'
27-
outcome_id = 7
28-
hiddenfromuser = $true
29-
note_html = $description
30-
}
31-
$body = ConvertTo-Json -Compress -Depth 10 -InputObject @($Object)
32-
try {
33-
if ($PSCmdlet.ShouldProcess('Add note to HaloPSA ticket', 'Add note')) {
34-
$Action = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/actions" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
35-
Write-Information "Note added to ticket in HaloPSA: $($ExistingTicket.TicketID)"
36-
}
37-
return "Note added to ticket in HaloPSA: $($ExistingTicket.TicketID)"
38-
} catch {
39-
$Message = if ($_.ErrorDetails.Message) {
40-
Get-NormalizedError -Message $_.ErrorDetails.Message
41-
} else {
42-
$_.Exception.message
43-
}
44-
Write-LogMessage -message "Failed to add note to HaloPSA ticket: $Message" -API 'HaloPSATicket' -sev Error -LogData (Get-CippException -Exception $_)
45-
Write-Information "Failed to add note to HaloPSA ticket: $Message"
46-
Write-Information "Body we tried to ship: $body"
47-
return "Failed to add note to HaloPSA ticket: $Message"
48-
}#>
21+
$Ticket = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Tickets/$($ExistingTicket.TicketID)?includedetails=true&includelastaction=false&nocache=undefined&includeusersassets=false&isdetailscreen=true" -ContentType 'application/json; charset=utf-8' -Method Get -Headers @{Authorization = "Bearer $($token.access_token)" } -SkipHttpErrorCheck
22+
if ($Ticket.id) {
23+
if (!$Ticket.hasbeenclosed) {
24+
Write-Information 'Ticket is still open, adding new note'
25+
$Object = [PSCustomObject]@{
26+
ticket_id = $ExistingTicket.TicketID
27+
outcome_id = 7
28+
hiddenfromuser = $true
29+
note_html = $description
30+
}
31+
32+
if ($Configuration.Outcome) {
33+
$Outcome = $Configuration.Outcome.value ?? $Configuration.Outcome
34+
$Object.outcome_id = $Outcome
35+
}
36+
37+
$body = ConvertTo-Json -Compress -Depth 10 -InputObject @($Object)
38+
try {
39+
if ($PSCmdlet.ShouldProcess('Add note to HaloPSA ticket', 'Add note')) {
40+
$Action = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/actions" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
41+
Write-Information "Note added to ticket in HaloPSA: $($ExistingTicket.TicketID)"
4942
}
43+
return "Note added to ticket in HaloPSA: $($ExistingTicket.TicketID)"
44+
}
45+
catch {
46+
$Message = if ($_.ErrorDetails.Message) {
47+
Get-NormalizedError -Message $_.ErrorDetails.Message
48+
}
49+
else {
50+
$_.Exception.message
51+
}
52+
Write-LogMessage -message "Failed to add note to HaloPSA ticket: $Message" -API 'HaloPSATicket' -sev Error -LogData (Get-CippException -Exception $_)
53+
Write-Information "Failed to add note to HaloPSA ticket: $Message"
54+
Write-Information "Body we tried to ship: $body"
55+
return "Failed to add note to HaloPSA ticket: $Message"
56+
}
5057
}
58+
}
59+
else {
60+
Write-Information 'Existing ticket could not be found. Creating a new ticket instead.'
61+
}
5162
}
63+
}
5264

53-
$Object = [PSCustomObject]@{
54-
files = $null
55-
usertype = 1
56-
userlookup = @{
57-
id = -1
58-
lookupdisplay = 'Enter Details Manually'
59-
}
60-
client_id = ($client | Select-Object -Last 1)
61-
_forcereassign = $true
62-
site_id = $null
63-
user_name = $null
64-
reportedby = $null
65-
summary = $title
66-
details_html = $description
67-
donotapplytemplateintheapi = $true
68-
attachments = @()
69-
_novalidate = $true
70-
source = 16 ## ISGQ-specific, sets source of ticket as CIPP in HaloPSA
65+
$Object = [PSCustomObject]@{
66+
files = $null
67+
usertype = 1
68+
userlookup = @{
69+
id = -1
70+
lookupdisplay = 'Enter Details Manually'
7171
}
72+
client_id = ($client | Select-Object -Last 1)
73+
_forcereassign = $true
74+
site_id = $null
75+
user_name = $null
76+
reportedby = $null
77+
summary = $title
78+
details_html = $description
79+
donotapplytemplateintheapi = $true
80+
attachments = @()
81+
_novalidate = $true
82+
}
7283

7384
if ($Configuration.TicketType) {
7485
$TicketType = $Configuration.TicketType.value ?? $Configuration.TicketType

0 commit comments

Comments
 (0)