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

  1. Download the api-import-export war file which is compatible with API Manager 2.6.0 from [1]
  2. Go to the API Manager Home path.
  3. Navigate to the webapps directory (<APIM_HOME>/repository/deployment/server/webapps)
  4. Paste the downloaded war file.
  5. 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.

  1. Go to the publisher portal (https://localhost:9443/publisher). You can log in by providing default username(admin) and password(admin)
  2. Click on New API
Create New API — WSO2 API Manager 2.6.0

3. Select Design a New REST API and click on Start Creating.

Create REST API — WSO2 API Manager 2.6.0

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.

Design Tab — WSO2 API Manager 2.6.0

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)

Implementation Tab — WSO2 API Manager 2.6.0

By default, advanced endpoint configurations shown as below.

No need to configure right now, we can do it by using APIMCLI Tool 😁

Advanced Endpoint Configurations — WSO2 API Manager 2.6.0

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.

Manage Tab — WSO2 API Manager 2.6.0
  • For more information about Create and Publish an API, Please go through the documentation[2]

GREAT!!! Now you have published an API. 😇😇😇 Lets move with the API Controller.

Getting started with API Controller

  1. Go to the official documentation link[3] and download the API Controller. for the Linux environment, I have downloaded the Linux 64-bit API Controller version.
  2. Extract the downloaded archive to a desired location.
  3. 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 [4] 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 \
--import-export https://localhost:9443/api-import-export-2.6.0-v17
Add Environment via APIMCLI
  • 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!!!

  1. Log into the environment.
apimcli login <environment_name> -k
Log into test_environment1

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 [5]

apimcli export-api -n <API-name> -v <version> -r <provider> -e <environment> -k
Export API

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 [6].

  • 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
Import API
 --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 [7] for more information.

apimcli import-api -f -e test_environment2 --params custom_params.yaml --update -k
Import API with parameter file

Below content included into the parameter.yaml file.

- name: test_environment2
endpointType: rest
endpointRoutingPolicy: load_balanced
- url:
factor: 1
retryTimeOut: 10000
retryDelay: 20000
retryErroCode: 101507
actionSelect: discard
actionDuration: 75000
suspendErrorCode: 101504
suspendMaxDuration: 25000
suspendDuration: 45000

And the result is,

  1. Endpoint Configurations.
Endpoint Configurations

2. Advanced Endpoint Configurations.

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.

That’s it!!!

Congratulations!!! Now You can export an API, import an API with/without paramters by using APIMCLI. 😇😇😇

Happy coding!!!










Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store