Required option working in UI but not in POST requests

System Information
  • Strapi Version : 3.6.5:
  • Windows localhost:
  • Sqlite:
  • Node Version : 14.17.4:
  • NPM Version : 6.14.14:

Hello world :slight_smile:

I have an issue with Strapi :
I have a collection ith two fields “email” (simple text field) and city (single relation with another collection named “city” linked on a city ID).
This collection has draft option turned to OFF and email is a required field.
When I try to add a record with empty email with UI interface, i have an error saying that email can’t be empty (okay, that’s what i want). But when i insert a record with a POST request and empty email, the record doesn’t give an error and is inserted (wrong behviour)…

Here is the good behevior in UI (OK) :

Here is a record sent by POST request with empty email (NOT OK) :
(sorry i’m a new user i can’t upload more than on picture but you can imagine that a have a record with empty email now in my UI)

Here is the “participation” model (api/participation/models/participation.js) :

'use strict';
const Boom = require('boom');

module.exports = {
    lifecycles: {
        async beforeCreate(data) {

            //TODO : check why record creation OK when email is empty ???

            //trick for gmail only
            //https://support.google.com/mail/answer/7436150
            let splitedEmail = data.email.split('@');
            if(splitedEmail[1] == 'gmail.com'){
                splitedEmail[0] = splitedEmail[0].split('.').join("");
                data.email = splitedEmail.join("@");
            }

            const participatingCity = await strapi.services.city.findOne({ id: data.city, participating: true });
            if(!participatingCity){
                throw Boom.badData('Selected city does not exist or is not participating.');
            }

            const existingParticipation = await strapi.services.participation.findOne({ email: data.email, city: data.city });
            if(existingParticipation){
                throw Boom.badData("You have already found this city.");
            };
        },
    }
};

I searched a long time, found this topic :

But the issue on this one was that draft option was activated, witch is not my problem…

Can somoeone help me pls ? :slight_smile:

Thanks a lot for reading, and sorry for my english it’s a little bit rusty…

Max

Hi there !

Still have the issue, does someone have a clue about that ?

NB : fields type “text” required are okay, i think it comes from “email” type field, required still not working for this one… :confused:

Yeah it’s something we are aware of, we need to add better validation to the API layer: Validations - Roadmap | Product Roadmap

I think we are somewhat covering this in our v4 but I’ll need to check once we get the public beta out.