-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.ps1
More file actions
62 lines (58 loc) · 2.73 KB
/
action.ps1
File metadata and controls
62 lines (58 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# TOPdesk-Task-SA-Target-TOPdesk-ChangeUpdate
###########################################################
# Form mapping
$formObject = $form.updates
$changeId = $form.id
$changeDisplayName = $form.number
try {
Write-Information "Executing TOPdesk action: [UpdateChange] for: [$($changeDisplayName)]"
Write-Verbose "Creating authorization headers"
# Create authorization headers with TOPdesk API key
$pair = "${topdeskApiUsername}:${topdeskApiSecret}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$key = "Basic $base64"
$headers = @{
"authorization" = $Key
"Accept" = "application/json"
"Partner-Solution-Id" = "TOOL001"
}
Write-Verbose "Updating TOPdesk Change: [$($changeDisplayName)]"
$splatUpdateChangeParams = @{
Uri = "$($topdeskBaseUrl)/tas/api/operatorChanges/$($changeId)"
Method = "PATCH"
Body = ([System.Text.Encoding]::UTF8.GetBytes(($formObject | ConvertTo-Json -Depth 10)))
Verbose = $false
Headers = $headers
ContentType = "application/json-patch+json; charset=utf-8"
}
$response = Invoke-RestMethod @splatUpdateChangeParams
$auditLog = @{
Action = "UpdateResource"
System = "TOPdesk"
TargetIdentifier = [String]$changeId
TargetDisplayName = [String]$changeDisplayName
Message = "TOPdesk action: [UpdateChange] for: [$($changeDisplayName)] executed successfully"
IsError = $false
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Information "TOPdesk action: [UpdateChange] for: [$($changeDisplayName)] executed successfully"
}
catch {
$ex = $_
$auditLog = @{
Action = "UpdateResource"
System = "TOPdesk"
TargetIdentifier = [String]$changeId
TargetDisplayName = [String]$changeDisplayName
Message = "Could not execute TOPdesk action: [UpdateChange] for: [$($changeDisplayName)], error: $($ex.Exception.Message)"
IsError = $true
}
if ($($ex.Exception.GetType().FullName -eq "Microsoft.PowerShell.Commands.HttpResponseException")) {
$auditLog.Message = "Could not execute TOPdesk action: [UpdateChange] for: [$($changeDisplayName)]"
Write-Error "Could not execute TOPdesk action: [UpdateChange] for: [$($changeDisplayName)], error: $($ex.ErrorDetails)"
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Error "Could not execute TOPdesk action: [UpdateChange] for: [$($changeDisplayName)], error: $($ex.Exception.Message)"
}
###########################################################