API Creation by NodeJS

Building node applications can be useful for scripting operations. You can configure node applications to integrate into command lines. For example, a common operation is to move a system from development to production. Use the information on this page to build a node application you can invoke from the command line.

Prerequisite: You have installed Node.js. For more information about installing Node.js, see Install Node.js.


The Admin API includes the ProjectExport resource. This resource returns the JSON representation of an entire API. You can GET the export JSON from one API Server and POST the JSON to another, with a node application that does the following:

  1. Obtain the export JSON from the Dev API Server by calling getApiExport.
  2. Insert this JSON to the Production API Server by calling postApiImport.
The following image shows this process:
The Admin API runs with the Jetty install of the B2B Example.

  • apiDev and apiProduction have the same value, which is not normally the case.
  • The URL contains abl/admin/v2. This designates that the API is using the sdmin data.
  • id fixup (see code comments) ensures that internal admin IDs do not conflict with existing admin data during import.
  • This example is a basic illustration. For real use, consider extending it to:
    • Provide argument input for dev/production servers.
    • Fix the passwords. For more information about fixing imported API projects, see API Project Samples.
  • The code emits the following log:
..getApiExport reading resource ProjectExport, with filter: equal(name:'Northwind-B2B' )
Execution Complete
..getApiExport finds export: Northwind-B2B
....postApiImport - Posting anApiExport into ProjectExport
....postApiImport - SUCCESS

Observe that the Execution Complete message occurs early, reflecting the JavaScript's common aync execution model. JavaScript for logic running in the API Server operates synchronously, providing a simpler programming model.



Run the Example

To run this example:

  1. Install the Node SDK.
    For more information about installing Node SDK, see Use Node SDK.
  2. Create the B2B example in the jetty install.
  3. Create a new folder and a file in it called exportImport.js with the previous code.
  4. Issue the following command from your command line:
    npm install underscore
Run it with (Note: A number of npm install steps might be required):
node exportImport.js