Skip to content

Commit 6d4534c

Browse files
committed
Move HTTP headers to APICalls.ps1
The Content-Type value is now specified via the Invoke-RestMethod -ContentType parameter in Internal/APICalls.ps1.
1 parent e5a8715 commit 6d4534c

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

ITGlueAPI/ITGlueAPI.psm1

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
$ITGlue_Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
2-
$ITGlue_Headers.Add("Content-Type", 'application/vnd.api+json')
3-
4-
Set-Variable -Name "ITGlue_Headers" -Value $ITGlue_Headers -Scope global
5-
6-
Import-ITGlueModuleSettings
1+
Import-ITGlueModuleSettings

ITGlueAPI/Internal/APICalls.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ function Invoke-ITGlueRequest {
3535
}
3636

3737
try {
38-
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
38+
$headers = @{
39+
'x-api-key' = (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password
40+
}
3941

4042
$parameters = @{
4143
'Method' = $Method
4244
'Uri' = $ITGlue_Base_URI + $ResourceURI + $query_string
43-
'Headers' = $ITGlue_Headers
45+
'Headers' = $headers
4446
'Body' = $body
4547
}
4648
if ($Method -ne 'GET') {
@@ -50,8 +52,6 @@ function Invoke-ITGlueRequest {
5052
$api_response = Invoke-RestMethod @parameters -ErrorAction Stop
5153
} catch {
5254
Write-Error $_
53-
} finally {
54-
[void] ($ITGlue_Headers.Remove('x-api-key')) # Quietly clean up scope so the API key doesn't persist
5555
}
5656

5757
return $api_response

0 commit comments

Comments
 (0)