- This feature is only available with the WSO2 WUM updates from July 8, 2019 onwards. For more information on updating WSO2 API Manager, see Updating WSO2 API Manager.
The WSO2 API Manager Command Line Interface(CLI) tool can be used to create APIs without using the API Publisher portal. You can use this feature to create an API specification when you already have a Swagger or Open API specification of your API.
Before you begin...
Running the CLI tool
Step 1 - Deploy the API import/export tool
Download the latest version of WSO2 API Manager from http://wso2.com/products/api-manager/.
- Start WSO2 API Manager.
Download the latest WSO2 API import/export tool (
api-import-export-2.6.0-v17.war) from here.
Note that the import/export tool attached is specific to this version of WSO2 API Manager.
Make sure to delete all previous versions of the web app (e.g.,
api-import-export-2.6.0-v17.war), both the compressed and the extracted files, before copying over the new web app.
- This version of the API Import and Export web application is compatible with the WSO2 WUM updates from July 8, 2019, onwards. For more information on updating WSO2 API Manager, see Updating WSO2 API Manager.
- The previous version of the web application which is compatible with WUM updates that are prior to the above-mentioned date can be download from here.
- Note that API update support in the targeted environment is available only with the
Copy the downloaded
api-import-export-2.6.0-v17.warfile to the
The file is automatically deployed as hot deployment is enabled.
Step 2 - Optionally, set the proxy environment variables for CLI
You can set proxy related
https_proxy standard environment variables, with or without basic authentication as shown below to send the requests initiated from CLI via a proxy server. After one of the following environment variables is set in your environment where CLI is used, all the requests will go through the proxy server specified.
In conjunction with the above proxy configurations, calls from the CLI to particular hosts that need to bypass proxies can be configured via either the
no_proxy environment variables.
Step 3 - Run the CLI tool
Download API Controller based on your preferred platform (i.e., Mac, Windows, Linux).
- Extract the downloaded archive containing the CLI Tool to a preferred location and navigate to it from the terminal (using
- Navigate to the working directory where the executable CLI Tool resides.
Execute the following command to start the CLI tool.
Add the location of the extracted folder to your system's
$PATHvariable to be able to access the executable from anywhere.
For further instructions execute the following command.
Global flags for CLI tool
The following are some global flags that you can use with the CLI tool.
Adding an environment
You can add environments by either manually editing the
$HOME/.wso2apimcli/main_config.yaml file or by running the following CLI command.
The directory structure for the configuration files (
$HOME/.wso2apimcli ) will be created upon execution of the
- Make sure that WSO2 API Manager is started and that the CLI import/export tool is running.
Run the following CLI command to add an environment.
- Required flags:
There are no short flags for the following flags.
- Required flags:
Logging into API Manager via the CLI tool
Before exporting an API, you need to log in to API Manager to be able to gain the required privileges for the action. Make sure that you have credentials with the proper scopes before logging in via the CLI tool.
The sample command to log in is given below.
To log out from the specific environment, use the command given below.
Create a new API project
- Open a terminal window and navigate to the path you need to create the project.
Execute the command given below to initialize a new API project.
A project folder with the following structure will be created in the given directory.
The specification of the created API.
The swagger file generated when the API is created.
Contains environment-specific details.
Adding environment-specific parameters for APIs using api_params.yaml
Refer Adding environment-specific parameters for APIs for more information on configuring api_params.yaml file.
To set a CI/CD pipeline you need to edit the configurations in this file. For instructions on how to use it, see Migrating the APIs to a Different Environment.
To add custom sequences, save them in xml format and add them to the corresponding folder. E.g., To add a custom in-sequence, save the custom sequence as
SampleSequence.xmland add it to the
api.yamlfile. You can edit the mandatory configurations listed below.
The name of API without spaces.
Context of the API in API Manager with a leading slash.
Production endpoint for API.
Sandbox endpoint for API.
For more information about the configurations, go to the gist.
After editing the mandatory fields, you can import the API using the following command.
For more information, see Migrating the APIs to a Different Environment.
To publish the API immediately after importing, set the
statusfield to "
Generate API projects using a Swagger/Open API specification
You can user Swagger2 and OpenAPI3 specifications to generate an API. File format should be yaml or json. A sample command is given below.
To import the created API to your preferred environment, use the command given below.
You can also initialize an API project from a remote Swagger/Open API specification. The sample command is given below.
Change the default API template
APIs are generated using a default template specified in the
HOME/.wso2apimcli/default_api.yaml file. You can edit this file to change how the API projects are initialized. This file contains the same notation as the
api.yaml file. If user prefers to generate APIs with predefined set of values for tags, descriptions, throttling tiers, etc., it can be defined through the default_api.yaml.
Generate APIs with dynamic data
You can initialize APi projects with dynamic data using an additional definition file. The definition file will have the field names (e.g., apiName, version) as variables. A sample is shown below. Part of a definition file listed below. In here apiName and version are denoted as environment variables(on usual notation). Upon execution, the CLI tool will automatically inject values from the environment to the definition
Execute the following command to create the project.
When executing the command, the CLI tool automatically injects the values to the API definition.
To make this work you will need to set up required environment variables according to your OS. In a Linux/Unix environment, it can be done using
API File reference
Quick demonstration video can be found as follow.