PowerShell – Non latin language with REST

#HTTP Headers building
$ContentType= 'application/json; charset=utf-8'
$headers = @{"tenant-code" = $tenantAPIKey; "Authorization"= $BasicCredentials}  

$Message = @{
  MessageBody = "Привет от Камиллы"
  MessageType = "String"

#Convert to JSON Depth at 10 ensure correct convertion for long text
$MessageInJSON = $Message | ConvertTo-Json -Depth 10 

#Convert Message to UTF-8 encoding
$Body = [System.Text.Encoding]::UTf8.GetBytes($MessageInJSON)

#Sending Message using Rest
$Output = Invoke-RestMethod -Method Post -Credential $Credentials -Uri $URI -Body $Body -ContentType $ContentType -Headers $headers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.