Post NULL to required field

Hello,

I’m trying to create a new record with the Content Management API but I want to know if it is possible to post null to a required field.

I want to pre-fill some fields from the API call, and let the user finish the draft (upload a logo and pick a color).

I have created the following model where all fields are required. I want to fill the webshop_url, name, email and phone from the API and let the user fill in the colors and upload the logo.

But when i try to post the following attributes with my API call

"attributes": {
			"phone": "0612345678",
			"email": "test@test.nl",
			"primary_color": null,
			"secondary_color": null,
			"logo": null,
			"name": "Test shop",
			"webshop_url": "https://test-shop.com"
		},

I will get a 422 Unprocessable Entity with the following validation errors.

 {
      "id": "d8f388",
      "type": "api_error",
      "attributes": {
        "code": "INVALID_FIELD",
        "details": {
          "field": "primary_color",
          "field_label": "Primary color",
          "field_type": "color",
          "code": "VALIDATION_REQUIRED",
          "options": {}
        }
      }
    },
    {
      "id": "b27332",
      "type": "api_error",
      "attributes": {
        "code": "INVALID_FIELD",
        "details": {
          "field": "logo",
          "field_label": "Logo",
          "field_type": "file",
          "code": "VALIDATION_REQUIRED",
          "options": {}
        }
      }
    }

So my question is: Is it possible to post null to required fields and make a draft.

Hello @algemeen and welcome! :slight_smile:

What you want to do is impossible unfortunately. The idea behind the required field is that a field is ALWAYS required. This prevents from unexpected data to be served from our API and so simplify the client logic.

You can remove the validation, add the records without the content and then add the validation. In this instance the API will return the records with the empty field, but will mark the records as invalid. So your client can prevent these records from rendering.

Hope this helps!