API Creation by Command Line

You can interact with your API project using any REST-compatible tool and language, such as cURL or your web browser. While cURL access is powerful, it is tedious to remember and supply the HTTP Header information (such as the auth token) and the IDs of various objects. Instead, you can interact with you API project using the Admin command line interface (CLI), liveapicreator-admin-cli.

The Admin CLI is appropriate for scripted API creation, such as life cycle management services to promote a dev project to production. Your scripts can deal with other elements of your DevOps environment.

For more information:

  • About the Admin CLI, including how to install the Admin CLI, how to access the Admin CLI help, and viewing a sample export and import script, see the npm site.
  • About practical examples of scripted API project creation, including an example of how you can script the life cycle operations, see the Business to Business Example.

Script the Import Process with the Admin CLI

You can deploy a system from source control artifacts by scripting the import process using the Admin CLI. The following script creates the Business to Business example:

(Windows version):
REM  import Script for Northwind-B2B Jetty
echo on
REM  Logon to local  Jetty server (if using a WAR file use http://localhost:8080/APIServer) 
call liveapicreatoradmin logout -a local
call liveapicreatoradmin login -u admin -p Password1 http://localhost:8080/ -a local
call liveapicreatoradmin use local
call liveapicreatoradmin status

REM  Import the Northwind B2B Project, and 'use' it in subsequent commands 
call liveapicreatoradmin project import --file Northwind-B2B.json
call liveapicreatoradmin project use --url_name nwindb2b
call iveapicreatoradmin project update --authprovider 1000

REM  Create the AuthProvider library. 
call liveapicreatoradmin libraries create --name RESTAuthSecurityProviderCreate project --short_name restauth --libtype javascript --ver 1.0 --linkProject  --file RESTAuthSecurityProvider.js  --comments RESTAuthProvider js Demo 

REM  Create a new library (postResourceTo.js), and link it to the current project 
call liveapicreatoradmin libraries create --name postResourceToJS --short_name postjs --linkProject --libtype javascript --ver 1.0 --file postResourceTo.js  --comments postResourceTo 
call liveapicreatoradmin libraries list

REM  Data Sources [optional] for other databases - set the password
call liveapicreatoradmin datasource list
REM call liveapicreatoradmin datasource update --prefix nw --password password1 -- Jetty does not use pw

REM  Auth Providers - link Auth Provider to the current project, using the library loaded above
call liveapicreatoradmin authprovider list
call liveapicreatoradmin authprovider create --name RESTAuthSecurityProviderCreateJS --createFunction RESTAuthSecurityProviderCreate --paramMap logonApiKey=Bzn8jVyfOTiIpW6UQCgy,loginBaseURL=http://localhost:8080/rest/default/nwindb2b/v1/nw%3AEmployees,loginGroupURL=http://localhost:8080/rest/default/nwindb2b/v1/nw%3ARegion --comments 'Uses NW Employees for REST Validation'
call liveapicreatoradmin authprovider linkProject --name RESTAuthSecurityProviderCreateJS

REM  Import the Pavlov API project
call liveapicreatoradmin project import --file PavlovAPI.json
call liveapicreatoradmin project list
call liveapicreatoradmin project update -authprovider 1000

REM  close connections
call liveapicreatoradmin logout -a local
(Mac version):
#! /bin/bash
# import Script for Northwind-B2B Jetty

## Logon to local  Jetty server (if using a WAR file use http://localhost:8080/APIServer) 
liveapicreatoradmin logout -a local
liveapicreatoradmin login -u admin -p Password1 http://localhost:8080/ -a local
liveapicreatoradmin use local
liveapicreatoradmin status

# Import the Northwind B2B Project, and 'use' it in subsequent commands 
liveapicreatoradmin project import --file Northwind-B2B.json
liveapicreatoradmin project use --url_name nwindb2b

# Create the AuthProvider library. 
liveapicreatoradmin libraries create --name RESTAuthSecurityProviderCreate project --short_name restauth --libtype javascript --ver 1.0 --linkProject  --file RESTAuthSecurityProvider.js  --comments RESTAuthProvider js Demo 

# Create a new library (postResourceTo.js), and link it to the current project 
liveapicreatoradmin libraries create --name postResourceToJS --short_name postjs --linkProject --libtype javascript --ver 1.0 --file postResourceTo.js  --comments postResourceTo 
liveapicreatoradmin libraries list

# Data Sources [optional] for other databases - set the password
liveapicreatoradmin datasource list
#liveapicreatoradmin datasource update --prefix nw --password password1 -- Jetty does not use pw

# Auth Providers - link Auth Provider to the current project, using the library loaded above
liveapicreatoradmin authprovider list
liveapicreatoradmin authprovider create --name RESTAuthSecurityProviderCreateJS --createFunction RESTAuthSecurityProviderCreate --paramMap logonApiKey=Bzn8jVyfOTiIpW6UQCgy,loginBaseURL=http://localhost:8080/rest/default/nwindb2b/v1/nw%3AEmployees,loginGroupURL=http://localhost:8080/rest/default/nwindb2b/v1/nw%3ARegion --comments 'Uses NW Employees for REST Validation'
liveapicreatoradmin authprovider linkProject --name RESTAuthSecurityProviderCreateJS

# Import the Pavlov API project
liveapicreatoradmin project import --file PavlovAPI.json
liveapicreatoradmin project list

# close connections
liveapicreatoradmin logout -a local

For more information about the Business to Business example, see Business to Business Example.