Import/Export APIs in WSO2 API Manager 2.6.0 with Configurations
Hello Geeks!!! 😇😇😇
Today, I’ll explain how to use the WSO2 API Manager Command Line Interface (APIMCLI) with WSO2 API Manager 2.6.0 in Linux Operating System.
WSO2 API Manager is the world’s leading open-source, enterprise-grade API management platform for on-premises, cloud, and hybrid architectures.
WSO2 API Manager Command Line Interface allows you to manage multiple environments which are running in a same WSO2 API Manager instance. This allows you to manage APIs between your environments by import and export APIs.
Sounds pretty cool??? Ok, Let’s start. 😇😇😇
Getting started with API Manager
- Download the api-import-export war file which is compatible with API Manager 2.6.0 from 
- Go to the API Manager Home path.
- Navigate to the webapps directory (<APIM_HOME>/repository/deployment/server/webapps)
- Paste the downloaded war file.
- Start the API Manager 2.6.0 by executing below command.
By default, management console, dev portal, publisher UI and admin portal will access via 9443 port and you can invoke published APIs via 8243 port. If you apply a portOffset for the API Manager, this would be change according to the offset value.
Now you have a running instance of WSO2 API Manager 2.6.0 with the capability of import and export APIs by using CLI tool. Let’s create an API.
- Go to the publisher portal (https://localhost:9443/publisher). You can log in by providing default username(admin) and password(admin)
- Click on New API
3. Select Design a New REST API and click on Start Creating.
3. You will navigate to the Design tab.
- Inside the General Details section, you can provide a name for the API, context, version, Description etc…
- Inside the API Definition section, You can define API Resources.
I applied below values and create an API resource as below.
In next page(Implement Tab), You can manage endpoint configurations, message mediation policies and CORS configurations.
I selected HTTP/REST Endpoint type and defined a production endpoint as below. (You can add advanced endpoint configurations to the endpoint by click on the settings icon near to the endpoint Test button)
By default, advanced endpoint configurations shown as below.
No need to configure right now, we can do it by using APIMCLI Tool 😁
In Manage Tab, You can add API configurations, Throttling Settings,API gateways etc… For now, we just put a tick to a Subscription Tiers and click on Save & Publish.
- For more information about Create and Publish an API, Please go through the documentation
GREAT!!! Now you have published an API. 😇😇😇 Lets move with the API Controller.
Getting started with API Controller
- Go to the official documentation link and download the API Controller. for the Linux environment, I have downloaded the Linux 64-bit API Controller version.
- Extract the downloaded archive to a desired location.
- Navigate to the extracted location and start the CLI tool.
Now, we can manage APIs in different environments via apimcli. First of all, we can list all the environments that available by executing below command.
apimcli list envs
We can add a specific environment by executing below command. Please go through the documentation  to manage environments via apimcli.
apimcli add-env -n test_environment1 \
--registration https://localhost:9443/client-registration/v0.14/register \
--apim https://localhost:9443 \
--token https://localhost:8243/token \
- I have added 2 environments named test_environment1 and test_environment2
Export the API
Now we came to the exciting part of this article. As described above, we can manage APIs in different environments by using API Controller. We have already created an API via publisher portal. Lets start!!!
- Log into the environment.
apimcli login <environment_name> -k
Now we have logged into the test_environment1 by providing default credentials.
2. Export the API.
You can export the API by executing below command. Please go through the documentation 
apimcli export-api -n <API-name> -v <version> -r <provider> -e <environment> -k
As you can see, I have exported the API from test_environment1 and that has been exported as a zip file. Inside the zip file, you can see the API information in api.json and api definition in swagger.json file.
3. Import the API.
You can import the exported API by executing below command. Please refer to the documentation .
- We have exported the API from test_environment1. We can import that API into test_environment2.
apimcli import-api -f <file> -e <environment> --update -k
--update - this flag is used if the API is available,this will update with new artifact. If not, then create a new API and import configurations automatically.
Now go to the publisher portal and then you can see, the exported API has been in the publisher portal successfully with defined configurations.
Now we can move with some advanced import statements. 😁
3. Import the API with parameter file.
We can import the exported API artifact and override configurations of the API. Please refer to the documentation  for more information.
apimcli import-api -f Test_API_1.0.0.zip -e test_environment2 --params custom_params.yaml --update -k
Below content included into the parameter.yaml file.
- name: test_environment2
- url: http://newendpoint.com
And the result is,
- Endpoint Configurations.
2. Advanced Endpoint Configurations.
Parsing Advanced Endpoint Configurations.
- apimcli 2.0.11 is supported advanced endpoint configurations as mentioned below.
retryErroCode - this should be a valid error code
actionSelect - this value can be either discard or fault
suspendErrorCode - this should be a valid error code
- apictl (Latest API Tool) is supported only for below mentioned advanced endpoint configurations.
- All the error codes mentioned in the below image.
Congratulations!!! Now You can export an API, import an API with/without paramters by using APIMCLI. 😇😇😇