You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2022-02-03 15:09:39

wlin
Member
Registered: 2022-02-03
Posts: 7

JSON error with accented character when replying to ticket

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

#2 2024-04-23 03:59:53

kurgans
Member
Registered: 2024-04-23
Posts: 1

Re: JSON error with accented character when replying to ticket

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

Board footer

Powered by FluxBB