Tyk's management call for deleting an API is throwing 500 internal server error but the API gets deleted from the gateway

Tyk’s management call for deleting an API is throwing 500 internal server error but the API gets deleted from the gateway. After the delete call, when the call is made for fetching the API from the gateway, it gives 404 not found error.
“status”: “error”,
“message”: “API not found”
Below the management call used for delete :
DELETE : https://{tyk-gateway-node}/tyk/apis/{api_id}

Hi @shatakshi_chugh,

Welcome to the community :partying_face:

This sounds like an old known issue :thinking:

Please confirm the gateway version and share the debug logs.

Hi!
Sorry for the late revert on the required details.

Gateway Version: 4.3.4

Debug Logs & Issue: On hitting the TYK Management Call sequentially for a given number of APIs published on the gateway, we can see the following debug logs on the node:

Aug 30 07:35:53 tyk[11561]: time=“Aug 30 07:35:53” level=debug msg=“Deleting API definition for: {api_name}”
Aug 30 07:35:53 tyk[11561]: time=“Aug 30 07:35:53” level=warning msg=“File does not exist! stat /opt/tyk-gateway/apps/{api_name}.json: no such file or directory”

The corresponding files do exist on the node but for some reason, on hitting the TYK Management Call for DELETING the APIs returns 500 Internal server error.
On top of that, if we reload the gateway post completion, the APIs can be seen as rightly removed/deleted from the gateway.

Could you please help us understand what exactly the issue is? Is it something pertaining to passing some extra parameter for obtaining the correct status code?

Hi @Bismeet_Singh,

Thank you for the revert.

I’m able to rerpdocue such when I have mismatch in the api_id defined in the API definition, and the name of the file itself. Essentially, having a file named my-api.json, with content like this

{
  "name": "the-api",
  "api_id": "the-api",
  "org_id": "default",
  .....
  <truncated>
}

…causes such error in my local.

Are you able to verify that the file name is same as the api_id (and name ideally) in the file content?

Hi!
I actually tried this way out in our setup. I modified the API JSONs by keeping the “api_id” and “name” same as the file name.

Still, I’m facing the same issue. Gateway logs still reveal that the file does not exist.

Hmm. can you provide more detail about your setup. Number of gateway nodes… configurations…

Additionally, you say

On hitting the TYK Management Call sequentially for a given number of APIs published on the gateway, we can see the following debug logs on the node:

Can you give more details about this, such that I can try to reproduce.

Sure!
Sorry for the late revert once again!

We have a TYK setup built using Terraform containing 2 HA Proxy Nodes, serving 3 Gateway Nodes which in turn has connectivity with 6 Redis Nodes, serving the source for 1 Pump Node to pull data from.

Regarding the sequential flow: We are actually executing an ansible script that is responsible for adding, deleting & retrieving APIs from the host gateway (its IP is passed at runtime by the user). The script first fetches all the APIs published at the Input Host and stores it in a variable for us to refer to; a loop on the same variable then deletes the APIs one-by-one with the help of Tyk Management Call & finally the script reloads the gateway for the user once the loop execution is complete.