Kibo eCommerce Node SDK

This topic explains how to develop Kibo eCommerce applications using the Kibo eCommerce Node SDK.

Before You Begin

Install the following software on your local machine:

In addition to the listed software, you need access to a Dev Center Account that contains a provisioned sandbox.

Don't have a Dev Center Account? Request a Demo

Get Started

The following steps guide you through installing the Kibo eCommerce Node SDK, authenticating your project with your Kibo eCommerce credentials, and making a call to the Kibo eCommerce API. Specifically, the tutorial demonstrates how to create a console application that retrieves the number of customer accounts for a Kibo eCommerce site, teaching you the necessary concepts for then building a fully-fledged application of your own.

Create a Kibo eCommerce application in Dev Center with the appropriate behaviors:

  1. Log in to Dev Center.
  2. Create a new Kibo eCommerce application.
  3. Add the Customer Read behavior to the application. This step is necessary to give your application the necessary permissions to read customer accounts. If you design additional functionality for your application, such as updating an order, add the appropriate behaviors to avoid a permissions error.
  4. Install the application to the sandbox of your choice.
  5. Enable the application in Admin.Note:  If you decide to add additional behaviors to your application after this step, you must reinstall the application to your sandbox and re-enable the application in Admin to apply the new behaviors.
  6. Note the application key, shared secret, tenant ID, and site ID. Tip:  You can obtain the application key and shared secret from the application details page. You can obtain the tenant ID and site ID by viewing your live site through Site Builder and looking at the URL, which has the pattern tTenantID‑ You can obtain the master catalog ID through a GetTenant API call, which also returns the tenant ID and site ID, but the master catalog ID is not required for the API call used in this tutorial.

Create a Node.js application that uses the Kibo eCommerce Node SDK:

  1. Create a new directory on your local machine.
  2. Open a command prompt in the new directory.
  3. Run npm init to create a package.json file in your directory. When prompted, provide a name for your npm package and accept the default values for the remaining prompts, making sure that the entry point for your application is index.js.Tip:  When you build a fully-fledged application, you can customize these responses, instead of accepting the default values like you do for this tutorial.
  4. Run npm install --save mozu-node-sdk to install the Kibo eCommerce Node SDK.
  5. In your project's root directory, create a file called mozu.config.json. Specify your application configuration data within this file, as shown in the following code block, replacing the placeholder values with your application-specific values: Note:  You must remove the comments from the code below. They are provided for instructional purposes, but will error your application because the JSON format does not support comments.
    	"appKey": "yourAppKey",
    	"sharedSecret": "yourSharedSecret",
    	"tenant": 12345,
    	"site": 12345,
    	"master-catalog": 12345, // not required for tutorial - shown for educational purposes
    	"baseUrl": "", // the base url for generating auth tickets - this value is always "" unless you are on an internal server
    	"basePciUrl" : "", // used to create credit cards in Mozu. "" for sandboxes, "" for production tenants
    	"developerAccountId": 1234, // unique ID of the developer account contacting App Dev - not required if you are not calling App Dev services 
    	"developerAccount": { // not required for this tutorial
    		"emailAddress": "" // the dev account email for authenticating to Arc.js and theme sync tools

Make a call to the Kibo eCommerce API in your main program file:

  1. In your project root directory, create a file called index.js.
  2. Code index.js to match the following example, which obtains a Kibo eCommerce API context, creates a customer account resource, and uses the getAccounts function to return the number of customer accounts on the tenant:
    // generate an API context based on config data by using application.js in the specified SDK directory
    var apiContext = require('mozu-node-sdk/clients/platform/application')();
    // create a customer account resource from the customerAccount.js file in the specified SDK directory
    var customerAccountResource = require('mozu-node-sdk/clients/commerce/customer/customerAccount')(apiContext);
    // log the customer accounts objects and the total number of accounts, using the JavaScript Promise programming structure
    customerAccountResource.getAccounts().then(function (accounts) {
    	console.log("Number of Customer Accounts:");
    }).catch(function(error) {
  3. In your project directory, run node index.js. The application logs the number of customer accounts to the console.

About the Toolkits

NPM Package Name Description
mozu-node-sdk The Kibo eCommerce Node SDK package.

View the source on GitHub

SDK Function Reference

The Kibo eCommerce Node SDK provides dozens of built-in functions that help you interact with the Kibo eCommerce API quickly and easily. To familiarize yourself with these functions:

  1. View the SDK source on GitHub or in the node_modules/mozu-node-sdk/clients directory that gets installed in your project folder.
  2. Dig through the source files or use the repository search box (on GitHub) to find the function you are looking for. The files mirror the structure of the Kibo eCommerce API.

For example, to find the functions related to customer segments, you would view the customerSegment.js file located in the node_modules/clients/commerce/customer directory.