01-31-2019 11:12 PM
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.
02-01-2019 04:52 AM
It was this that finally did the trick I suppose, in combination with the correct charset setting?
$body = [System.Text.Encoding]::UTF8.GetBytes($json)
01-31-2019 11:53 PM
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:
02-01-2019 12:04 AM
02-01-2019 12:31 AM
Hmm okay. Try changing this:
"Content-Type" = 'application/json'
To this:
"Content-Type" = 'application/json ; charset=utf-8'
02-01-2019 12:46 AM
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'
}
02-01-2019 12:53 AM
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
$changeI 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
02-01-2019 04:22 AM
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"
$changeI 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.
02-01-2019 04:48 AM
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
02-01-2019 04:52 AM
It was this that finally did the trick I suppose, in combination with the correct charset setting?
$body = [System.Text.Encoding]::UTF8.GetBytes($json)
02-01-2019 05:25 AM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide