API Implementation Guide

Overview

The InterWorx Application Programming Interface (API) provides programmatic access to NodeWorx and SiteWorx features and services. Developers can build custom applications, tools, and services that correspond to the same services and tools available through your InterWorx installation, or simply automate tasks. The API is based on open standards known collectively as “Web Services,” which include XMLRPC, SOAP, and the Web Services Definition Language (WSDL). These standards are supported by a wide range of development tools on a variety of platforms.

Programming Language Support

Since the API requests and responses in the InterWorx API follow current standards, any programming language with the appropriate library support can be used.

WSDL Location (SOAP)

The WSDL Schema is exposed at:

https://%%SERVERNAME%%:2443/soap?wsdl

XMLRPC Point of Contact

Example API Connection in PHP

Here is an example using PHP to connect to the InterWorx API. Please see the API Specifications for detailed information about each action.

This example shows multiple ways to accomplish the same thing. Please review it carefully and choose the methods that best fit your needs.
<?php
/*
 * The key can be provided in several ways for authentication
 *
 * The simplest way is to authenticate as the NodeWorx or SiteWorx user
 * you wish to execute as.
 */
$key = array( 'email'    => 'nodeworxlogin@example.com',
              'password' => 'nodeworxpass' );
/* OR */
$key = array( 'email'    => 'siteworx@siteworx.com',
              'password' => 'siteworxpass',
              'domain'   => 'example.com' );

/*
 * Alternately, you can provide an active SESSION_ID
 *
 * You can retrieve the session id by using an alternate authentication
 * method and then calling the getSession action on the NodeWorx or
 * SiteWorx Index controllers.
 */
$key = array( 'sessionid' => '3c8ae9d982edd507428d8fdd53855a77' );

/*
 * Finally, if you have access to an API key, you can provide that.
 *
 * Copy and paste the entire contents of the API Key field in NodeWorx.
 */

// NodeWorx
$key =
'-----BEGIN INTERWORX API KEY-----
...
-----END INTERWORX API KEY-----';              

// SiteWorx
$key = array( 'domain' => %%YOURDOMAIN%%,
              'apikey' => '-----BEGIN INTERWORX API KEY-----.....' );
/*
 * The example below shows you how to use the API to add a secondary
 * nodeworx user.
 */

$api_controller = '/nodeworx/users';
$action         = 'add';

// Be aware that even actions that require no input still require the parameter
// Just pass in an empty array
$input = array( 'nickname'         => 'Example User',
                'email'            => 'exampleuser@example.com',
                'language'         => 'en-us',
                'theme'            => 'interworx',
                'password'         => 'pass',
                'confirm_password' => 'pass',
                'perms'            => array( 'LOGIN', 'SWACCOUNTS' ) );

$params = array( 'apikey'    => $key,
                 'ctrl_name' => $api_controller,
                 'action'    => $action,
                 'input'     => $input );

// You can connect using XMLRPC, like this:
// NOTE: You'll need to have included the Zend Framework to do this
$client = new Zend_XmlRpc_Client( 'https://%%SERVERNAME%%:2443/xmlrpc' );
$result = $client->call( 'iworx.route', $params );

// Or, you can use SOAP, like this:
// NOTE: if SOAP is missing, try 'yum install php-soap'
$client = new SoapClient( 'https://%%SERVERNAME%%:2443/soap?wsdl' );
$result = $client->route( $key, $api_controller, $action, $input );
?>

Output

The output of the API is an associative array with two indexes.

array( 'status'  => 0, // 0 means success, everything else doesn't
       'payload' => 'message or data' );
#!/usr/bin/perl -w

#You must install the RPC::XML perl module.
require RPC::XML;
require RPC::XML::Client;

# This is the connection to the XMLRPC service to communicate with the API
$cli = RPC::XML::Client->new('https://%%SERVERNAME%%:2443/xmlrpc');

#This is the API key stuct, pass authentication information here.
$apikey = RPC::XML::struct->new({
			'email' =>  	RPC::XML::string->new('siteworx@siteworx.com'),
			'password' => 	RPC::XML::string->new('yourpassword'),
			'domain' =>	RPC::XML::string->new('%%YOURDOMAIN%%')
			});

#This is the API controller
$ctrl_name = RPC::XML::string->new('/siteworx/email/alias');

#This is the API Action
$action = RPC::XML::string->new('add');

#This is how you pass the input, in a struct.
$input = RPC::XML::struct->new({
				'username' =>  	RPC::XML::string->new('example'),
				'forwardsto' => RPC::XML::string->new('someone@somewhere.com')
				});

#This generates a pointer to an RPC::XML::struct object, which contains the API's output
my $resp = $cli->send_request('iworx.route', $apikey, $ctrl_name, $action, $input);

#value() gives a pointer to a native PERL hash table. This will contain the "status"
#  and "payload" keys if the XMLRPC communication with the API was successful. If
#  there was a problem and you sent bad data to the API, they keys will be "faultString"
#  and "faultCode". You may want to do some error checking here.
my $results = $resp->value();

#This assumes that we communicated properly with the API, and got a valid response from it.
#We check the key "staus". If it's 0, the add alias worked out!
if ($results->{status} == 0){
	print "Success!\n";

} else {
	print "Failure!\n";
}

#This is here to print out the payload. The payload can be delivered in an array or as a string,
#depending which controller/action you are using.
if (ref($results->{payload}) eq 'ARRAY') {
	print "Payload is an array.\n";
	my @payload = @{$results->{payload}};
	foreach (@payload)
	{
		my @key = @{$_};
		print "@key" . "\n";
	}
} else {
	print "Payload is a string.\n";
	print $results->{payload};
}

status

The status should be 0 if things went according to plan. If it's not 0, things did not go according to plan. Plan accordingly.

status 401

If you receive code 401, that indicates an authentication error.

payload

The payload can be a string (either a success or failure message) or an array of data (for example if you called one of the list* actions).

Special Actions for Testing

There are a few actions that exist to help with testing your application. These don't actually DO anything, so they're safe to call over and over.

The actions are on every single controller.

winCommit

Simply returns a "success" status. Use to test that your login code works.

failCommit

Returns an unsuccessful status. Use to test error handling.