I'm trying to download a file from Sharepoint library via web service with nusoap client. I'm able to connect and get List content using Lists.wsdl but I'm having trouble figuring out the parameters for Copy.wsdl methods.
<?php
require_once('lib/nusoap.php');
$username = 'domain\user';
$password = 'secret';
$rowLimit = '0';
$listGuid = "{0379989D-8639-430B-9FD0-96551B7EAB29}";
//Lists.wsdl copied from the Sharepoint site and stored on local drive
$wsdl = "http://localhost/sp/Lists.wsdl";
//NTLM authentication.
$client = new nusoap_client($wsdl, true);
$client->setCredentials('','','ntlm');
$client->useHTTPPersistentConnection();
$client->setCurlOption(CURLOPT_USERPWD, $username.':'.$password);
//XML for the request
$getItemsXml ='
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>'.$listGuid.'</listName>
<rowLimit>'.$rowLimit.'</rowLimit>
</GetListItems>
';
//This works and returns requested data from a list
$result = $client->call('GetListItems', $getItemsXml);
$responseContent = substr($client->response,strpos($client->response, "<"),strlen($client->response)-1);
//This part does not work
//Library ID
$fileGuid = "{A24306B5-50E9-44C0-9728-69E2D015B689}";
$cwsdl = "http://localhost/sp/Copy.wsdl";
$cclient = new nusoap_client($cwsdl, true);
$cclient->setCredentials('','','ntlm');
$cclient->useHTTPPersistentConnection();
$cclient->setCurlOption(CURLOPT_USERPWD, $username.':'.$password);
//This is where I get lost
$fileParams = array();
$cResult = array(0);
$fieldInformationCollection = array('fieldInformation'=>array('DisplayName'=>'', 'Id'=>'', 'InternalName'=>'', 'Type'=>'', 'Value'=>''));
$content = array('');
$fileParams[] = "http://site.example.com/subsite/folder/somefile.pdf";
$fileParams[] = $cResult;
$fileParams[] = $fieldInformation;
$fileParams[] = $content;
//This call fails
$result = $cclient->call('GetItem', $fileParams);
?>
Debug info from the failed call shows that some of the parameters are wrong but I can't figure it out.
wsdl: in serializeType: uqType: GetItem, ns: http://schemas.microsoft.com/sharepoint/soap/, phptype: struct, arrayType:
wsdl: in serializeType: phpType is struct, but value is not an array
wsdl: in serializeType: returning:
wsdl: serializeRPCParameters returning:
nusoap_client: got wsdl error: phpType is struct, but value is not an array: see debug output for details
I've tried reading (and understanding) the Copy.wsdl file and complete debug output, but no dice.
Anybody got this working? Thanks.
So after several more hours of debugging I have found out that the answer is amazingly simple. The only parameter that needs to be sent is URL of the file to be downloaded like this:
//Set URL of the file
$file['Url'] = 'http://site.example.com/subsite/Folder/requested_file.ext';
//Call nusoap client
$result = $cclient->call('GetItem', $file);
The parameter needs to be an associative array with single element called 'Url'.
The client will return an array with elements 'GetItemResult' (set to 0 on success), 'Fields' (an array of 75 arrays with various informations about the file from the library) and finally 'Stream' which contains Base64 encoded file contents in a string.
file_put_contents('c:/temp/requested_file.ext', base64_decode($result['Stream']));