How to generate request body for Post Local Execution Variable (Binary)

Hi,

I’ve got a problem to generate the request body for posting local execution Binary variables. As described in the docs, the REST api could set the serialized value for a binary variable in the context of a given execution by id. However, it is difficult for me the understand the request body of the API.

For example, the following request body is used to set the JSON serialization of a Java Class.

---OSQH1f8lzs83iXFHphqfIuitaQfNKFY74Y
Content-Disposition: form-data; name="data"
Content-Type: application/json; charset=US-ASCII
Content-Transfer-Encoding: 8bit

["foo", "bar"]
---OSQH1f8lzs83iXFHphqfIuitaQfNKFY74Y
Content-Disposition: form-data; name="type"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

java.util.ArrayList<java.lang.Object>
---OSQH1f8lzs83iXFHphqfIuitaQfNKFY74Y--

How can I understand each part of the body please?

Hi @Tonny_Tc,

If possible, use a non-binary serialization. You can serialize objects as JSON and deserialize them using Camunda SPIN. In this case, you do not need to worry about the composing the endpoint for binary variables. Only use it, if you have to submit a file or byte array.

For the remainder of my response, I assume that binary is a hard requirement. The docs state

For binary variables a multipart form submit with the following parts:

I recommend using some library to create the requests instead of creating them manually.

To understand the request body, we need to understand multipart form submits. This is a specific content type for HTTP request. The respective request bodies consist of multiple parts (hence, multipart). Each part is separated by a boundary. In the example, the boundary is

---OSQH1f8lzs83iXFHphqfIuitaQfNKFY74Y

Next follows some metadata:

  • The variable name (name of the form field), i.e., data: Content-Disposition: form-data; name="data"
  • The MIME type used in the request, i.e., JSON: Content-Type: application/json; charset=US-ASCII
  • The encoding that is used, i.e., 8bit: Content-Transfer-Encoding: 8bit

Finally, the part contains the actual data, which is the value of the variable (form field):

["foo", "bar"]

For the Camunda API, every request must include two parts:

  • data
  • valueType

The name of the process variable and the ID of the execution are set via path parameters. Avoid using the form parts: type and data (with application/json content type).

If you are eager to know more, I recommend reading up on multipart form submits:

@StephanHaarmann
Thanks very much for your kind reply. In fact, I really did not understand the boundary before your explanation.

For my case, there are some variables using Java Class such as java.math.BigDecimal, java.math.BigInteger and so on. And for maintenance purposes, they may be changed via REST api directly. I’m not sure whether the case is suitable to use JSON instead.