How to build process variables. VariablesBuilder is missing


I would like to start an instance invoice process using REST API. The endpoint requires variables object, which is in the following form
“variables”: {
“invoiceNumber” : {“value” : “ZZZZ”, “type”: “string”},
“amount” : {“value” : 30, “type”: “integer”},
“creditor” : {“value” : “Creditor 1”, “type”: “string”},
“invoiceCategory” : {“value” : “Category 1”, “type”: “string”},
“approverGroups” : {“value” : true, “type”: “boolean”},
“invoiceClassification”: {“value” : “Creditor 1”, “type”: “string”}
The question is, what is the best (right) way of constructing such an object? Is there a JAVA object with setters, so I could use it?


I found VariablesBuilder java class and with the help of it I created the following

        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("variables", VariablesBuilder.create()
                                                    .variable("invoiceNumber", "YYY", "string")
                                                    .variable("amount", 300, "integer")
                                                    .variable("invoiceId", "ZZ-345")
                                                    .variable("creditor", "Creditor 1", "string")
                                                    .variable("invoiceCategory", "Category 1", "string")
                                                    .variable("approverGroups", true, "boolean")
                                                    .variable("invoiceClassification", "Creditor 1", "string")

        webTarget = webTarget.path("process-definition/key")
        Response response =
            .post(Entity.entity(JSON(parameters).toString(), MediaType.APPLICATION_JSON), Response.class);

The issue is, the VariablesBuilder is not available in the camunda-engine-rest-core-7.8.0.jar file. What is the reason of not including it into the above jar?


Hi @thorben! From the code comment, I see that you are the author of this class, could you please let me know why this did not make to the main core? Would it be safe to use it in my custom application or there some other ways to set the variables?


It is used in unit tests only. The main codebase doesn’t need the class.

The engine-rest classes artifact is not intended to be used with JAX-RS client libraries, so it will probably not work out of the box in a couple of such use cases. You can always write or copy custom code to work around that.