WSO2 Tutorial 4 min

Working with the command line WSO2 API Manager tool

Rob Blaauboer
Rob Blaauboer
Integration Consultant & WSO2 Trainer
wso2apimcli working with the command line in api manager

Working with the command line WSO2 API Manager toolThe latest version of WSO2’s API manager, version 2.5.0, has an additional tool to download that will make it easier for you to copy an API or an application from one environment to the other. People who are knowledgeable about the API manager can say: hang on, don’t we have that already? And they’re partly right. There is a tool that will allow you to import or export an API that has been created on the API manager. It is called API – import – export and is actually a war file that is deployed on the API manager itself in the webapps directory. My colleague Daniel Stevanović wrote a blog about it way back in 2015. 

The command line tool is more than that. To be precise it actually uses the latest version, tied to the version of the WSO2 API manager, of that very same war file. The addition is that you now have a more elaborate solution where you can define environments that you would like to copy to. In this blog, we are going to look at how we can define two environments, let’s call them development and test and using the command line tool from one environment to the other.

Setting up the environment

So, let’s define the environment that we’re going to use. It consists of two API managers on the same server which means that you need a port offset for instance of one the second API manager to let them coexist on the same server.

We are not going to make any other changes the out-of-the-box API managers and the Port offset that we just described. On the first API manager, the one with the zero-port offset, we are going to deploy the standard API: the Pizzashack. Reason for this is that it’s packaged with the application requires no other installation, just click the button for the deployment of the sample API.

Make sure that you actually deploy the WSO2 API Manager 2.5.0 Import / Export WAR file. You can  download it from this location.

We are not going to do a very detailed explanation of how you download and install the API manager. If you’re looking for information about that please see our blog on installing WSO2 products.

I’ve taken the API manager using WUM an updated it to the latest version available. It made to directories:


and make sure that the second API manager has a port offset of one.

I’ve downloaded the apimcli tool in the same directory where I created the two API subdirectories. I’ve executed the tool once to create the yaml configuration files.

Lets add the two environments using the command-line. This is for a localhost deployment on Linux:

./apimcli add-env -n APIM-TEST --registration https://localhost:9444/client-registration/v0.13/register --apim https://localhost:9444 --token https://localhost:8244/token --import-export https://localhost:9444/api-import-export-2.5.0-v1 --admin https://localhost:9444/api/am/admin/v0.13     --api_list https://localhost:9444/api/am/publisher/v0.13/apis --app_list https://localhost:9444/api/am/store/v0.13/applications./apimcli add-env -n APIM-DEV --registration https://localhost:9443/client-registration/v0.13/register --apim https://localhost:9443 --token https://localhost:8243/token --import-export https://localhost:9443/api-import-export-2.5.0-v1 --admin https://localhost:9443/api/am/admin/v0.13     --api_list https://localhost:9443/api/am/publisher/v0.13/apis --app_list https://localhost:9443/api/am/store/v0.13/applications

For Windows the  ./ is not necessary.

The file looks like this

wso2apimcli - working with the command line in api manager

Start both instances using the shell of bat file and login to the APIM-DEV. Deploy the sample PizzaShack API.

API Publisher-working with the command line api manager tool

API Publisher listing-working with the command line in api manager tool

WSO2 API publisher - all API's

Let’s list the environments. As you can see the two environments are present.

environments - working with the command line API manager tool

We will now export the API using the apimcli tool:

apimcli export-api -n PizzaShackAPI -v 1.0.0 -r admin -e APIM-DEV -u admin -p admin

We however encounter an issue with regards to the self-signed certificate. A response is given that the certificate is signed by unknown authority. We now make the tool using the -k or –insecure setting. The –verbose setting gives more information about the actions of the tool.

apimcli export-api --verbose –-insecure -n PizzaShackAPI -v 1.0.0 -r admin -e APIM-DEV -u admin -p admin

Successfully exported API!

If you have a CA that is not trusted yet, use the following two commands to add the CA to your OS. This is the command for Centos7:

sudo cp cacert.pem /etc/pki/ca-trust/source/anchors/ 
sudo update-ca-trust

Find the exported API at:

.wso2apimcliexportedapisAPIM-DEVPizzaShackAPI_1.0.0.zip in windows.

Linux has a different directory where is stored and created the exported APIs.


Let’s verify the export. There are two directories under exported:

  1. apis
  2. apps

And indeed, we find a zip file with the exported PizzaShackAPI.

zip PizzaShackAPI

Import the API

We are going to import the API into APIM-TEST.

For Windows this is the command from the directory where

apimcli import-api --verbose –-insecure -f APIM-DEVPizzaShackAPI_1.0.0.zip -e APIM-TEST -u admin -p admin

Linux uses this command, note that this includes the addition of the CA cert.

./apimcli import-api --verbose -f /opt/wso2/.wso2apimcli/exported/apis/APIM-DEV/PizzaShackAPI_1.0.0.zip -e APIM-TEST -u admin -p admin

Questions regarding this blog? Don’t hesitate to let us know.

Advanced API Management Guide

advanced api 2
Get it now
We appreciate it
Care to share

Please select one of the social media platforms below to share this pages content with the world