- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Special Characters utf8-bom with the API
after updating all the organization name with PowerShell and the API I noticed a formatting error.
Special Characters like øæå are replaced with squares.
Does anyone know what kind of little parameter i need to add in my code to make it support our nordic characters?
any help would be greatly appreciated.
Solved! Go to solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It was this that finally did the trick I suppose, in combination with the correct charset setting?
$body = [System.Text.Encoding]::UTF8.GetBytes($json)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried using URL encoding for those characters? The name parameter ends up as a param in the get URL so depending on how the script works this might be needed.
øæå = %C3%B8%C3%A6%C3%A5
Online converter if needed:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmm okay. Try changing this:
"Content-Type" = 'application/json'
To this:
"Content-Type" = 'application/json ; charset=utf-8'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for your input.
this is my current header:
$header = @{ 'X-Cisco-Meraki-API-Key' = $apikey 'Content-Type' = 'application/json ; charset=utf-8' 'Accept-Language' = 'nb-NO,nb;q=0.9,no-NO;q=0.8,no;q=0.6,nn-NO;q=0.5,nn;q=0.4,en-US;q=0.3,en;q=0.1' }
Ive also tried a few other charsets, like iso and sorts.
also tried this.
$header = @{ 'X-Cisco-Meraki-API-Key' = $apikey 'Content-Type' = 'application/json' 'Accept-Language' = 'nb-NO,nb;q=0.9,no-NO;q=0.8,no;q=0.6,nn-NO;q=0.5,nn;q=0.4,en-US;q=0.3,en;q=0.1' 'Accept-Charset'= 'utf-8, iso-8859-1;q=0.5, *;q=0.1' }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This worked for me:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' $header = @{ "X-Cisco-Meraki-API-Key" = $api_key "Content-Type" = 'application/json ; charset=utf-8' } $api = @{ "endpoint" = 'https://xxxx.meraki.com/api/v0' } $api.url = '/networks/xxxmy-network-idxxxx' $uri = $api.endpoint + $api.url $parms = @{ name = 'My Network øæå' } $json = $parms | ConvertTo-Json $change = Invoke-RestMethod -Method Put -Uri $uri -Body $json -Headers $header $change
I set the encoding of the file to UTF-8 from Notepad++ and then ran it from powershell.
Maybe what Nick did here will also help:
Source: https://stackoverflow.com/questions/21598398/wrong-encoding-on-powershell-invoke-webrequest-post
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i appreciate your responses. i tried them in both vscode(with all types of encoding) and in ISE.
i also tried this
$change = Invoke-RestMethod -Method Put -Uri $updateuri -Body $json -Headers $header -ContentType "text/plain; charset=utf-8" $change
I have a support case open with meraki. ill see if they can come up with something.
i have not tried to do the same with a network name. cant think of any reasons why there would be a difference between network name and org name, but there might be.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
found a solution based on your reply.
$header = @{ "X-Cisco-Meraki-API-Key" = $apikey "Content-Type" = 'application/json ; charset=utf-16' } $customuri = $org.samlConsumerUrl.Split('/')[2].split('.')[0] $updateuri = 'https://{1}.meraki.com/api/v0/organizations/{0}' -f $org.id,$customuri $parms = @{ name = $WantedName } $json = $parms | ConvertTo-Json $body = [System.Text.Encoding]::UTF8.GetBytes($json) $change = Invoke-RestMethod -Method Put -Uri $updateuri -Body $body -Headers $header $change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It was this that finally did the trick I suppose, in combination with the correct charset setting?
$body = [System.Text.Encoding]::UTF8.GetBytes($json)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it was probably just that one-liner.
i tested with a bunch of different header parameters and running powershell in different charsets.
glad you pointed me to the solution though!
I believe it converts the data to bytes, and just sends the bytes, ignoring charsets or something.
