OTRS5 Webservices - OTRS as requester

Moderator: crythias

Locked
MarkJ
Znuny newbie
Posts: 1
Joined: 24 Nov 2016, 18:07
Znuny Version: OTRS5

OTRS5 Webservices - OTRS as requester

Post by MarkJ »

Hi there,
I am struggling with the following project:
Our support staff is using NextCloud/OwnCloud to exchange files with their customers. They usually do create an OwnCloud share per ticket. I started working on a solution to automate this task once a new ticket is created, which involves a SOAP webservice written in PHP which will create the appropriate folder within OwnCloud's file system and then trigger OC to rescan the affected directory. The webservice requires a static username, a password and the ticket number. The webservice is working properly and returning an return code, which was successfully tested using SoapUI.

I started to deal with OTRS' webservice settings and tried to write an invoker which is event driven (TicketCreate). Unfortunately I cannot find any helpful example. It does trigger the webservice though but I have no glue on how to pass username, password and ticket number. As mentioned, I've searched the internet for hours but not found any explanation or example I userstood.

I would really appreciate if someone could point me to the right direction

Here is what I've got:
The invoker NextCloud.pm

Code: Select all

#!/usr/bin/perl -w
# --
# --
package Kernel::GenericInterface::Invoker::Test::NextCloud;
#use Kernel::System::Ticket;

use strict;
use warnings;

# 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
my $URL = 'https://transfer.myserver.local/webservices/index.php';

# this name space should match the specified name space in the SOAP transport for the web service.
my $NameSpace = 'createFolder';

# 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 = 'createFolder';

# 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 the OTRS Admin Manual in order to get a complete list of parameters.
my $XMLData = '
<username>ssdfjsdfm</username>
<password>uij8k1lam9m3§9</password>
<structure>Ticketnumber</structure>  # <- How do I get the actual ticket number in here?
';



# ---

# 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 ( keys %{$Body} ) {
        print Dumper( $Body->{$ResponseKey} );
    }
}
The webservice's WSDL:

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<definitions name='CloudServices'
  targetNamespace='urn:NextcloudCloudServices'
  xmlns:tns='urn:NextcloudCloudServices'
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
  xmlns='http://schemas.xmlsoap.org/wsdl/'>

<message name='createFolderRequest'>
  <part name='username' type='xsd:string'/>
  <part name='password' type='xsd:string'/>
  <part name='structure' type='xsd:string'/>
</message>
<message name='createFolderResponse'>
  <part name='Result' type='xsd:string'/>
</message>

<portType name='CloudServicesPortType'>
  <operation name='createFolder'>
    <input message='tns:createFolderRequest'/>
    <output message='tns:createFolderResponse'/>
  </operation>
</portType>

<binding name='CloudServicesBinding' type='tns:CloudServicesPortType'>
  <soap:binding style='rpc'
    transport='http://schemas.xmlsoap.org/soap/http'/>
  <operation name='createFolder'>
    <soap:operation soapAction='urn:xmethods-delayed-quotes#createFolder'/>
    <input>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </input>
    <output>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </output>
  </operation>
</binding>
<service name='CloudServicesService'>
  <port name='CloudServicesPort' binding='CloudServicesBinding'>
    <soap:address location='https://transfer.myserver.local/webservices/index.php'/>
  </port>
  </service>
</definitions>
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: OTRS5 Webservices - OTRS as requester

Post by jojo »

we have a free module for our Professional and Enterprie level customers. Just contact sales@otrs.com

As creating an invoker is not as easy without deeper knowlege of OTRS development you can try to trigger the script via Generic Agent instead.
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
Locked