-
Notifications
You must be signed in to change notification settings - Fork 0
/
departments.ps1
117 lines (94 loc) · 3.12 KB
/
departments.ps1
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
########################################################################
# HelloID-Conn-Prov-Source-NMBRS-Departments
#
# Version: 1.1.1
########################################################################
# Initialize default value's
$config = $Configuration | ConvertFrom-Json
# Set debug logging
switch ($($config.IsDebug)) {
$true { $VerbosePreference = 'Continue' }
$false { $VerbosePreference = 'SilentlyContinue' }
}
#region functions
function Invoke-NMBRSRestMethod {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Uri,
[Parameter()]
[string]
$Service,
[Parameter(Mandatory)]
[string]
$SoapBody
)
switch ($service) {
'DebtorService' {
$soapHeader = "
<deb:AuthHeaderWithDomain>
<deb:Username>$($config.UserName)</deb:Username>
<deb:Token>$($config.Token)</deb:Token>
<deb:Domain>$($config.Domain)</deb:Domain>
</deb:AuthHeaderWithDomain>"
}
}
$xmlRequest = "<?xml version=`"1.0`" encoding=`"utf-8`"?>
<soap:Envelope xmlns:soap= `"http://www.w3.org/2003/05/soap-envelope`" xmlns:deb=`"https://api.nmbrs.nl/soap/$($config.version)/$service`">
<soap:Header>
$soapHeader
</soap:Header>
<soap:Body>
$soapBody
</soap:Body>
</soap:Envelope>"
try {
$splatParams = @{
Uri = $Uri
Method = 'POST'
Body = $xmlRequest
ContentType = 'text/xml; charset=utf-8'
}
if (-not [string]::IsNullOrEmpty($config.ProxyAddress)) {
$splatParams['Proxy'] = $config.ProxyAddress
}
Invoke-RestMethod @splatParams -Verbose:$false
}
catch {
throw $_
}
}
function Get-DepartmentsbyDebtor {
[CmdletBinding()]
param ( [Parameter(Mandatory)]
[string]
$DebtorId)
$splatParams = @{
Uri = "$($config.BaseUrl)/soap/$($config.version)/DebtorService.asmx"
Service = 'DebtorService'
SoapBody = "<deb:Department_GetList xmlns=`"https://api.nmbrs.nl/soap/$($config.version)/DebtorService`">
<deb:DebtorId>$DebtorId</deb:DebtorId>
</deb:Department_GetList>"
}
[xml]$response = Invoke-NMBRSRestMethod @splatParams
Write-Output $response.Envelope.Body.Department_GetListResponse.Department_GetListResult.Department
}
#endregion
try {
Write-Verbose 'Retrieving NMBRS Department data'
$departmentList = Get-DepartmentsbyDebtor($config.DebtorID)
Write-Verbose 'Importing raw data in HelloID'
foreach ($department in $departmentList) {
$curDepartment = @{
ExternalId = $department.Id
DisplayName = $department.Description
}
Write-Output $curDepartment | ConvertTo-Json -Depth 10
}
}
catch {
$ex = $PSItem
Write-Verbose "Could not retrieve NMBRS employees. Error: $($ex.Exception.Message)"
Write-Verbose "Could not retrieve NMBRS employees. ErrorDetails: $($ex.ErrorDetails)"
}