Good day. I’m testing out how I can create tickets with the Freshservice API, using Powershell. I’m getting a 400 Bad Request error every time I try including characters like Þ, Æ, and Ö, in the description or subject field. If I remove these characters, the tickets are successfully created without any issues.
Has anyone encountered similar problems and found ways to resolve it?
Here are examples of tests I’ve done that have all failed:
$headers = @{
"Authorization" = "Basic $base64AuthInfo"
"Content-Type" = "application/json" #I've also tried specifying charset=utf-8
}
$body = @{
description = "Test with Icelandic characters: Þ, Æ, Ö"
subject = "Test Þema"
email = "<test@email>"
priority = 1
status = 2
} | ConvertTo-Json -Depth 10 -Compress
$jsonBody = @"
{
"description" : "Test with Icelandic characters: Þ, Æ, Ö",
"subject" : "Test Þema",
"email" : "<test@email>",
"priority" : 1,
"status" : 2
}
"@
$utf8Body = [System.Text.Encoding]::UTF8.GetString([System.Text.Encoding]::UTF8.GetBytes($body))
Write-Output "Sending request with json body: $jsonBody"
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $jsonBody
Write-Output "Sending request with json body: $body"
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body
Write-Output "Sending request with json body: $utf8Body"
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $utf8Body
The error outputted is always the same:
Response Body: {"description":"Validation failed","errors":[{"field":"status","message":"It should be one of these values: '2,6,3,7,4,5,8'","code":"missing_field"},{"field":"subject","message":"It should be of type String","code":"missing_field"},{"field":"priority","message":"It should be one of these values: '1,2,3,4'","code":"missing_field"},{"field":"requester_id","message":"One of the following is mandatory: requester_id, phone, email","code":"missing_field"}]}```