Can otrs.SoapRequest return ticket ID/number

Moderator: crythias

Post Reply
ExecMike
Znuny newbie
Posts: 7
Joined: 27 Mar 2017, 09:20
Znuny Version: 5.0.16
Real Name: Mike

Can otrs.SoapRequest return ticket ID/number

Post by ExecMike »

Hello all

Last time I enabled Web service in my OTRS. I'm able to create new tickets using otrs.SOAPRequest.pl script

Code: Select all

#!/usr/bin/perl
# --
# Copyright (C) 2001-2017 xxx, http://otrs.com/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;

## nofilter(TidyAll::Plugin::OTRS::Perl::Dumper)

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);

use SOAP::Lite;
use Data::Dumper;

# Variables to be defined

# this is the URL for the web service
# the format is
# <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/Webservice/<WEB_SERVICE_NAME>
# or
# <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/WebserviceID/<WEB_SERVICE_ID>
my $URL = 'http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorSOAP';

# this name space should match the specified name space in the SOAP transport for the web service
my $NameSpace = 'http://www.otrs.org/TicketConnector/';

# this is operation to execute, it could be TicketCreate, TicketUpdate, TicketGet, TicketSearch
# or SessionCreate. and they must to be defined in the web service.
my $Operation = 'TicketCreate';

# this variable is used to store all the parameters to be included on a request in XML format, each
# operation has a determined set of mandatory and non mandatory parameters to work correctly, please
# check OTRS Admin Manual in order to get the complete list
my $XMLData = '
<UserLogin>some user login</UserLogin>
<Password>some password</Password>
<Ticket>
    <Title>some title</Title>
    <CustomerUser>some customer user login</CustomerUser>
    <Queue>some queue</Queue>
    <State>some state</State>
    <Priority>some priority</Priority>
</Ticket>
<Article>
    <Subject>some subject</Subject>
    <Body>some body</Body>
    <ContentType>text/plain; charset=utf8</ContentType>
</Article>
';

# create a SOAP::Lite data structure from the provided XML data structure
my $SOAPData = SOAP::Data->type( 'xml' => $XMLData );

my $SOAPObject = SOAP::Lite->uri($NameSpace)->proxy($URL)
    ->$Operation($SOAPData);

# check for a fault in the soap code
if ( $SOAPObject->fault() ) {
    print $SOAPObject->faultcode(), " ", $SOAPObject->faultstring(), "\n";
}

# 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)
    for my $ResponseKey ( sort keys %{$Body} ) {
        print Dumper( $Body->{$ResponseKey} );    ## no critic
    }
}
When I run this script it creates a new ticket in OTRS and returns ""500 Server closed connection without sending any data back at otrs.SOAPRequest.pl line 74" which is I believe expected behaviour, but I would like to make it return the ticket ID/number.

I was thinking about using another request type "TicketGet" but then I need to have already TicketID in the request. I would like to do it for one shot, ideally in the same .pl script.

Unfortunately I'm not a perl expert so I would appreciate any tips from you.

Thank you.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Can otrs.SoapRequest return ticket ID/number

Post by reneeb »

I assume, a response should be sent back. So please check your Apache and OTRS logs... And you can debug the Generic Interface (open the webservice in the admin area and click the button "Debugger")
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
ExecMike
Znuny newbie
Posts: 7
Joined: 27 Mar 2017, 09:20
Znuny Version: 5.0.16
Real Name: Mike

Re: Can otrs.SoapRequest return ticket ID/number

Post by ExecMike »

In debuger I found that OTRS generates actually ticket number.
untitled.png
According to the comments in otrs.SOAPRequest.pl it should be printed. However I'm not perl expert and I'd appreciate it if you can let me know whether it should be something added into this script to print ticket number/Article ID/Ticket ID.

Thank you in advance.

Code: Select all

# 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)
    for my $ResponseKey ( sort keys %{$Body} ) {
        print Dumper( $Body->{$ResponseKey} );    ## no critic
    }
You do not have the required permissions to view the files attached to this post.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Can otrs.SoapRequest return ticket ID/number

Post by RStraub »

Mhmm...

try replacing the else block with something simpler. Like from this:

Code: Select all

    # 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)
    for my $ResponseKey ( sort keys %{$Body} ) {
        print Dumper( $Body->{$ResponseKey} );    ## no critic
    }
to this:

Code: Select all

    # get the XML response part from the SOAP message
    my $XMLResponse = $SOAPObject->context()->transport()->proxy()->http_response()->content();
   print Dumper($XMLResponse);

Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Post Reply