5
votes

I am trying to pass json payload in variables as value to start a process definition using engine-rest api as below:-

API:

http://localhost:8080/engine-rest/process-definition/processService:1:9459dbe9-6b2c-11e8-b9e8-28d2447c697a/start

Body :

{
  "variables": {
      "payload": {
        "value": {
            "mode": "email",
            "meta": [{
                "key": "topic",
                "value": "weather"
            }, {
                "key": "qos",
                "value": "2"
            }]
        },
        "type": "Json"
      }
  }
}

but it is giving 400 BAD REQUEST with below error:- Must provide 'null' or String value for value of SerializableValue type 'Json'.

Also i have used a expression in my BPMN process to fetch a key-value pair like below, it also throwing me error :-

${S(payload).prop("mode").stringValue() == 'email'}

Now working steps:- when i try to send body json payload in string format then it works fine.

API:

http://localhost:8080/engine-rest/process-definition/processService:1:9459dbe9-6b2c-11e8-b9e8-28d2447c697a/start

Body:

{
  "variables": {
      "payload": {
        "value": "{\"mode\": \"email\",\"meta\": [{\"key\": \"topic\",\"value\": \"weather\"},{\"key\": \"qos\",\"value\": \"2\"}]}",
        "type": "String"
      }
  }
}

same java code i am using here to fetch json payload-

public void notify(DelegateExecution delegateProcessExecution) throws Exception {
   Object notificationPayload =
       delegateProcessExecution.getVariable("payload");

    if (null != notificationPayload) {
        String notifyPayload = notificationPayload.toString();  
        JSONObject inputJson = new JSONObject(notifyPayload);
    }
    // ...
}

So i want this payload as json for whole process so that i don't need to convert it to string as above working example.

2

2 Answers

2
votes

You should only change the type to "json", example:

{
    "variables": {
        "broker": {
            "value": "{\"name\":\"Broker Name\"}",
            "type": "json"
        }
    }
}
0
votes

This is apparently a shortcoming in the rest engine up to V7.10.0, I have created a Jira Issue for this: https://app.camunda.com/jira/browse/CAM-9617.

The workaround is to pass an escaped JSON String as value, as you have pointed out above. One can also use "type": "Object" if the engine has a Jackson Java Bean on the classpath that matches the given value. You supply the bean type name in a valueInfo object:

https://docs.camunda.org/manual/7.10/reference/rest/process-definition/post-start-process-instance/#request-body

For example:

{
  "variables": {
      "payload": {
        "value": "{\"mode\": \"email\",\"meta\": [{\"key\": \"topic\",\"value\": \"weather\"},{\"key\": \"qos\",\"value\": \"2\"}]}",
        "type": "String",
        "valueInfo": {
            "objectTypeName": "my.own.BeanWithModeAndMetaProps",
            "serializationDataFormat": "application/json"
            }
      }
  }
}