WSO2 API Manager-Republish all your API’s at once with this tool

Nicolas Yamin
4 min readMar 12, 2021

Hi everyone! In this opportunity, I want to share with you an extremely useful tool that will allow you the republish all your deployed API’s with a single command.

Companies and users having hundreds or more API’s in their environments and can’t afford republishing them manually should find it handy.

Republishing is done whenever you need to apply a change that will be picked up from configuration files exclusive to API’s. One very common case is when you wrote a custom handler (such as a new login method, logger, and so on)and want to engage it for all API’s. Manually republishing these API’s one by one is a very time consuming process indeed, and if you have 100+ API’s, you might want to think of a better alternative.

Luckily, leveraging the flexibility of WSO2 API manager REST client (you can find the docs here), we can extend its functionalities and modify the lifecycle states of our API’s via a REST call.

In the repo below you will find a little script to do just that:

You can check the README file to find out just how it works, or even take a look at the code, since the REST calls inside the source code and the config parameters can be easily modified to work on any API-Manager version from 2.1.0 onwards. In order to do this, make sure to check the REST client documentation corresponding to you version of API-M, since there might be slight changes in the way the URLs are composed and config parameters named.

Basically, what we are doing to make this tool work is having a little config file to set our required parameters to customize our REST call according to our API-M environment, such as hostname, port, username, password and so on.

Then, in our JS code, we set calls to:

  • Authenticate users
  • Ask for a token that will allow us to operate via REST calls
  • Look for our published APIs and list them
  • Send a command to redeploy all listed APIs.

Finally, we write a couple of log files to record every operation or error, should they arise.

But enough technical stuff, you can always take a look at the details in the repo. Let me walk you through a practical example using API Manager 3.2.0.

A practical example

Let’s suppose we have our localhost instance with four APIs, and we need to redeploy them all to engage a custom handler we wrote.

Notice the “PUBLISHED” state on the four APIs

Follow these steps to redeploy the APIs:

  1. Install NodeJS in your environment before proceeding with the script execution. It is recommended to use NodeJS v11.14.0 for a flawless dependency installation and execution.

2. Download and extract the tool.

3. Open a command line (Git Bash recommended)Execute the following command from the root of the script directory to install the Node dependencies.

npm install

4. Then navigate to [ROOT_DIRECTORY_TOOL]/repository/conf/deployment.toml file. Here you will find all the needed parameters you need to change to adapt the call to your environment. Since we are working in a localhost environment, we have our default setting. But for reference, in most cases, you would need to change these properties:

  • hostname: Hostname of the Publisher node (default is localhost)
  • port: Port of the Publisher Node (default is 9443)
  • kmhostname: Hostname of the Key Manager node (default is localhost)
  • kmport: Port of the Key Manager node (default is 9443)
  • tokenPort: Port of the /token Endpoint (default is 8243)
  • username: Admin username (default is admin)
  • password: Admin password (default is admin)
The file you need to change, with the basic parameters highlighted.

5. Go back to the ROOT directory and execute the script using the below command.

node server.js

This will execute the code which will pick up the parameters defined in the deployment file and make the necessary REST calls. In the console, we can check the execution progress, as well as the results:

Check that your APIs are being correctly listed.

And that’s it! As long as we are running the right version of API-M, and we get our config parameters right, our APIs should have been republished and each modification requiring such a process in now applied (like custom handlers).

And with that, we made it to the end. I will try to post the same tool for previous API Manager versions as they become available, so you can use them if you have a different version and don’t want to go through the code to alter the REST calls.

Finally, a shout out to Athiththan Kathirgamasegaran, who provided the base code for this tool, as well as the original repo and docs. He writes awesome Medium articles which you can check out here. Also, his GitHub is here.

Thanks for making it this far and see you around in the next article!

--

--