Trigger event subprocess using rest api

Hi,

I am trying to trigger event sub process(can be started by message start event) using rest api and i am getting 400 as http response Can someone help me to sort this issue.

URL used : POST /message
Request Body : {
“messageName” : “test”,
“businessKey” : “123”,
“correlationKeys” : {
“businessKey” : {“value” : “123”, “type”: “String”}
},
“processVariables” : {
“localVariable”: {
“value”: “demo”,
“type”: “String”
}
}
}
Http response : 400 connection closed.

Hi @satheshkumar.s welcome to the forum,

Can you please upload the model you’re sending the message to?
Also upload the code showing how youre starting the process.

P.S. If you post code it’s easier to read if you use the correct syntax - read the style guide to improve the readability of your post.

Hi Niall,

Thanks for your response. Please find the details below.The special characters are generated by IDE. Please ignore it.

Java code used in external task to trigger event sub process :

    String url = "http://<hostname>:<port number>/engine-rest/message";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("POST");
    con.setRequestProperty("Content-Type","application/json");
    String postJsonData = "{\n" +
            "  \"messageName\" : \"startConsume\",\n" +
            "  \"businessKey\" : \"1234\",\n" +
            "  \"correlationKeys\" : {\n" +
            "    \"businessKey\" : {\"value\" : \"123\", \"type\": \"String\"}\n" +
            "  },\n" +
            "  \"processVariables\" : {\n" +
            "    \"localVariable\": {\n" +
            "            \"value\": \"demo\",\n" +
            "            \"type\": \"String\"\n" +
            "\t\t\t}\n" +
            "  }\n" +
            "}";

    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(postJsonData);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();
    System.out.println("nSending 'POST' request to URL : " + url);
    System.out.println("Post Data : " + postJsonData);
    System.out.println("Response Code : " + responseCode);

Test Process.bpmn (6.8 KB)

Looks like you’re starting the process with
business key = 1234
and you’re trying to send a message to a process with
business key = 123

So that would explain why it can’t find the process

I did try with same business key . But no luck.

The local variables you’re using will also have a problem - they probably don’t exist in the context that the message will be received. You should take them out and it should work.

Also take a look in camunda’s own logs for a details about the error

Hi Niall,
I did change my request body as below . But still it’s not working.

Request Body:
{
“messageName” : “startConsume”,
“businessKey” : “123”,
“correlationKeys” : {
“businessKey” : {“value” : “123”, “type”: “String”}
}
}

Camunda Error log:
ENGINE-16004 Exception while closing command context: Cannot correlate message ‘startConsume’: No process definition or execution matches the parameters

This error message occurs while correlating a message with either invalid businessKey or invalid correlationkeys/process variables.

Correlating the message with invalid businessKey:
image

Error message:

org.camunda.bpm.engine.context : ENGINE-16004 Exception while closing command context: Cannot correlate message 'unknownMessage': No process definition or execution matches the parameters

org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message 'unknownMessage': No process definition or execution matches the parameters
	at org.camunda.bpm.engine.impl.cmd.CorrelateMessageCmd.execute(CorrelateMessageCmd.java:88) ~[camunda-engine-7.13.0-ee.jar:7.13.0-ee]

Correlating message with proper keys:

{    
    "businessKey": "KNO222",
    "messageName": "unknownMessage",
    "correlationKeys": {
        "name": {
            "value": "peter",
            "type": "String"
        }
    },
    "processVariables": {
        "city": {
            "value": "bangalore",
            "type": "String"
        }
    },
    "resultEnabled": true
}

Response:

[
    {
        "resultType": "Execution",
        "execution": {
            "id": "8379acb1-f47d-11ea-9154-507b9dc4ed46",
            "processInstanceId": "8379acb1-f47d-11ea-9154-507b9dc4ed46",
            "ended": false,
            "tenantId": null
        },
        "processInstance": null
    }
]

Deploy this bpmn file and test: MessageService.bpmn (5.8 KB)

1 Like