Skip to content

Commit 2126d66

Browse files
authored
Merge pull request #162 from davidhaymond/utf8-fix
Specify UTF-8 in API requests to support Unicode characters
2 parents 529de39 + 6d4534c commit 2126d66

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-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

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@ 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
}
48+
if ($Method -ne 'GET') {
49+
$parameters['ContentType'] = 'application/vnd.api+json; charset=utf-8'
50+
}
4651

4752
$api_response = Invoke-RestMethod @parameters -ErrorAction Stop
4853
} catch {
4954
Write-Error $_
50-
} finally {
51-
[void] ($ITGlue_Headers.Remove('x-api-key')) # Quietly clean up scope so the API key doesn't persist
5255
}
5356

5457
return $api_response

0 commit comments

Comments
 (0)