5

I try to interact with the otrs-ticketsystem in order to make a few pictures and calculate some statistics. This I want to do in haskell - I use the package soap.

Ignoring the import statements the code is fairly straightforward, I create a SOAP-Transport with config file soap.cfg (see below). Then construct the SOAP-Body and call the web service with "Dispatch".

{-# LANGUAGE OverloadedStrings #-}

import Network (withSocketsDo)
import Network.SOAP
import Network.SOAP.Transport.HTTP

import Text.XML.Writer
import Text.XML.Stream.Parse as Parse
import           Data.Text (Text)
import qualified Data.Text as T
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Configurator (load, Worth(Required))

main :: IO ()
main = withSocketsDo $ do
    transport <- confTransport "soap" =<< load [Required "./src/SOAP/soap.cfg"]
    let body = do element "TicketObject" ("TicketSearch" :: Text)
                  element "OwnerID" ("owner" :: Text)

    xmlresult <- invokeWS transport "#TicketObject" () body (RawParser id)
    BS.putStrLn xmlresult

soap.cfg

soap {
    url = "http://domain/otrs/rpc.pl"
    user = "testuser"
    password = "testpass"
    trace = true
    timeout = 15
    }

If I build and call this program I get the following xmlresult:

request:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <TicketObject>TicketSearch</TicketObject>
        <OwnerID>heu</OwnerID>
    </soapenv:Body>
</soapenv:Envelope>

response:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
    soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Client</faultcode>
            <faultstring>
                SOAPAction shall match 'uri#method' if present (got 'Dispatch', expected '#TicketObject'
            </faultstring>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

If I then change the line following line

xmlresult <- invokeWS transport "Dispatch" () body (RawParser id)

to

xmlresult <- invokeWS transport "#TicketObject" () body (RawParser id)

the faultstring becomes

<faultstring>
    Denied access to method (TicketObject) in class (main) at /opt/otrs/Kernel/cpan-lib/SOAP/Lite.pm line 2810.
</faultstring>

I searched the internet for some solution, I only found this

with the last one I successfully managed to get a result - but only for iPhoneObject and TicketGet - unfortunately TicketSearch seems not to be supported.

Can anybody tell me what valid XML for the request needs to look like?

I also found How to create an otrs ticket using a soap request .Net - which uses web services - but unfortunately I do not know how to create such a service.

Community
  • 1
  • 1
epsilonhalbe
  • 15,637
  • 5
  • 46
  • 74
  • If anyone is asking why I use haskell instead of perl, php or java - well it is the language I am most confident in – epsilonhalbe Oct 18 '14 at 22:01
  • according to [TicketSearch](https://doc.otrs.com/doc/api/otrs/7.0/Perl/Kernel/System/Ticket/TicketSearch.pm.html) documentation `OwnerID` should be replaced by `OwnerIDs` – palik Mar 16 '19 at 10:47

1 Answers1

0

You'll find a XML-snippet in Using javax.xml.soap to access OTRS SOAP service without WSDL.

Here a request's trace produced by perl script

Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 707
Content-Type: text/xml; charset=utf-8
SOAPAction: "/Core#Dispatch"

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><Dispatch xmlns="/Core"><Username xsi:type="xsd:string">foo</Username><Password xsi:type="xsd:string">bar</Password><Object xsi:type="xsd:string">TicketObject</Object><Method xsi:type="xsd:string">TicketSearch</Method><Param1_Name xsi:type="xsd:string">TicketID</Param1_Name><Param1_Value xsi:type="xsd:int">561141</Param1_Value></Dispatch></soap:Body></soap:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x557656ccebb0)
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
Connection: close
Date: Mon, 18 Mar 2019 16:35:20 GMT
Vary: Accept-Encoding
Content-Length: 416
Content-Type: text/xml; charset=utf-8
Client-Date: Mon, 18 Mar 2019 16:35:21 GMT
Client-Peer: 85.239.118.197:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
Client-SSL-Cert-Subject: /OU=Domain Control Validated/OU=EssentialSSL Wildcard/CN=*.pyur.com
Client-SSL-Cipher: ECDHE-RSA-AES128-GCM-SHA256
Client-SSL-Socket-Class: IO::Socket::SSL
Set-Cookie: TS0179c75b=013dfe6b3e1266bc1210a8bb5e6a9352943012e3f1d5767b07f5ec8a310bb53c004c09e467d982f0117fe8a3f6aa1dee4e812153c4; Path=/; Domain=.ticketsystem.pyur.com
SOAPServer: SOAP::Lite/Perl/1.11

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><DispatchResponse xmlns="/Core" xsi:nil="true" /></soap:Body></soap:Envelope>
palik
  • 2,425
  • 23
  • 31