-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.ps1
More file actions
77 lines (73 loc) · 3.35 KB
/
action.ps1
File metadata and controls
77 lines (73 loc) · 3.35 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# TOPdesk-Task-SA-Target-TOPdesk-IncidentCreate
###########################################################
# Form mapping
$formObject = @{
callerLookup = $form.callerLookup
briefDescription = $form.briefDescription
request = $form.request
action = $form.action
operator = $form.operator
operatorGroup = $form.operatorGroup
category = $form.category
subcategory = $form.subcategory
callType = $form.callType
impact = $form.impact
urgency = $form.urgency
priority = $form.priority
duration = $form.duration
entryType = $form.entryType
processingStatus = $form.processingStatus
branch = $form.branch
}
try {
Write-Information "Executing TOPdesk action: [CreateIncident] for: [$($formObject.briefDescription)]"
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 "Creating TOPdesk Incident: [$($formObject.briefDescription)]"
$splatCreateIncidentParams = @{
Uri = "$($topdeskBaseUrl)/tas/api/incidents"
Method = "POST"
Body = ([System.Text.Encoding]::UTF8.GetBytes(($formObject | ConvertTo-Json -Depth 10)))
Verbose = $false
Headers = $headers
ContentType = "application/json; charset=utf-8"
}
$response = Invoke-RestMethod @splatCreateIncidentParams
$auditLog = @{
Action = "CreateResource"
System = "TOPdesk"
TargetIdentifier = [String]$response.id
TargetDisplayName = [String]$response.number
Message = "TOPdesk action: [CreateIncident] for: [$($formObject.briefDescription)] executed successfully"
IsError = $false
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Information "TOPdesk action: [CreateIncident] for: [$($formObject.briefDescription)] executed successfully"
}
catch {
$ex = $_
$auditLog = @{
Action = "CreateResource"
System = "TOPdesk"
TargetIdentifier = ""
TargetDisplayName = [String]$formObject.briefDescription
Message = "Could not execute TOPdesk action: [CreateIncident] for: [$($formObject.briefDescription)], error: $($ex.Exception.Message)"
IsError = $true
}
if ($($ex.Exception.GetType().FullName -eq "Microsoft.PowerShell.Commands.HttpResponseException")) {
$auditLog.Message = "Could not execute TOPdesk action: [CreateIncident] for: [$($formObject.briefDescription)]"
Write-Error "Could not execute TOPdesk action: [CreateIncident] for: [$($formObject.briefDescription)], error: $($ex.ErrorDetails)"
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Error "Could not execute TOPdesk action: [CreateIncident] for: [$($formObject.briefDescription)], error: $($ex.Exception.Message)"
}
###########################################################