jsonpowershellcharacter-encodinginvoke-webrequest

Integration for wix.com store api | diacritics problem


annoying problem, maybe you can help me. Trying to pass data into "new product" on wix.com via API), but some of the products contains local signs. After invoke-webrequest is successfully processed (part of code below) on the server end I'm obtaining converted data without diacritics

Trying to enforce charset utf-8, and in $body I'm obtaining proper result,

$headers  = @{
     "Content-Type"  = "application/json"
     "Authorization" = "$auth"
     "charset"       = "UTF-8"
            }
[...]
$obj = @{
    "product" = @{
                "name"        = [string]($product.name)
               }
[...]

$body = $obj | convertto-json -depth 3;
Invoke-WebRequest -Headers $headers -Uri $url  -method POST -body $body 

but on server all diacritics are gone. I believe there should be some possibility to change it, but seems that required some changes on server end. Please correct me if I'm wrong. Any help appreciated. Thanks a lot for all answers.


Solution

  • tl;dr

    Invoke-WebRequest -Headers $headers -Uri $url -Method POST -Body (
      [System.Text.Utf8Encoding]::new().GetBytes($body)
    )
    

    Background information: