Created
October 26, 2021 11:41
-
-
Save rkaldung/9d39ccf60ef67c6c2f7e83c112afc612 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$user = "John.Doe" | |
$pass = "VerySecret" | |
$uri = "https://FQDN/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST" | |
$headers = @{} | |
$headers.Add("Accept", "application/json") | |
$headers.Add("Content-Type", "application/json") | |
# Create Ticket | |
# Parameter see https://github.com/znuny/Znuny/blob/dev/Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm#L69 | |
# Read attachment and encode (please prepare one with the used filename) | |
$Content = Get-Content lorem-ipsum.txt | |
$ContentBytes = [System.Text.Encoding]::UTF8.GetBytes($Content) | |
$ContentEncoded = [System.Convert]::ToBase64String($ContentBytes) | |
$TicketData = @{ | |
UserLogin = $user | |
Password = $pass | |
Ticket = @{ | |
Title = 'Tickettitle' | |
QueueID = 1 | |
State = 'new' | |
Priority = '3 normal' | |
CustomerUser = '[email protected]' | |
Type = 'Unclassified' | |
} | |
Article = @{ | |
Subject = 'The article subject' | |
Body = 'Test' | |
ContentType = 'text/plain; charset=utf8' | |
MimeType = 'text/plain' | |
Charset = 'utf8' | |
} | |
Attachment = @{ | |
Content = $ContentEncoded | |
ContentType = 'text/plain' | |
Filename = 'lorem-ipsum.txt' | |
} | |
} | |
$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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment