I have a script that sends text (names) to a REST api.
I read the names (and other info) from the AD and construct a JSON string and then use Invoke-RestMethod to send the data to the external REST API. They tell med I should send the data in ISO 8859-1 but I only get ? characters for the NLS.
I tried convering the string from UTF to ISO 8859-1 using the value
[Text.Encoding]::GetEncoding(28591)
to convert the string to ISO 8859-1 but no effect.
Tried changing the header
$headers.Add("Content-Type", "application/json; charset=iso-8859-1")
Even tried sending as html encoded (but it gave html encoding in plan text) [System.Net.WebUtility]::HtmlEncode('something ')
Edit:
To get the right text in the json file I have to add the text HMSHåndbøker like this: $handbook1 = "HMSHÃ¥ndbÞker" I guess this is some kind of UTF coding.
`$larray = @{}
$larray.Add("userName",$user.sn)
...
$data = @(@{"accessGranted"="true"; "applicationType"=$handbook1; "subapplicationId"="2";},@{"accessGranted"="true"; "applicationType"=$handbook1; "subapplicationId"="4";},@{"accessGranted"="true"; "applicationType"=$handbook1; "subapplicationId"="5";})
$larray.Add("applicationAccess", $data)
#--------------------------------
# Create json string from array
#--------------------------------
$json = (Convertto-json -Compress -Depth 4 -InputObject @($larray))`
This works if/when I can hardcode a string but if any text from the AD has NLS characters I cannot get them to the correct format.
Any suggestions?
Edit2:
$url = "https://simployeramw.azure-api.net/ItasAPI-V2/importlogon"
$lheaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$lheaders.Add("Content-Type", "application/json")
$lheaders.Add("X-ITAS-PersonIdentifierType", "EmployeeNumber")
$lheaders.Add("X-ITAS-UnitIdType", "DepartmentCode")
$lheaders.Add("Ocp-Apim-Subscription-Key", $CONST_AUTH_SKEY)
$lheaders.Add("Authorization", "Bearer " + $token)
$rc = Invoke-RestMethod $url -Method 'POST' -Headers $lheaders -Body $json