66# Enable TLS1.2
77[System.Net.ServicePointManager ]::SecurityProtocol = [System.Net.ServicePointManager ]::SecurityProtocol -bor [System.Net.SecurityProtocolType ]::Tls12
88
9+ # region functions
10+ function Set-AuthorizationHeaders {
11+ param (
12+ [ValidateNotNullOrEmpty ()]
13+ [string ]
14+ $Username ,
15+
16+ [ValidateNotNullOrEmpty ()]
17+ [string ]
18+ $ApiKey
19+ )
20+ # Create basic authentication string
21+ $bytes = [System.Text.Encoding ]::ASCII.GetBytes(" ${Username} :${Apikey} " )
22+ $base64 = [System.Convert ]::ToBase64String($bytes )
23+
24+ # Set authentication headers
25+ $authHeaders = [System.Collections.Generic.Dictionary [string , string ]]::new()
26+ $authHeaders.Add (" Authorization" , " BASIC $base64 " )
27+ $authHeaders.Add (' Accept' , ' application/json; charset=utf-8' )
28+ $authHeaders.Add (' Partner-Solution-Id' , ' TOOL001' ) # Fixed value - Tools4ever Partner Solution ID
29+
30+ Write-Output $authHeaders
31+ }
32+ # endregion functions
33+
934try {
1035 Write-Information ' Starting target account import'
1136
@@ -27,16 +52,12 @@ try {
2752 $fields = $importFields -join ' ,'
2853 Write-Information " Querying fields [$fields ]"
2954
30- # Create basic authentication string
31- $username = $actionContext.Configuration.username
32- $apikey = $actionContext.Configuration.apikey
33- $bytes = [System.Text.Encoding ]::ASCII.GetBytes(" ${username} :${apikey} " )
34- $base64 = [System.Convert ]::ToBase64String($bytes )
35-
36- # Set authentication headers
37- $headers = [System.Collections.Generic.Dictionary [string , string ]]::new()
38- $headers.Add (" Authorization" , " BASIC $base64 " )
39- $headers.Add (' Accept' , ' application/json; charset=utf-8' )
55+ # Setup authentication headers
56+ $splatParamsAuthorizationHeaders = @ {
57+ UserName = $actionContext.Configuration.username
58+ ApiKey = $actionContext.Configuration.apikey
59+ }
60+ $headers = Set-AuthorizationHeaders @splatParamsAuthorizationHeaders
4061
4162 $existingAccounts = @ ()
4263 $pageSize = 100
96117 if ([string ]::IsNullOrEmpty($account.dynamicName )) {
97118 $dynamicName = $account.id
98119 }
99- else {
120+ else {
100121 $dynamicName = $account.dynamicName
101122 }
102123
0 commit comments