# Post Request to Receive Task

**URL:** <https://forum.flowable.org/t/post-request-to-receive-task/5017>\
**Category:** Flowable Engine\
**Created:** [December 8, 2019, 3:00pm UTC](https://forum.flowable.org/t/post-request-to-receive-task/5017 "2019-12-08T15:00:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rima](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rima](https://forum.flowable.org/u/rima)\
**Post date:** [December 8, 2019, 3:00pm UTC](https://forum.flowable.org/t/post-request-to-receive-task/5017/1 "2019-12-08T15:00:04Z")

</div>

Hello there,

we’re having a receive task in our process where we wait a certain amount of months until somebody sends something to the system. Now we want to test this process using a post request from postman. We found a way using the REST API to find out the process instance id (flowable-taks/process-api/runtime/process-instances) and as there is no simple way to set a business key we now want to adress our post request against the process instance id.

Our first question would be if this is the right way of doing this and if yes, how we have to formulate the post request.

Best regards and many thanks in advance  
Marius

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [December 11, 2019, 2:17pm UTC](https://forum.flowable.org/t/post-request-to-receive-task/5017/2 "2019-12-11T14:17:06Z")

</div>

Are you using the prebuilt Flowable-Rest application or a custom application with the REST API enabled? If you building a custom app, you can create your own endpoint but you’d have to make some assumptions about how many tasks will be active at a time. Imagine the following situation:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/4/49338cf0c15bb2c24d206343368e62f7fd3828a6.png)

In this case there is a parallel gateway casing both send tasks to be executed followed by both receive tasks to await triggering. In this case, the process instance id is insufficient to determine which receive task needs to be triggered. If you know that only one triggerable task will be active at a time and don’t mind making that limitation permanent it would be easy to add an endpoint that takes the process instance id, queries for all active tasks and sends a trigger. Technically you could filter on task name but you’d need to deal with the complexity. You can do the same thing via a couple of calls to the REST API, if you don’t want to create your own end point.

As far as modeling the process goes, using a receive task is acceptable but if the message you are trying to receive comes in very quickly you might end up with a race condition between the message and Flowable’s database transaction. That can be solved using a transaction listener to do the actual sending:

```auto
    @Override
    public void execute(DelegateExecution delegateExecution) {
        ...

        Context.getTransactionContext().addTransactionListener(TransactionState.COMMITTED, new TransactionListener() {

            @Override
            public void execute(CommandContext commandContext) {
                rabbitTemplate.convertAndSend(exchange, routingKey, messageContent);
            }
        });
    }

```

It can be further refined by using a triggerable service task instead of a separate send and receive tasks.

Will

---

<div class="post-metadata">

**Author:** ![rima](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rima](https://forum.flowable.org/u/rima)\
**Post date:** [December 12, 2019, 4:04pm UTC](https://forum.flowable.org/t/post-request-to-receive-task/5017/3 "2019-12-12T16:04:39Z")

</div>

Hey Will,

first of all thanks for your valuable input. I’m afraid we still don’t get how we could post to our receive task.

Our receive task in theory will wait for weeks for it’s message so we don’t have a necessity to use triggerable tasks in this case.

We thought we could use the prebuilt Flowable REST application for this use case but if it’s necessary we also have no problem to create a custom REST API application. We just don’t know A how we should do this and B how to connect all of this to our flowable process model. Is there any specific step by step documentation for this procedure?

Best regards  
Marius

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [December 12, 2019, 5:32pm UTC](https://forum.flowable.org/t/post-request-to-receive-task/5017/4 "2019-12-12T17:32:07Z")

</div>

Let’s assume we have a Spring Boot app with flowable-starter-rest and no security (for simpler curl requests) running on port 8989. This app has a single process named `santaGiftRequest`:

![image](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/0/0ce75700d4ae7ff5b4e33b8790c4ade693a57676.png)

It contains a service task to send your wish list to Santa and then a receive task named “getPresents”. You can use the following sequence to fully execute it via the REST API:

1. Starting the process:

```auto
╭─williamwitt@Diagon-Alley.local ~
╰─➤ curl -X POST \
  http://localhost:8989/process-api/runtime/process-instances \
  -H 'Content-Type: application/json' \
  -d '{
        "processDefinitionKey": "santaGiftRequest"
}' | jq
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 733 0 686 100 47 133k 9400 --:--:-- --:--:-- --:--:-- 143k
{
  "id": "e03b2b6c-1d04-11ea-a2ac-1ee190cb6f7e",
  "url": "http://localhost:8989/process-api/runtime/process-instances/e03b2b6c-1d04-11ea-a2ac-1ee190cb6f7e",
  "name": null,
  "businessKey": null,
  "suspended": false,
  "ended": false,
  "processDefinitionId": "santaGiftRequest:1:573a866f-1d00-11ea-a2ac-1ee190cb6f7e",
  "processDefinitionUrl": "http://localhost:8989/process-api/repository/process-definitions/santaGiftRequest:1:573a866f-1d00-11ea-a2ac-1ee190cb6f7e",
  "processDefinitionName": "Santa Gift Request",
  "processDefinitionDescription": null,
  "activityId": null,
  "startUserId": null,
  "startTime": "2019-12-12T11:28:56.727-06:00",
  "variables": [],
  "callbackId": null,
  "callbackType": null,
  "tenantId": "",
  "completed": false
}

```

1. Find the execution

```auto
╭─williamwitt@Diagon-Alley.local ~
╰─➤ curl -X POST \
  http://localhost:8989/process-api/query/executions/ \
  -H 'Content-Type: application/json' \
  -d '{
        "processInstanceId": "e03b2b6c-1d04-11ea-a2ac-1ee190cb6f7e",
        "activityId": "getPresents"
}' | jq
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 759 0 665 100 94 216k 31333 --:--:-- --:--:-- --:--:-- 247k
{
  "data": [
    {
      "id": "e03b527e-1d04-11ea-a2ac-1ee190cb6f7e",
      "url": "http://localhost:8989/process-api/runtime/executions/e03b527e-1d04-11ea-a2ac-1ee190cb6f7e",
      "parentId": "e03b2b6c-1d04-11ea-a2ac-1ee190cb6f7e",
      "parentUrl": "http://localhost:8989/process-api/runtime/executions/e03b2b6c-1d04-11ea-a2ac-1ee190cb6f7e",
      "superExecutionId": null,
      "superExecutionUrl": null,
      "processInstanceId": "e03b2b6c-1d04-11ea-a2ac-1ee190cb6f7e",
      "processInstanceUrl": "http://localhost:8989/process-api/runtime/process-instances/e03b2b6c-1d04-11ea-a2ac-1ee190cb6f7e",
      "suspended": false,
      "activityId": "getPresents",
      "tenantId": ""
    }
  ],
  "total": 1,
  "start": 0,
  "sort": "processInstanceId",
  "order": "asc",
  "size": 1
}

```

1. Trigger the execution

```auto
╭─williamwitt@Diagon-Alley.local ~
╰─➤ curl -X PUT \
  http://localhost:8989/process-api/runtime/executions/e03b527e-1d04-11ea-a2ac-1ee190cb6f7e \
  -H 'Content-Type: application/json' \
  -d '{
        "action": "trigger",
          "variables": [
    {
      "name": "myVariable",
      "type": "string",
      "value": "test"
    }
  ]
}' | jq
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 133 0 0 100 133 0 13300 --:--:-- --:--:-- --:--:-- 13300

```

Edit: If you’re using the prebuilt flowable-rest app, you’ll use basic authentication and the process endpoint is mapped at `/flowable-rest/service/` instead of `/process-api/`

Will

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [December 12, 2019, 5:39pm UTC](https://forum.flowable.org/t/post-request-to-receive-task/5017/5 "2019-12-12T17:39:30Z")

</div>

Docs for doing this via the Java API:  
[https://flowable.org/docs/userguide/index.html#\_xml\_representation\_2](https://flowable.org/docs/userguide/index.html#_xml_representation_2)
