Skip to content

Instantly share code, notes, and snippets.

@rkaldung
Created October 26, 2021 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkaldung/9d39ccf60ef67c6c2f7e83c112afc612 to your computer and use it in GitHub Desktop.
Save rkaldung/9d39ccf60ef67c6c2f7e83c112afc612 to your computer and use it in GitHub Desktop.
$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 = 'do-not-reply@znuny.com'
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