Docs‎ > ‎Live API Creator Overview‎ > ‎

NodeJS Support

NodeJS is a popular JavaScript-based runtime, with a rich ecosystem of packages.  Packages are easily installed using node npm install. There are two kinds of packages:
  • normal. Provide services for (normal) JavaScript coding.

  • cli. Create tools for command line extensions in Windows command files and Unix shell scripts, e.g., for DevOps scripting.
Live API Creator complements NodeJS npm packages (also described on the npm site) for both. The following examples are drawn from the B2B Sample

Prerequisites:
  • Install NodeJS 4.x. NodeJS provides options for install via brew, or installers - evaluate your options.
Note: Live API Creator is not compatible with Node 5.x.

Note: npm installs apply to all sub folders - they are not inherently global to your machine.  We recommend performing these installs from your lac folder as illustrated here

This page provides a quick overview of installation and usage. For more information, see Admin CLI, (data) CLI, and the Node SDK.

Node SDK

Use this for simplified data access from NodeJS programs.

Install the node APICreatorSDK

The Node SDK library is using npm (Note: Do not use the -g option):

npm install APICreatorSDK

Usage

Here's a quick example from the b2bscripts/scs/projects/test/node/verify.js:

var api = apicreator.connect('http://localhost:8080/rest/default/b2bderbynw/v1', 'Bzn8jVyfOTiIpW6UQCgy');
var ordersEP = api.endpoint('nw:Orders');
ordersEP.get('sysfilter=equal(OrderID:2000)').then(function (data) {
var theOrder = data[0];
if (theOrder.AmountTotal == 301.20 && theOrder.discountedAmount == 298.188) {
console.log("....Success...");
} else {
console.log("** Expected values not found, theOrder...");
}
});

liveapicreator-cli

Use this to access your data from shell / command scripts. Access these as lac (or liveapicreator) commands.

Install the CLI

Install using npm by running the following:

npm install -g liveapicreator-cli

Note: (Unix and Mac) You will probably need to run this with sudo because of file permissions:

sudo npm install -g liveapicreator-cli

(Windows) npm install creates an executable called liveapicreator (or lac as a shortcut) in your <node_modules>/.bin directory. If this directory is not in your PATH, you will probably want to fix that, otherwise you'll have to specify the full path to the executable.

Usage

As shown below, you can login once, and then use that AuthID for multiple commands. See the full example in /b2bscripts/scs/projects/test/lac/postAndVerify.sh:

#! /bin/bash
liveapicreator login -u demo -p Password1 http://localhost:8080/rest/default/b2bderbynw/v1 -a b2b

# Post and read order to b2b Partner
liveapicreator post PartnerOrder -j '{ "CustomerNumber": "VINET","Items": [ {"ProductNumber": 16, "Quantity": 1 },{"ProductNumber": 7,"Quantity": 2}, {"ProductNumber": 14, "Quantity": 3}, {"ProductNumber": 10, "Quantity": 4}, {"ProductNumber": 13, "Quantity": 5}  ] }'

lac get nw:Orders -f 'equal(OrderID: 2000, AmountTotal: 301.20)' --format json

liveapicreator-admin-cli

Use this to access your admin data (API projects, resources, rules, etc) from shell / command scripts.  Access these as lacadmin (or liveapicreatoradmin) commands as shown below:

Install the Admin CLI

As usual:

npm install -g liveapicreator-admin-cli

See the previous Mac and Windows notes. For example, you may require sudo.

Usage

Example from b2bscripts/scs/projects/b2b/build/importnwb2b.sh (similar version for Windows command files):

lacadmin project import --file ../src/b2bnwderby.json
Subpages (1): Configure Windows Path