6

In the admin panel - I have a content-type products, which shows me all the products in the database (MongoDB)

enter image description here

Suppose I would like to edit a product and when I click on the Save button, I would like to hit a custom API/ override the existing endpoint that updates my products collection!

enter image description here

Is it possible to customize or override the admin panel APIs?

Mahesh Kumaran
  • 887
  • 2
  • 12
  • 30

2 Answers2

6

Update(v4): Judging by the comments - this answer is now outdated as things have changed for v4.

The Strapi admin(strapi-admin) and Content manager(strapi-plugin-content-manager) are defined separately.

If you'd like to override/extend the endpoints; do so by defining the functions you want to override like so:

Locate the controller at:

extensions/<plugin-name>/controllers/<controller-to-override-name>.js

Example:

extensions/content-manager/controllers/ContentManager.js

Notice that the "strapi-plugin" part of the name was dropped!

Example of how to override and extend in controller file:

'use strict';
module.exports = {
  
  //this is how you destroy count
  async count(ctx) {
    ctx.body = {
      count: 99
    };
  },
  //this is how you extend
  async aFuncThatDoesntExistInOriginalController(ctx) {
     //add logic
  },
};

If you're extending you must add a mapping from route to controller & method
To see which endpoint is mapped to which method in the controller check out:

node_modules/<plugin-name>/config/routes.json
node_modules/strapi-plugin-content-manager/config/routes.json

Some basic info in docs: controllers, customization1 & customization2 and FAQ

Eggcellentos
  • 1,570
  • 1
  • 18
  • 25
  • hi, looks like your talking about the API endpoints that are generated when creating a new content type. I m interested in overriding the admin page endpoints. The endpoints that are hit when you update a content-type via the admin page : Sample log: [2020-06-17T08:00:33.185Z] debug PUT /content-manager/explorer/application::products.products/5e8cc069ca721f208dcd35b2 (68 ms) 200 – Mahesh Kumaran Jun 17 '20 at 07:58
  • 2
    I have been trying to extend content manager plugin for hours and couldn't work out why no changes were being applied. It was to do with me prefixing the folder `strapi-plugin` - as the documentation says to! Thank you – Kiee Jun 10 '21 at 20:08
  • What about strapi 4? – Sebastián Rojas Feb 19 '22 at 23:05
  • Any idea for solving issue in strapi 4? – Pandhu Wibowo Apr 13 '22 at 06:59
  • I'm no longer using it so I can't test. I suggest one of you add an updated answer :) – Eggcellentos Apr 13 '22 at 12:59
0

Just to add on ghosh's answer. You have to copy also the dependencies on which ContentManager.js relies on to avoid any errors as follows:

extensions/content-manager/  
└─── controllers
|   │   -   ContentManager.js
|   └─── validation/
|       -   index.js
|       -   model-configuration.js
|    
└─── services/
|    └─── utils/
|       └─── configuration/
|           -   attributes.js
│   
└─── utils/
    -   parse-multipart.js
saad-mb
  • 201
  • 2
  • 6