Simple Groupware SOAP Server
Beginning with Simple Groupware 0.6x, a full SOAP server is included. To get all available functions, open this URL in your browser:
http(s)://<sgs-server>/<sgs-dir>/bin/soap.php
Example Output:
Simple Groupware & CMS Simple Groupware Soap/Ajax Functions
/**
* Returns the method's input arguments * * @return mixed Returns the methods input arguments */
get_echo( )
/**
* Returns assets from the database * * @param int|string $folder Folder ID or String (/Workspace/.../) * @param string $view View name (e.g. display, details) * @param string $fields field1,field2 or * (optional) * @param string $order field-name asc|desc (optional) * @param int|string $limit Numeric limit or offset,limit (optional) * @param array $items Asset-IDs (optional) * @return array Array with associative Arrays for each asset found */
asset_get_rows( $folder, $view, $fields=*, $order=, $limit=, array $items=Array )
To start your own implementation of a SOAP client, you can use the following code.
Read some datasets from a folder
header ( 'Content-Type: text/html; charset=utf-8' );
try {
// Connect $client = new sgsSoapClient(); // Try to read some assets $folder = '<folder-id>'; $view = 'display'; print_r( $client->asset_get_rows( $folder, $view ) );
}
catch ( SoapFault $e ) {
// output error messages, trace information echo 'Error: <pre>'; echo $e->getMessage(), "\n\n"; echo $e->getTraceAsString(), "\n\n"; echo htmlspecialchars( $client->getDebugInformation(), ENT_QUOTES ); echo '</pre>';
}
Create a new dataset (e.g. a task)
header ( 'Content-Type: text/html; charset=utf-8' );
try {
// Connect $client = new sgsSoapClient(); // Try to create an asset $folder = '<folder-id>'; $view = 'new'; $data = array( 'subject' => 'Example task', 'begin' => '01/01/2010', 'ending' => '01/02/2010', ); // Success: returns the ID // Failure: returns an array: // Array( field_name => Array( Array( field_displayname,
// error_message ),... ), ... ) print_r( $client->asset_insert( $folder, $view, $data ) );
}
catch ( SoapFault $e ) {
// output error messages, trace information echo 'Error: <pre>'; echo $e->getMessage(), "\n\n"; echo $e->getTraceAsString(), "\n\n"; echo htmlspecialchars( $client->getDebugInformation(), ENT_QUOTES ); echo '</pre>';
}
Change an existing dataset (e.g. a task)
header ( 'Content-Type: text/html; charset=utf-8' );
try {
// Connect $client = new sgsSoapClient(); // Try to create an asset $folder = '<folder-id>'; $view = 'edit'; $id = '8101'; $data = array( 'subject' => 'Example task changed', 'begin' => '01/15/2010', 'ending' => '01/17/2010', ); // Success: returns the ID // Failure: returns an array: // Array( field_name => Array( Array( field_displayname, // error_message ),... ), ... ) print_r( $client->asset_update($folder, $view, $data, $id ) );
}
catch ( SoapFault $e ) {
// output error messages, trace information echo 'Error: <pre>'; echo $e->getMessage(), "\n\n"; echo $e->getTraceAsString(), "\n\n"; echo htmlspecialchars( $client->getDebugInformation(), ENT_QUOTES ); echo '</pre>';
}
sgsSoapClient class
/**
* Simple Groupware SOAP Client Example * * @author Simple Groupware Solutions Thomas Bley */
class sgsSoapClient
{
/**
* Default server URL
*
* @var string
*/
private $_url = 'http(s)://<sgs-server>/<sgs-dir>/bin/soap.php';
/**
* Default server username
*
* @var string
*/
private $_username = '<username>';
/**
* Default server password
*
* @var string
*/
private $_password = '<password>';
/**
* Soap client object
*
* @var object
*/
private $_client = null;
/**
* Connect to Soap server
*
* @param string $url Soap server URL
* @param string $username Username
* @param string $password Password
*/
public function __construct( $url = null, $username = null, $password = null )
{
if ( $url !== null ) {
$this->_url = $url;
}
if ( $username !== null ) {
$this->_username = $username;
}
if ( $password !== null ) {
$this->_password = $password;
}
$this->_client = new SoapClient ( null, array(
'location' => $this->_url, 'uri' => '',
'trace' => true,
'login' => $this->_username,
'password' => $this->_password ) );
$this->testGetEcho();
}
/**
* Makes a remote soap call
*
* @param string $name Soap function name
* @param array $arguments Soap function arguments
*/
public function __call( $name, $arguments )
{
return $this->_client->__soapCall( $name, $arguments );
}
/**
* Verifies the server functionality over the echo function
*/
public function testGetEcho()
{
$text = array( 'test text', 'test text 2' );
$result = $this->_client->get_echo( $text[0], $text[1] );
if ( $text !== $result ) {
throw new Exception( 'get_echo result mismatch: result: '.
print_r( $result, true ) . ' expected: ' . print_r( $text, true ) );
}
}
public function getDebugInformation()
{
return print_r( array(
'request_headers' => $this->_client->__getLastRequestHeaders (),
'request' => $this->_client->__getLastRequest (),
'response_headers' => $this->_client->__getLastResponseHeaders (),
'response' => $this->_client->__getLastResponse ()
), true );
}
}
Run SOAP functions from the PHP console
Instead of using the Simple Groupware SOAP Server, you can use all commands directly from the built-in PHP console:
To run SOAP functions from the console, you need to replace "$client->" with "ajax::".
Example: create a new task from the PHP console
Login as the super administrator, click "PHP console" on the administration page and enter this code:
$folder = '2101';
$view = 'new';
$data = array(
'subject' => 'Example task', 'begin' => '01/01/2010', 'ending' => '01/02/2010',
);
print_r( ajax::asset_insert( $folder, $view, $data ) );
Then click "Execute" and you're done.
Note: All folders can be referenced also as a path, e.g. instead of '2101', you can also use '/Workspace/Demo/Tasks'.