2
votes

I added an API and later on remove it in /carbon management console. Now I wanted to add it back and it failed with "wso2 am 1.10.0: Error occurred while adding the API. A duplicate API already exists for {CONTEXT}".

I even manually went to database and manually removed the API from all related tables, including AM_API. I also manually removed the related file under /repository/deployment/server/synapse-configs/default/api .

So what else I have to do so I can recreate that API without the above error? Is this a bug in this version?

Related discussion: WSO2 API Manager - context management (Is this issue coming back in Version 1.10.0?)

1

1 Answers

-1
votes

First thing to note is, you should not delete the apis via the carbon management console. The xml representation you see there is just the runtime logic which the underneath mediation engine refers when routing messages. An API in WSO2 API Manager has three aspects.

  1. Metadata stored in the registry database
  2. Data such as subscriptions etc. which are stored in APIM database
  3. Runtime API representation which is stored as an xml file

Now, what first happened is, you just deleted the xml. But, all other data which tells the api manager about that api was still exist. Thats why you got the initial error. Its not easy to delete the metadata etc manually. Specially because you (and any other user including me) are not aware of the places where they are stored.

Therefore, the best way to remove an api is to either delete it from the api publisher UI or delete it via the api publisher's api. Even when you try to delete via above two methods, it will complain if there are any active subscriptions. So, you will have to attend to them as well.

I can think of the following to overcome this situation:

  1. Delete this via the publisher's rest api (this is the best option I can see)

  2. If #1 does not work, then you will have to first check for all the entries in APIM database and delete them (I am not able to list the necessary tables etc.). Then, if you are familiar with the registry, you can go to the registry browser and traverse to /_system/governance/apimgt/applicationdata/ collection and delete the resource relevant to your api. This might help you to clean up the system.