App-OTRS-CreateTicket
view release on metacpan or search on metacpan
bin/otrs.CreateTicket.pl view on Meta::CPAN
my @SOAPData;
push @SOAPData, SOAP::Data->name('UserLogin')->value($Param{UserLogin});
push @SOAPData, SOAP::Data->name('Password')->value($Param{Password});
push @SOAPData, SOAP::Data->name(Ticket => \SOAP::Data->value(@TicketData));
push @SOAPData, SOAP::Data->name(Article => \SOAP::Data->value(@ArticleData));
push @SOAPData, SOAP::Data->name(Attachment => @Attachments) if @Attachments;
push @SOAPData, SOAP::Data->name(DynamicField => @DynamicFields) if @DynamicFields;
my $SOAPObject = SOAP::Lite
->uri($NameSpace)
->proxy($URL)
->$Operation(@SOAPData);
# check for a fault in the soap code
if ( $SOAPObject->fault ) {
print $SOAPObject->faultcode, "\n";
print $SOAPObject->faultstring, "\n";
exit 0;
}
# otherwise print the results
else {
# get the XML response part from the SOAP message
my $XMLResponse = $SOAPObject->context()->transport()->proxy()->http_response()->content();
# deserialize response (convert it into a perl structure)
my $Deserialized = eval {
SOAP::Deserializer->deserialize($XMLResponse);
};
# remove all the headers and other not needed parts of the SOAP message
my $Body = $Deserialized->body();
# just output relevant data and no the operation name key (like TicketCreateResponse)
if ( defined $Body->{TicketCreateResponse}->{Error} ) {
print "Could not create ticket.\n\n";
print "ErrorCode: $Body->{TicketCreateResponse}->{Error}->{ErrorCode}\n";
print "ErrorMessage: $Body->{TicketCreateResponse}->{Error}->{ErrorMessage}\n\n";
exit 0;
}
else {
print "Created ticket $Body->{TicketCreateResponse}->{TicketNumber}\n";
}
}
exit 1;
__END__
=head1 NAME
otrs.CreateTicket.pl - create tickets in OTRS via web services.
=head1 SYNOPSIS
Example 1: all arguments on the command line, add attachment
otrs.CreateTicket.pl --Server otrs.example.com --Ssl --UserLogin myname \
--Password secretpass --Title 'The ticket title' \
--CustomerUser customerlogin --Body 'The ticket body' \
--DynamicField Branch="Sales UK" --DynamicField Source=Monitoring \
--Attachment demo.xls --Attachment screenshot.png
Example 2: read body in from a file
otrs.CreateTicket.pl --Server otrs.example.com --Ssl --UserLogin myname \
--Password secretpass --Title 'The ticket title' \
--CustomerUser customerlogin --BodyFile description.txt
Example 3: read body in from STDIN, pending at some date
otrs.CreateTicket.pl --Server otrs.example.com --Ssl --UserLogin myname \
--State 'pending reminder' --PendingTime 2014-10-03T15:00 \
--Password secretpass --Title 'The ticket title' \
--CustomerUser customerlogin < description.txt
Example 4: read body in from STDIN, pending in two hours
otrs.CreateTicket.pl --Server otrs.example.com --Ssl --UserLogin myname \
--State 'pending reminder' --PendingTime 120 \
--Password secretpass --Title 'The ticket title' \
--CustomerUser customerlogin < description.txt
Please note that if you do not specify a --BodyFile or pipe in a file, the
command will expect your input as the ticket body; this is typically not
what you want.
=head1 SYNTAX
otrs.CreateTicket.pl command syntax:
otrs.CreateTicket.pl [arguments]
Arguments:
SERVER CONNECTION
--Server Name of OTRS server.
--Ssl (boolean) If SSL (https) should be used.
Alternatively:
--Url Full URL to GenericTicket web service.
USER AUTHENTICATION
--UserLogin Login name of valid Agent account.
--Password Password for user.
TICKET DATA
--Title Title of ticket.
--CustomerUser Customer of ticket (mandatory!).
--Priority Defaults to '3 normal' if not specified.
--Queue Defaults to 'Postmaster' if not specified.
--Owner Optional.
--Responsible Optional, and only if activated on the server.
--Service Optional, and only if activated on the server.
--SLA Optional, and only if activated on the server.
--Type Optional, and only if activated on the server.
PLEASE NOTE: on version 3.3 or later you might need to
use the value 'Unclassified' as the default changed.
--PendingTime If a number, # of minutes after current time. Otherwise,
should be a string in 'YYYY-MM-DDTHH:MM' format.
( run in 3.387 seconds using v1.01-cache-2.11-cpan-df04353d9ac )