-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.ps1
More file actions
51 lines (46 loc) · 1.62 KB
/
action.ps1
File metadata and controls
51 lines (46 loc) · 1.62 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
try {
$searchValue = $dataSource.searchValue
$endPoint = '/tas/api/branches'
$searchAttribute = 'name'
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"
}
if ([String]::IsNullOrEmpty($searchValue) -eq $true) {
return
}
else {
Write-Information "searchValue: $searchValue"
$splatParams = @{
Uri = $topdeskBaseUrl + $endPoint + "?query=" + $searchAttribute + "==" + "'$searchValue'"
Method = 'GET'
Verbose = $false
Headers = $headers
ContentType = "application/json; charset=utf-8"
}
write-warning "$($splatParams.Uri)"
$results = Invoke-RestMethod @splatParams
$resultCount = @($results).Count
Write-Information "Result count: $resultCount"
if ($resultCount -gt 0) {
foreach ($result in $results) {
$returnObject = @{
name = $result.name;
id = $result.id;
}
Write-Output $returnObject
}
}
}
}
catch {
$msg = "Error searching Topdesk operator [$searchValue]. Error: $($_.Exception.Message)"
Write-Error $msg
}