Remove plugin from multiple services

Hi All,

Consider a custom plugin say “cus-plugin” is configured for 5 different Kong services , is there a way to remove this plugin (from all 5 services) from Kong configuration using a single API ?

As I read the Kong docs , to remove plugin config , I need to execute DELETE end point
/plugins/{plugin id}

But in case the plugin is configured for 5 services , then I have to individually execute it 5 times for each plugin-id.

You are correct if you enable a plugin on 5 different services that if you wish to remove the plugin you must delete it off each of the 5 services individually. Sure it does make extra work but imagine if you accidentally deleted a plugin off ALL services by mistake? Could cause your entire gateway to go into disarray :slight_smile: . Maybe eventually they make a way to pass multiple service ids + plugin name or something for delete but I don’t think it follows the basic CRUD functionality they have intended on Kong resources for now (which you can write your own wrapper API’s on top of theirs to accomplish what you want if you so desire).

1 Like

Thanks @jeremyjpj0916
Seems like this may be cumbersome for us.
Is there any available documentation on writing wrapper APIs which I can follow , in case I need to write on our own ?

Documentation of the Admin API is available online at (and is versioned per major Kong version). You are free to write any wrapper you may want on top of the basic CRUD functionalities it offers.

1 Like

Thanks @thibaultcha

But I could not find much details on admin API customization or how can we extend (or add wrappers to) the existing Admin APIs ?

The idea of a wrapper is this for example:

Say there is an API Called deleteConsumer() and an API called getConsumers(), you want to make an API that deletes all consumers(which is not available). Then in sudo code you do this with your wrapper API logic:

consumers = kong.getConsumers();
for(i = 0; i < consumers.size(); i++)

Many thanks @jeremyjpj0916
This is helpful , but I was also looking as to where I need fit in this code in the Kong framework .
Recently I developed a custom Kong plugin , so is this API customization also deployed as a plugin or something else ?

Ah right, to do it like so an as API exposed off of your custom plugin for kong is slightly more challenging but totally doable, lets take this source code for example(yours will be similar):

So for instance your plugin you will put an api.lua script in your source plugin and create methods similarly to the plugin I linked you above, I suppose to wrap other API calls and logic you can include references to other plugins “api.lua” codebases like the one above and call their methods directly with the API you expose off your plugin. That way your plugins api.lua calls other existing methods within the kong codebase. A little more work than just writing an external client to call admin CRUD api endpoints but still doable if you study the Kong code and find the lua scripts/methods you need within kong. For instance create/delete consumers is not exposed in any plugins “api.lua” file but I am sure there is a different method in the core you can reference from your plugins api.lua.

1 Like

Many thanks @jeremyjpj0916 , this is what I was looking for , so let me try it out.

And appreciate your quick response on this !!

1 Like