Skip to content

Commit

Permalink
feat: add ticket consolidation support
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Feb 25, 2025
1 parent f60d0a7 commit f308348
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion Modules/CippExtensions/Public/Halo/New-HaloPSATicket.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,46 @@ function New-HaloPSATicket {
#Get Halo PSA Token based on the config we have.
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json).HaloPSA

$TicketTable = Get-CIPPTable -TableName 'PSATickets'
$token = Get-HaloToken -configuration $Configuration

if ($Configuration.ConsolidateTickets) {
$ExistingTicket = Get-CIPPAzDataTableEntity @TicketTable -Filter "PartitionKey eq 'HaloPSA' and RowKey eq '$($client)-$($title)'"
if ($ExistingTicket) {
Write-Information "Ticket already exists in HaloPSA: $($ExistingTicket.TicketID)"

$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)" }
if (!$Ticket.hasbeenclosed) {
Write-Information 'Ticket is still open, adding new note'
$Object = [PSCustomObject]@{
ticket_id = $ExistingTicket.TicketID
outcome = 'Private Note'
outcome_id = 7
hiddenfromuser = $true
note_html = $description
}
$body = ConvertTo-Json -Compress -Depth 10 -InputObject @($Object)
try {
if ($PSCmdlet.ShouldProcess('Add note to HaloPSA ticket', 'Add note')) {
$Action = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/actions" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
Write-Information "Note added to ticket in HaloPSA: $($Action.id)"
}
return
} catch {
$Message = if ($_.ErrorDetails.Message) {
Get-NormalizedError -Message $_.ErrorDetails.Message
} else {
$_.Exception.message
}
Write-LogMessage -message "Failed to add note to HaloPSA ticket: $Message" -API 'HaloPSATicket' -sev Error -LogData (Get-CippException -Exception $_)
Write-Information "Failed to add note to HaloPSA ticket: $Message"
Write-Information "Body we tried to ship: $body"
return
}
}
}
}

$Object = [PSCustomObject]@{
files = $null
usertype = 1
Expand Down Expand Up @@ -41,6 +79,16 @@ function New-HaloPSATicket {
if ($PSCmdlet.ShouldProcess('Send ticket to HaloPSA', 'Create ticket')) {
$Ticket = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Tickets" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
Write-Information "Ticket created in HaloPSA: $($Ticket.id)"

if ($Configuration.ConsolidateTickets) {
$TicketObject = [PSCustomObject]@{
PartitionKey = 'HaloPSA'
RowKey = "$($client)-$($title)"
TicketID = $Ticket.id
}
Add-CIPPAzDataTableEntity @TicketTable -Entity $TicketObject -Force
Write-Information 'Ticket added to consolidation table'
}
}
} catch {
$Message = if ($_.ErrorDetails.Message) {
Expand Down

0 comments on commit f308348

Please sign in to comment.