You are not logged in.
Hello,
I'm trying to reply to tickets using the GLPI API, but I'd like some of my replies to include accented characters like 'é', 'è' or 'à' mainly.
It seems every time my message contains an accented character, I get the "ERROR_JSON_PAYLOAD_INVALID" error.
My script is running in PowerShell, and I've tried adding "Charset=UTF-8" to the "Content-Type" of my header without any luck.
Below you'll find the snippet of script that I'm using:
$Global:Headers = @{
"Content-Type" = "application/json; Charset=UTF-8"
"Session-Token" = $SessionToken.session_token
"App-Token" = $AppToken
}
# [...]
function Reply-Ticket ($TicketID, $Message) {
$Body = ConvertTo-Json @{
"input" = @{
"tickets_id" = $TicketID
"content" = "$Message"
}
}
try {
$Output = Invoke-RestMethod -Method POST -Headers $Headers -Body $Body -Uri "$ApiUrl/Ticket/$TicketID/TicketFollowup/"
}
catch {
Add-LogLine "Failed to reply to ticket $TicketID : $($_.Exception.Message)" 2
return
}
}
# [...]
$SessionToken = Init-Session $OD3IUserToken $OD3IAppToken
Reply-Ticket -TicketID 3839 -Message "ééÀÀàè"
Kill-Session $SessionToken $OD3IAppToken
["ERROR_JSON_PAYLOAD_INVALID","JSON payload seems not valid"]
Does anybody know if it's possible to include accented characters when using the API, if so, how do you usually proceed ?
Thank you in advance
Regards,
Offline
I have the same issue today.
Fix for me (to add before your Invoke-RestMethod):
$Body = [System.Text.Encoding]::UTF8.GetBytes($Body)
Last edited by kurgans (2024-04-23 04:01:12)
Offline