Right the wrong: Get rid of partially deleted APIs in WSO2 APIM

[Source: https://s3.amazonaws.com/lowres.cartoonstock.com/education-teaching-complaint-grammar_mistake-spelling_mistake-grammar-linguistics-tcrn2348_low.jpg]

Make the wrong

A person who never made a mistake never tried anything new!

The famous lines from one of the greatest minds of all time, Sir Alber Einstein. As human beings making mistakes and correcting those mistakes are part of the learning process, especially when you are working with machines. This blog will walk you through such a learning experience from the mistakes made in terms of Application Programming Interface (API).

Partially deleted APIs in WSO2 APIM

This blog covers the scenarios and the corrective measures to be taken against the partially deleted APIs in WSO2 APIM. There could be instances where we might want to remove an API from our system or might have deleted it by mistake. As a result, we may not be able to create the same API again or may not be able to retrieve the API if it was done by mistake.

When an API is created the relevant details will be stored in AM_DB, registry, and in synapse folder. Similarly, when an API is deleted via publisher portal or via REST API calls all the references of that particular API should be removed from the above-mentioned locations. The possible cause for the partially deleted APIs could be due to some human errors, network stability, or connectivity issues while deleting the APIs via publisher or REST APIs.

Solve the struggle!

We have identified the problem and the possible causes for it. Now, it’s time to solve the problem and end the suffering. Please note that the following details are applicable for APIM-2.X.X.

When deleting an API from the APIM the following conditions need to be satisfied.

In API-Manager an API can be deleted in 2 ways. They are as follows.

1. Deleting an API through Publisher Portal

  • Access the Publisher portal via https://<host_name>:<port>/publisher
  • If an API is in the published state then it should be checked for any existing subscriptions. These details can be checked in the API’s thumbnail or by clicking on the API thumbnail these details can be viewed in a more descriptive manner.
  • If the API has any subscriptions then access the Store portal via https://<host_name>:<port>/store and remove the subscriptions.
  • The subscription should be removed by navigating through API-Store → Applications → Select the subscribed Application → Click on Subscribes tab → click on the Unsubscribe option for the selected API
  • Now go to the Publisher Portal and delete the relevant API as shown in the below image.

✅ Recommendation

Please note that deleting an API through the Publisher portal or the REST API calls are the most preferred ways to delete an API as it will delete all the records and metadata of that particular API in all the referred places such as registry, database, and synapse-config. Therefore, I highly recommend you follow this approach to delete the APIs.

2. Deleting an API from the registry through carbon management console and databases

This approach needs to be done at 3 levels (a, b, c). They are as follows.

a. Deleting an API from the registry via the carbon management console

  • Access the carbon management console via https://<host_name>:<port>/carbon
  • On the left side of the Home menu, under the “Resources” tab, click on the “Browse” option.
  • Then navigate to /_system/governance/apimgt/applicationdata/provider/admin/<api_name>
  • You will be directed to the following UI
  • If you have created multiple versions with the same API name you will get multiple folders with the version number as the name.
  • Click on the relevant version folder’s “Action” button.
  • The “Delete” button will be displayed.
  • Click on the Delete button and the relevant API will be deleted from the registry browse.

b. Deleting API information from the relevant database tables

Once the API has been deleted from the registry browse the relevant API details must be deleted from the below-mentioned database tables in order to completely remove the API from the system. Please follow the steps mentioned below.

  • As the initial step get all the details of the deleted API from the database (AM_DB) by executing the following query. This will return you all the relevant details which you will be needing later to completely delete all the API-related details from the database. From this, we will be mainly needing the API_ID in order to execute the upcoming queries.
  • Next, execute the following DELETE queries one by one.
  • Provide the relevant values instead of “?” in the required places.

c. Deleting the API synapse-config

  • Once the queries got executed next delete the relevant API synapse-config which is located in the <APIM_Home>/repository/deployment/server/synapse-configs/default/api folder if exists.

After completing all the above steps, you can re-start the server and you will not be able to see any reference to the deleted API 😄 That’s all, and we are good to go!

Wrap Up!

In this blog, we were able to see the possible causes of partially deleted APIs and how we can get rid of them with very few simple steps. I hope that this will be a useful read for all the folks who have locked up in similar scenarios. I’ll meet you all in another exciting blog post!!!

Stay Safe and Happy Learning!

Inquisitive

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