Code: Select all
use strict;
use warnings;
use utf8;
## nofilter(TidyAll::Plugin::OTRS::Perl::Dumper)
# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use JSON;
use REST::Client;
# This is the HOST for the web service the format is:
# <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl
my $Host = 'http://localhost/otrs/nph-genericinterface.pl';
my $RestClient = REST::Client->new(
{
host => $Host,
}
);
my $CreateControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket';
my $CreateOrUpdateParams = {
UserLogin => "some agent user login", # to be filled with valid agent login
Password => "some agent user password", # to be filled with valid agent password
Ticket => {
Title => 'some ticket title',
Queue => 'Raw',
Lock => 'unlock',
Type => 'Unclassified',
State => 'new',
Priority => '3 normal',
Owner => 'some agent user login',
CustomerUser => 'customer-1',
},
Article => {
Subject => 'some subject',
Body => 'some body',
ContentType => 'text/plain; charset=utf8',
},
};
my $CreateJSONParams = encode_json $CreateOrUpdateParams;
my @CreateRequestParam = (
$CreateControllerAndRequest,
$CreateJSONParams
);
# We have to use REST-POST requests in order to send UserLogin and Password correctly
# though other REST methods would fit better.
$RestClient->POST(@CreateRequestParam);
# If the host isn't reachable, wrong configured or couldn't serve the requested page:
my $CreateResponseCode = $RestClient->responseCode();
if ( $CreateResponseCode ne '200' ) {
print "Create request failed, response code was: $CreateResponseCode\n";
}
else {
# If the request was answered correctly, we receive a JSON string here.
my $ResponseContent = $RestClient->responseContent();
my $Data = decode_json $ResponseContent;
# Just to print out the returned Data structure:
use Data::Dumper;
print "Create Response was:\n";
print Dumper($Data);
}