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.
APIMCLI Check

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.

We can add a specific environment by executing below command. Please go through the documentation [4] to manage environments via apimcli.

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

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.
Import API

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.

Import API with parameter file

Below content included into the parameter.yaml file.

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.
  • 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!!!

[1] https://docs.wso2.com/download/attachments/28718536/api-import-export-2.6.0-v17.war?version=1&modificationDate=1600688632000&api=v2

[2] https://docs.wso2.com/display/AM260/Create+and+Publish+an+API

[3] https://docs.wso2.com/display/AM260/Initializing+projects+using+the+CLI+Tool#InitializingprojectsusingtheCLITool-Step3-RuntheCLItool

[4] https://docs.wso2.com/display/AM260/Initializing+projects+using+the+CLI+Tool#InitializingprojectsusingtheCLITool-Addinganenvironment

[5] https://docs.wso2.com/display/AM260/Migrating+the+APIs+and+Applications+to+a+Different+Environment#MigratingtheAPIsandApplicationstoaDifferentEnvironment-ExportinganAPI

[6] https://docs.wso2.com/display/AM260/Migrating+the+APIs+and+Applications+to+a+Different+Environment#MigratingtheAPIsandApplicationstoaDifferentEnvironment-ImportinganAPI

[7] https://docs.wso2.com/display/AM260/Building+CICD+Pipeline#BuildingCICDPipeline-SettingUpAdvancedEndpointConfigurations

Software Engineer @ WSO2 | WSO2 Certified API Manager Expert | BIT(UCSC) | DiHN | OCPJP | Student Member of CSSL