Here's a quick how-to on getting attachments out of SM7 via WebService using PHP. There may be nicer/better ways to do this, but this works for me. Some of the code is a tad rough still, but I figured I'd share anyway.
It requires the nusoap library, which can be downloaded from http://sourceforge.net/projects/nuso...3.zip/download
You need to pass in the incident number to get the incident details back. To get an attachment out, you need it's uid number, which can be found in a number of ways. As commented below, I get it via an SQL query, because everything else on my webview for tickets is via SQL.
If anyone has questions or ideas on how to do this better, post away. Hopefully this helps someone else, as there is not a lot of code out there on how to do this in languages other than .NET and JAVA.
Code:<?php require_once('lib/nusoap.php'); /* Some values that we need to make this work. I'm getting them via SQL query to the SYSATTACHMENTS table. You could get them from the webservice call response itself, but for my setup and needs, my way works. SELECT mimetype, size, filename, topic FROM sysattachmem1 where uid='$uid' and segment=0 I'm passing in UID from another page, when I run an SQL to list all the attachments in the record. */ $id="IM0001"; $uid = "4b988a10001a104106608400"; $fileLength = "123"; $fileName = "test.doc"; //Setup our client $client = new nusoap_client("http://<servername>:<port>/SM/7/IncidentManagement.wsdl", 'wsdl'); //It needs to be UTF-8 $client->soap_defencoding = 'UTF-8'; //Possibly not needed $client->decode_utf8 = false; $client->setCredentials("username", "password"); //Namespace - This is required. $namespace = "http://schemas.hp.com/SM/7"; //Paramaters $params= "<ns:RetrieveIncidentRequest attachmentInfo=\"true\" attachmentData=\"true\" ignoreEmptyElements=\"true\"> <ns:model> <ns:keys> <ns:IncidentID>$id</ns:IncidentID> </ns:keys> <ns:instance> </ns:instance> </ns:model> </ns:RetrieveIncidentRequest>"; //Call the function $result = $client->call('RetrieveIncident', $params, $namespace); $output = $client->response; //The start string we're going to look through in the XML response. This signifies the start of the attachment data $firstStart = "Content-ID: $uid"; //The length of this string, so we can get the data after it $firstLength = strlen($firstStart); //The start of our data. I'm adding 4 here because that's what works. Bit of trial and error to work that out. $firstPos = strpos($output, $firstStart) + $firstLength+4; //Get the data from this position to the fileLength $fileData = substr($output, $firstPos, $fileLength); //Set up headers header("Content-disposition: attachment; filename=\"$fileName\""); header("Content-type: application/x-download"); //Echo out the data echo $fileData; ?>


Reply With Quote

Bookmarks