Powershell Syntax REST API OTRS

Hallo OTRS-Community, ich verzweifle gerade an der korrekten Powershell-Syntax eines Aufrufes über die REST-Schnittstelle zu OTRS. Folgender Aufruf funktioniert nicht: $servername="https://service-it.augsburg.de/otrs/nph-genericinterface.pl/Webservice/Gener..." $content = @' \"Ticket\":{\"Title\":\"REST Create Test\", \"Type\": \"Unclassified\", \"Queue\":\"Servicedesk\",\"State\":\"open\",\"Priority\":\"3 normal\",\"CustomerUser\":\"customer\"},\"Article\":{\"Subject\":\"Rest Create Test\",\"Body\":\"This is only a test\",\"ContentType\":\"text/plain; charset=utf8\" '@ $OTRS= Invoke-WebRequest -Uri $servername -Body @{content=$content} -Method Post $OTRS.content Fehlermeldung: Invoke-WebRequest : Error while decoding request content. In Zeile:1 Zeichen:7 + $RT = Invoke-WebRequest -Uri $servername -Body @{content=$content} -M ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand Hat mir jemand ein funktionierendes Beispiel? Gruß, Thomas

Hallo Thomas,
On Aug 9, 2019, at 1:24 PM,
wrote: Hat mir jemand ein funktionierendes Beispiel?
Klar, allerdings mit Session statt Username/Passwort. Sollte aber kein Problem sein. $headers = @{} $headers.Add("Accept", "application/json") $headers.Add("Content-Type", "application/json”) $TicketData = @{ SessionID = $SessionID Ticket = @{ Title = 'Tickettitle' QueueID = 1 State = 'new' Priority = '3 normal' CustomerUser = 'no-reply@xxx.com' Type = 'Unclassified' } Article = @{ Subject = 'The article subject' Body = 'Test' ContentType = 'text/plain; charset=utf8' MimeType = 'text/plain' Charset = 'utf8' } } $json = $TicketData | ConvertTo-Json $Result = Invoke-RestMethod -Method Post -Headers $Headers -ContentType 'application/json' -Uri "$uri/Ticket" -Body $json Write-Host Created ticket $Result.TicketNumber - Roy -- Roy Kaldung
participants (2)
-
Roy Kaldung
-
Thomas.Thoma@augsburg.de