strapiheadless-cms

How to override Strapi Admin panel endpoints?


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?


Solution

  • 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