Developing a plugin with endpoints

System Information
  • 4.0.1:
  • Windows:
  • SQLlite:
  • v16.13.1:
  • 8.1.2:
  • 1.22.17:

Hi

I follow the instructions on Plugins development - Strapi Developer Docs

I used “yarn strapi generate” and selected plugin and gave it a name. Added the needed export to the plugin.js and I can see it show up in the backend plugins.

But it doesn’t show up in User Permissions, meaning I can’t give it any permissions. But when I try and go to the route made by the generate it gives the following answer:

{

  • data: null,
  • error: {
    • status: 401,
    • name: “UnauthorizedError”,
    • message: “Missing or invalid credentials”,
    • details: { }}
      }

The code for the routes and controllers seems fine, and if I remove the plugin it gives me a 404 not found instead of the 401.

What am I doing wrong? I feel I need to register the plugin somewhere, or add something in the plugins.js besides the enabled and resolve.

I found a solution, but it doesn’t seem very documentede anywhere.

Solution:

module.exports = {
  'content-api': {
  type: 'content-api',
  routes: [
    {
      method: 'GET',
      path: '/',
      handler: 'myController.index',
      config: {
        policies: [],
      },
    },
  ]
}};

Before:

module.exports = [
  {
    method: 'GET',
    path: '/',
    handler: 'myController.index',
    config: {
      policies: [],
    },
  },
];

3 Likes

thank you, shows up in the permissions now