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.

All examples given are in PHP

WSDL Location (SOAP)

The WSDL Schema is exposed at:

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

XMLRPC Point of Contact

Example API Connection

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.
 */
$key =
'-----BEGIN INTERWORX API KEY-----
...
-----END 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/nodeworx/xmlrpc-api' );
$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/nodeworx/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' );

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).

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WP Hashcash