Triggering message event via REST API

I’m running the Camunda Process Engine and interacting with it via the REST API. I’m able to deploy process definitions and kick of process instances with no problem. I’ve run thru manual tasks, service tasks, etc. all without issue.

However, I’m having problems with the message events. I’ve created a simple workflow with a Start -> Message Intermediate Catch Event -> End sequence. I kick off the process and can verify in the Cockpit that it’s running and sitting at the message catch event. I then use the REST API to query for the message event subscription:

http://localhost:8080/engine-rest/execution/ca6d6fff-9ca7-11e6-ad85-28d24460819d/messageSubscriptions/test

The “test” is the name of the message as defined in the BPMN, as the GUID is my process ID. The response I get back is this:

{
“type”: “InvalidRequestException”,
“message”: “Message event subscription for execution ca6d6fff-9ca7-11e6-ad85-28d24460819d named test does not exist”
}

I’ve tried using the Message ID instead of the name, but no luck. I’ve also tried this with a Message Receive Task, but again, I get the message that no subscription for the message event exists. I’ve also tried triggering the event by POSTing the following:

http://localhost:8080/engine-rest/execution/ca6d6fff-9ca7-11e6-ad85-28d24460819d/messageSubscriptions/test/trigger

I get the following response:

{
“type”: “RestException”,
“message”: “Cannot trigger message Test for execution ca6d6fff-9ca7-11e6-ad85-28d24460819d: Execution with id ‘ca6d6fff-9ca7-11e6-ad85-28d24460819d’ does not have a subscription to a message event with name ‘test’: eventSubscriptions is empty”
}

The response clearly seems to indicate that the process is not subscribed to any events, which seems wrong given I see that the process is clearly blocked at an message catch event node.

Am I misunderstanding the message event, or is this behavior expected? I’m assuming that I need to invoke the “trigger” API to satisfy this event and move the workflow forward. Any help would be appreciated.

You don’t need to contact the execution - you can send a message to the Engine itself and it will collaborate with any waiting processes
Use the POST http://localhost:8080/engine-rest/message call do to this.

You can find a full example here.

2 Likes

Thanks so much, Niall – can’t believe I missed that. Worked like a charm :slight_smile:

I checked the example but how can i trigger [Timer Intermediate catch event] which has 23 hours duration on it.

Hello @recep_daban

Welcome to Camunda forum !

Please help me understand your use case, so that I can help you better. Could you please confirm why you want to trigger Timer intermediate catch event manually? The timer event would automatically be fired after specified interval/duration i.e. 23 hours in your case. In case you want this timer to get fired in regular intervals, you would have to change the Timer Definition accordingly ( please see https://docs.camunda.org/manual/7.12/reference/bpmn20/events/timer-events/#time-cycle).
More details about Timer events are in user-guide https://docs.camunda.org/manual/7.12/reference/bpmn20/events/timer-events/#timer-intermediate-catching-event.

Best,
Garima

1 Like

Hi @garima,

Thanks for repy. I want to trigger Timer intermediate catch by REST API. I tried to use POST /message methot at https://docs.camunda.org/manual/7.12/reference/rest/message/post-message/ but could not accomplish. After some research i found this https://docs.camunda.org/manual/latest/reference/rest/job/put-set-job-duedate/ . But I dont know this is right way to trigger timer by REST API.

Hello @recep_daban

If I understand correctly, you want to trigger execution of Timer event before its scheduled time ( which is after 23 hours in your case). If yes, then REST api https://docs.camunda.org/manual/latest/reference/rest/job/put-set-job-duedate/ can be used to update the duedate. For example: You can set the duedate to 2 minutes after or may be in the past if you want it to run immediately.

Best
Garima

Yes right. I want to trigger before its scheduled time. So right way to trigger timer via REST API use update due date. Thanks for reply