Skip to content

Instantly share code, notes, and snippets.

@sugarknowledge
Created November 20, 2012 17:50
Show Gist options
  • Save sugarknowledge/4119576 to your computer and use it in GitHub Desktop.
Save sugarknowledge/4119576 to your computer and use it in GitHub Desktop.
PHP Example using NuSOAP with the v4 SOAP API to create a document
//set_entry result
Array
(
[id] => 5ab53b9d-2f31-9b69-d92b-50abc2d0f6a2
)
//set_document_revision result
Array
(
[id] => 906ad157-0aa0-c01e-2694-50abc2adcbf2
)
<?php
$url = "http://{site_url}/service/v4/soap.php?wsdl";
$username = "admin";
$password = "password";
//require NuSOAP
require_once("./nusoap/lib/nusoap.php");
//retrieve WSDL
$client = new nusoap_client($url, 'wsdl');
//display errors
$err = $client->getError();
if ($err)
{
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
//login -------------------------------------------------------
$login_parameters = array(
'user_auth' => array(
'user_name' => $username,
'password' => md5($password),
'version' => '1'
),
'application_name' => 'SoapTest',
'name_value_list' => array(
),
);
$login_result = $client->call('login', $login_parameters);
/*
echo '<pre>';
print_r($login_result);
echo '</pre>';
*/
//get session id
$session_id = $login_result['id'];
//create document -----------------------------------------------------------------------------------
$set_entry_parameters = array(
//session id
"session" => $session_id,
//The name of the module
"module_name" => "Documents",
//Record attributes
"name_value_list" => array(
//to update a record, you will nee to pass in a record id as commented below
//array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
array("name" => "document_name", "value" => "Example Document"),
array("name" => "revision", "value" => "1"),
),
);
$set_entry_result = $client->call("set_entry", $set_entry_parameters);
echo "<pre>";
print_r($set_entry_result);
echo "</pre>";
$document_id = $set_entry_result['id'];
//create document revision -----------------------------------------------------------------------------------
$contents = file_get_contents ("/path/to/example_document.txt");
$set_document_revision_parameters = array(
//session id
"session" => $session_id,
//The attachment details
"note" => array(
//The ID of the parent document.
'id' => $document_id,
//The binary contents of the file.
'file' => base64_encode($contents),
//The name of the file
'filename' => 'example_document.txt',
//The revision number
'revision' => '1',
),
);
$set_document_revision_result = $client->call("set_document_revision", $set_document_revision_parameters);
echo "<pre>";
print_r($set_document_revision_result);
echo "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment