Create custom endpoint for Users

Keep in mind, that first part of the handler is the Filename. You mentioned that you created a Users.js file with controller suggestedusers, but from routes you are accessing the userpermissions.js file, so it doesn’t contain your custom controller suggestedusers.

Look at the screenshot bellow:


To achieve your needs:
  1. Create the controller file /extensions/users-permissions/controllers/custom.js:
module.exports = {
  suggestedUsers: async (ctx, next) => {
    console.log('/suggested-users accessed.');
    await next();
  }
};
  1. Create the route file extensions/users-permissions/config/routes.json:
{
  "routes": [
    {
      "method": "GET",
      "path": "/suggested-users",
      "handler": "custom.suggestedUsers",
      "config": {
        "policies": []
      }
    }
  ]
}

  1. Make the route public or accessible only for authenticated.
  2. Profit:
    image
2 Likes