# Return Values from HTTPTask Rest Call

**URL:** <https://forum.flowable.org/t/return-values-from-httptask-rest-call/1738>\
**Category:** Flowable Engine\
**Created:** [March 12, 2018, 1:15pm UTC](https://forum.flowable.org/t/return-values-from-httptask-rest-call/1738 "2018-03-12T13:15:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarcasigan](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sarcasigan](https://forum.flowable.org/u/sarcasigan)\
**Post date:** [March 12, 2018, 1:15pm UTC](https://forum.flowable.org/t/return-values-from-httptask-rest-call/1738/1 "2018-03-12T13:15:26Z")

</div>

Hello,

I am new to Flowable, but i have successfully called an external RESTful API thru HTTP Task, but i want the response from HTTP Task returned back to me so i could return it back to the caller, is this possible?

Sample code:  
public CommonResponse startProcess(Interview interview) {

```
    repositoryService.createDeployment()
        .addClasspathResource("processes/sample-timer-process.bpmn20.xml").deploy();

    CommonResponse commonResponse = new CommonResponse(
        CommonResponse.SUCCESS, CommonResponse.SUCCESS);

    try {
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("sampleRequestBody", interview);

        runtimeService.startProcessInstanceByKey("timerProcess", variables);
    } catch (FlowableObjectNotFoundException e) {
        commonResponse.setStatus(CommonResponse.ERROR);
        commonResponse.setMessage(e.getMessage());
        return commonResponse;
    }

    return null;
}

```

So instead of returning null at the bottom, i would like to return the response from the call.

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [March 13, 2018, 9:37am UTC](https://forum.flowable.org/t/return-values-from-httptask-rest-call/1738/2 "2018-03-13T09:37:13Z")

</div>

Hi,

Has the process instance finished immediately after the start process instance was started? Or is it still running and waiting in a user task for example?  
If the process instance is still running you can use the runtimeService getVariables method to get the process variables. If the process instance has ended you could use the HistoryService to get the process variables.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![sarcasigan](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sarcasigan](https://forum.flowable.org/u/sarcasigan)\
**Post date:** [March 13, 2018, 10:54am UTC](https://forum.flowable.org/t/return-values-from-httptask-rest-call/1738/3 "2018-03-13T10:54:43Z")

</div>

Thanks for the reply.

The process instance has ended, and i have added History Service code already but got no process variables.  
See code below:  
runtimeService.startProcessInstanceByKey(“timerProcess”, variables);

```
        List<HistoricProcessInstance> history =
            historyService.createHistoricProcessInstanceQuery()
                .processDefinitionKey("timerProcess").finished().list();

        for (HistoricProcessInstance historyInstance: history) {
            Map<String, Object> response = historyInstance.getProcessVariables();
            for (Entry<String, Object> entry : response.entrySet()){
                System.out.println(entry.getKey() + " " + entry.getValue());
            }
        }

```

Please help why there is no process variables? Is it because “returnVariables” is not set to true?  
If yes, how to set “returnVariables” to true thru Java?

---

<div class="post-metadata">

**Author:** ![sarcasigan](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sarcasigan](https://forum.flowable.org/u/sarcasigan)\
**Post date:** [March 13, 2018, 2:03pm UTC](https://forum.flowable.org/t/return-values-from-httptask-rest-call/1738/4 "2018-03-13T14:03:33Z")

</div>

I think i have gotten the response using this code snippet:  
List history =  
historyService.createHistoricVariableInstanceQuery()  
.variableName(“httpPost.responseBody”)  
.orderBy(new TaskQueryProperty()).desc()  
.listPage(0, 1);

---

<div class="post-metadata">

**Author:** ![arpit.agrawal](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@arpit.agrawal](https://forum.flowable.org/u/arpit.agrawal)\
**Post date:** [March 17, 2018, 6:31pm UTC](https://forum.flowable.org/t/return-values-from-httptask-rest-call/1738/6 "2018-03-17T18:31:08Z")

</div>

Hi,

> [@sarcasigan](#):
>
> List\<HistoricProcessInstance\> history =  
> historyService.createHistoricProcessInstanceQuery()  
> .processDefinitionKey(“timerProcess”).finished().list();

if in this query you also add

`.includeProcessVariables()`

you can then access process variables also for a particular process instance otherwise you have to write history variable query also which you posted in your last comment.

Thanks,  
Arpit
