No CreatedBy when created by API

I am using Strapi V4, and I have created a middleware that allows returning the ‘createdBy’ field:

javascript
Copier le code


module.exports = (config, { strapi }) => {
  return async (ctx, next) => {
    if (!ctx.query.populate) {
      ctx.query.populate = ["createdBy"];
    }

    await next();
  };
};```
It works well; however, when I create an element via a POST request, the 'createdBy' value is set to 'null'.

<i>This topic has been created from a Discord post (1281629561515282463) to give it more visibility.
It will be on Read-Only mode here.
<a href="https://discord.com/channels/811989166782021633/1281629561515282463/1281629561515282463">Join the conversation on Discord</a></i>

You have to set the populateCreatorFields option to true in the schema of your content type

createdBy is a relationship to admin users only, it will not be set for users-permissions users.