SmartOrg API

The SmartOrg API allows you to build modern Javascript applications on top of SmartOrg's portfolio evaluation technology.

What you need

  • API software
  • Access to our servers
    To receive our software and an account on our servers, please write to us about your interest.

View the API

Take a look at the API documentation which comes with code examples. This is targeted at developers, and relies on some foundational concepts around Portfolio Management.

Using the API

All usage begins with creating a SmartOrg object.

var endpoint = "https://localhost";
var path = "kirk";
var smartorg = new SmartOrg(endpoint, path);

The first step is to authenticate.

var username = ...; // get the username from somewhere
var password = ...; // get the password from somewhere
smartorg.authenticate({'username': username, 'password': password})
 .then(function (userInfo) {
     console.info("user ID " + userInfo.uid + " logged in");
 })
 .catch(function (err) {
     console.error("Error occurred "+err);
 });

Once authentication is complete, you can use the API to use the SmartOrg platform.

Obtain a list of portfolios

You can fetch all the portfolios available to the user.

smartorg.portfolios()
.then(function (portfolios) {
 portfolios.map(function (portfolio) {
     console.log(portfolio);
 })
})
.catch(function (err) {
 console.error(err);
})

Obtain tree for a portfolio

Each portfolio has a tree structure, which you can pull out.

smartorg.treeFor(portfolioName)
.then(function (treeNodes) {
 treeNodes.map(function (treeNode) {
     console.log(treeNode);
 })
})
.catch(function (err) {
 console.error(err);
})

The tree structure is returned as an array of nodes, and each node has an array of children node pointers. You can construct a tree in memory by putting each node into a hash, and recursing starting from the root node.
You can identify the root node in one of two ways:

  • treeID == name
  • parent array is null

One way of doing this could be:

rootNode = treeNodes.filter(
function(treeNode) {
    return treeNode.treeID === treeNode.name;
    // You could also do:
    // return treeNode.parent === null;
})[0];

The rootNode is like any other Node. You can construct your tree visualization by going through a
node's children. To do this, you would first want to construct a dict of all the nodes using treeNodes,
which you obtained earlier with a call to smartorg.treeFor:

var allNodes = {};
treeNodes.forEach(function(treeNode) { 
allNodes[treeNode._id] = treeNode;
});

Now that we have a dict built up, and we also have the rootNode, we can do a simple depth first tree traversal and print out the tree in the console, like so:

function traverse(node, level) {
    var tabs = "";
    for (i=0;i<level;i++) { tabs += "  ";}
    console.log(tabs+node.name);
    node.children.forEach(function(childNodeID) {
        traverse(allNodes[childNodeID], level+1);    
    });
}
traverse(rootNode, 0);

Obtain a node

You can also pull a single node by its id, like so:

smartorg.nodeBy(nodeID).
    then(function(node) {
        console.log(node);
    })

If you have handled your objects efficiently and have the allNodes dict in your context, you may not need to pull in a node individually and can straightaway do a dict lookup.

Obtain action menu for node

The node object gives you structural information that lets you construct an action menu for that node. In order to obtain the action menu associated with any node, you can use actionMenuFor. This function returns a callback that provides a (menu object)[global.html#PromiseActionMenuCallbackSuccess]. Here is an example that prints out the menu action titles of a node in the console:

smartorg.actionFor(nodeID)
    .then(function(menu) {
        menu.menuItems.Actions.forEach(function(action) {
            console.log(action.displayText);
        });
    })
    .catch(function (err) {
        // handleError
    });

You can look at the other attributes of a menu action.

Obtain results of running action

Once you have the action menu item, you can execute the command associated with it and fetch the results. To do this, you would need actionFor.

Here's an example:

 smartorg.actionFor(actionID, nodeID)
    .then(function(data) {

    })
    .then(function(err) {
        // handleError
    }