Validate entity without persisting it

Hi,
I’m implementing an app with Strapi v4 and I’m wondering if it’s possible to call strapi.entityService.create("uid", {data: { <data> }}) so that the passed data are validated according to the content-type’s rules but the entity is not created. (and similarly with the update method.)

Or maybe there is a workaround using some internal Strapi API?

Thanks and all the best!

Jen

Just found out, you can use

strapi.entityValidator.validateEntityCreation(strapi.getModel(<uid>), <the entitty>)

And it throws all the validations errors of there are any. There also exists validateEntityUpdate equivalent, which also takes the current entity. Check out strapi/index.js at main · strapi/strapi · GitHub for details.

1 Like