How to perform CRUD operations with users-permissions_user plugin

System Information
  • v4:
  • Windows 11:
  • Postgres:
  • 16:
  • v8:

I actually have 2
How can I perform CRUD operations for user data using the up-plugin plugin inside another controller?
for example gettings a user by ID, deleting a user by ID, editing a user by ID, etc

For example
strapi.plugin("up-user").get({ where: { id: 1 } })

I suppose you could call the plugins’s user controller like so:

await strapi.controller("plugin::users-permissions.user").create(...)
await strapi.controller("plugin::users-permissions.user").update(...)
await strapi.controller("plugin::users-permissions.user").find(...)
await strapi.controller("plugin::users-permissions.user").findOne(...)
await strapi.controller("plugin::users-permissions.user").destroy(...)

Not sure how well this will play with authorization. Another option would be calling the plugin’s user service:

await strapi.service("plugin::users-permissions.user").add(...)
await strapi.service("plugin::users-permissions.user").fetch(...)
await strapi.service("plugin::users-permissions.user").remove(...)

Just beware that calling the service directly will circumvent bunch of validations that are done within the controller. See the controller implementation for details.

1 Like

On it. Thank you