Define required variables in BPMN

Hello, guys!
Hope you are well.

Is there any way to declare required variables in BPMN file?
For example, I have a process definition and to start it I have to pass ‘user_id’ variable. If I try to start it without this variable - the process engine should throw an exception and process instance is not created.

Refer the Form Field Validation documentation.

@Vladimir In the start event of the process you can have form field as user_id and add constraint as “required” like below:

otherwise you can configure custom form validator:

@Component
public class CustomValidator implements FormFieldValidator {

  public boolean validate(Object submittedValue, FormFieldValidatorContext validatorContext) {
    // get access to the current execution
    DelegateExecution e = validatorContext.getExecution();

    // get access to all form fields submitted in the form submit
    Map<String,Object> formVariables = validatorContext.getSubmittedValues();
    if(!StringUtils.hasText(formVariables.get("user_id"))){
       throw new InvalidRequestException("User_id is null or empty");
    }
  }

}

Bpmn configuration:

<camunda:formField
    id="firstname" label="First Name" type="string">
    <camunda:validation>
       <camunda:constraint name="validator" config="${customValidator}" />
    </camunda:validation>
</camunda:formField>

Not OP, but this doesn’t seem to work on forms on start events.
In the attached diagram I make a simple form with the validate_me field required.
However I was able to start this flow with an empty body in postman.

It can be seen that there are no process variables, even though validate_me is marked as required.

I could very easily be missing something. Any suggestions would be very much appreciated.

XML for startEvent:

    <bpmn:startEvent id="StartEvent_1" name="Start of flow">
      <bpmn:extensionElements>
        <camunda:formData>
          <camunda:formField id="validate_me" label="Validate Me" type="string">
            <camunda:validation>
              <camunda:constraint name="required" />
            </camunda:validation>
          </camunda:formField>
        </camunda:formData>
      </bpmn:extensionElements>
      <bpmn:outgoing>Flow_1s5g9d6</bpmn:outgoing>
    </bpmn:startEvent>

validate_start_event.bpmn (2.8 KB)

Edit: removed unrelated information from screenshot and added XML

It can be seen that there are no process variables, even though validate_me is marked as required.