Skip to content
Advertisement

how to use properly OTRS GenericTicketConnectorSOAP in PHP

I am using PHP version 5.6 . I made a PHP form that have 3 fields, username,password and CSV file upload. The CSV file contains in every line two “number codes” the ticket number and the invoice number divided by “;” , so in that way the CSV have two columns. On the processing code that i wrote, i made the code to read the CSV file line by line and explode the ticket number and the invoice number in two variables. After that, the code making the XML data that need to be sent via GenericTicketConnectorSOAP and perform the Ticket update. My php code is the following:

$URL = 'http://localhost/otrs/nphgenericinterface.pl/Webservice/GenericTicketConnectorSOAP';
$NameSpace = 'http://www.otrs.org/TicketConnector/';
         // SOAP parameters 
$parameters = [
'proxy_host'     => $URL,
'proxy_port'     => 8080,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer'       => false,
'verify_peer_name'  => false,
)
)
)
];
// More code that it is not necessary to post it
//Posting the code that the problem starts
    if(move_uploaded_file($_FILES['file']['tmp_name'],($path . $newfilename))){
echo '<div class="alert alert-primary" role="alert"><p>Success: File uploaded.</p></div>';
                                                     $fn = fopen($path . $newfilename,"r");
  
                                                    while(! feof($fn) )  {
                                                        
                                                    $content = fgets($fn);
                                                    // Divide the ticket number and the invoice number into two variables
                                                    list($ticketnumber,$invoicenumber) = explode(";", $content);
                                                    
                                                    echo "TicketNumber: ".$ticketnumber." Invoicenumber: ".$invoicenumber;
                                                    
                                                
                                                            // Making XMLData 
                                                    
                                                            $XMLData = '<UserLogin>'.$user.'</UserLogin><Password>'.$password.'</Password>';
                                                            $XMLData .= '<TicketNumber>'.$ticketnumber.'</TicketNumber>
                                                            <DynamicField><Name>'.$invoicefield.'</Name>
                                                            <Value>'.$invoicenumber.'</Value></DynamicField>'; 
                                                             // SOAP client
                                                            // extension of php soap NEED TO BE ENABLED ON php.ini
                                                    
                                                            $client = new SoapClient($NameSpace,$parameters);
                                                            $result = $client -> TicketUpdate($XMLData);
                                                                
                                                                if (is_soap_fault($result)) {
                                                                    print_r("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
                                                                    $scarti.=",".$ticketnumber;
                                                                    echo '<div class="alert alert-danger" role="alert"><p>Ticket fault: '.$scarti.'</p></div>';
                                                                }else{
                                                                    echo '<div class="alert alert-success" role="alert"> Success ticket number:'.$ticketnumber.'</div>';
                                                                } 


                                                    } // while ends

My issue shows up on the while loop, where stops on the first row of the CSV file without getting any error message for the SOAP client or the SOAP function call. What possible going wrong here? If i remove the “SOAP code” the loop stops on the latest ticket number, so this has to be something fault on the SOAP client or function. Also, i tested the SOAP connection with this piece of code:

         $handle = curl_init($URL);
                                  curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);
                                  $response = curl_exec($handle);
                                  $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
                                  if($httpCode == 404) {
                                       echo "Connection failed";
                                  }else {
                                        echo "Connection OK";
                                  }  

and the result was “Connection OK”.

UPDATE:

I wrote this piece of code in order to print any error:

    $parameters = [
    'stream_context' => stream_context_create(
    array(
    'ssl' => array(
    'verify_peer => false,
 'verify_peer_name'  => false,
    )
)
)
try{
                                                                   
$client = new SoapClient($URL,$parameters); 
                                    
}catch(Exception $e){
    echo $e->getMessage();
}   

The result was : “SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorSOAP’ : failed to load external entity “http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorSOAP”

Advertisement

Answer

The issue has been solved by adding on php.ini file these lines:

ini_set('soap.wsdl_cache_enabled', '0'); 
ini_set('soap.wsdl_cache_ttl', '0');
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement