# Query Formdata using rest api

**URL:** <https://forum.flowable.org/t/query-formdata-using-rest-api/1485>\
**Category:** Flowable Application\
**Created:** [January 24, 2018, 12:24am UTC](https://forum.flowable.org/t/query-formdata-using-rest-api/1485 "2018-01-24T00:24:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziwenzhao](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ziwenzhao/32/491_2.png) [@ziwenzhao](https://forum.flowable.org/u/ziwenzhao)\
**Post date:** [January 24, 2018, 12:24am UTC](https://forum.flowable.org/t/query-formdata-using-rest-api/1485/1 "2018-01-24T00:24:50Z")

</div>

Hi, I want to get the formdata of a task or a processDefinition using rest api.  
The first approach is that I set the form properties (of a task) one by one, and I can get the formdata using api.  
But the second approach is that I associated a task with a reference form, in this way I cannot get formdata using rest api.  
So is there something I did wrong? Or currently, if I want to use rest api to query formdata, the only way is setting form properties one by one?

Regards,  
Ziwen

---

<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:** [January 24, 2018, 10:47am UTC](https://forum.flowable.org/t/query-formdata-using-rest-api/1485/2 "2018-01-24T10:47:09Z")

</div>

Hi Ziwen,

The form data api is there for the form properties approach we have since a long time in Flowable. The new approach is using the form definition JSON you create in the Flowable Modeler and reference from the user task. There is a separate api for using the new form definitions. On the RuntimeService there’s the getStartFormModel method to fetch a start form model and startProcessInstanceWithForm to start a new process instance with the form input. On the TaskService there’s the getTaskFormModel method to fetch a task form and completeTaskWithForm to complete a task with the form input.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![ziwenzhao](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ziwenzhao/32/491_2.png) [@ziwenzhao](https://forum.flowable.org/u/ziwenzhao)\
**Post date:** [January 28, 2018, 5:22am UTC](https://forum.flowable.org/t/query-formdata-using-rest-api/1485/3 "2018-01-28T05:22:51Z")

</div>

Thanks for the reply, but I am current using rest api to interact with flowable-task.  
The domain is localhost:8080/flowable-task/process-api  
So in the docs, there is a **GET form/form-data** rest api to get form data, but it can only get data if I set form properties one by one in the modeler, but not if I associate a usertask with a customized reference form.

Regards,  
Ziwen

---

<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:** [January 28, 2018, 10:40am UTC](https://forum.flowable.org/t/query-formdata-using-rest-api/1485/4 "2018-01-28T10:40:28Z")

</div>

Hi Ziwen,

Ok, for the rest api the same difference is true. the form/form-data rest service only provides the form properties defined on a user task. On /flowable-task/form-api/form-repository/form-definitions you can query on form definitions with the key you used when creating the form definition in the Flowable Modeler. And with /flowable-task/form-api//form-repository/deployments/{deploymentId}/resourcedata/{resourceName} you can get the actual form definition JSON.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![ziwenzhao](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ziwenzhao/32/491_2.png) [@ziwenzhao](https://forum.flowable.org/u/ziwenzhao)\
**Post date:** [January 28, 2018, 9:06pm UTC](https://forum.flowable.org/t/query-formdata-using-rest-api/1485/5 "2018-01-28T21:06:56Z")

</div>

Thank you very much. It works. I wonder if there is any way to get the entire form, like a html component, so its appearance will looks like the same as when I designed it.  
I mean that I can put the this form component directly in html, instead of rendering it with all the properties myself.

Regards,  
Ziwen

---

<div class="post-metadata">

**Author:** ![Florian\_Faist](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/florian_faist/32/635_2.png) [@Florian\_Faist](https://forum.flowable.org/u/Florian_Faist)\
**Post date:** [September 12, 2019, 2:27pm UTC](https://forum.flowable.org/t/query-formdata-using-rest-api/1485/6 "2019-09-12T14:27:55Z")

</div>

This is my solution to load a Form.  
I use the Flowable Rest Api / swagger

```
public Optional<FormModelResponse> getFormInstanceModelByTaskId(String taskId) {
    Optional<FormDataResponse> formData = getFormsByTaskId(taskId);
    if (formData.isPresent()) {
        try {
            //When a form loads the First time it is not saved as FormInstance during PE. So u have to do it in your own way
            String formInstanceId = createEmptyFormInstanceIfNotExists(formData.get().getFormKey(), taskId);
            FormRequest formRequest = new FormRequest();
            formRequest.setTaskId(taskId);
            formRequest.setFormInstanceId(formInstanceId);
            //Now you can load a the Form Instance because later u need the Version of your Process corresponding Form Deployment
            FormInstanceModelResponse instanceData = flowableServiceFactory.getFormInstanceModelsApi().getFormInstanceModel(formRequest);
            FormDefinitonQueryModel formDefinitionQuery = new FormDefinitonQueryModel();
            formDefinitionQuery.setKey(instanceData.getKey());
            formDefinitionQuery.setVersion(instanceData.getVersion().toString());
            // With the Formdefinition Query you get The Form Definition id in the Correct Version you need that for the Form Definition id
            DataResponseFormDefinitionResponse formdDefResult = flowableServiceFactory.getFormDefinitionsApiExtended().getFormDefenitionByQuery(formDefinitionQuery);
            formRequest.setFormDefinitionId(formdDefResult.getData().get(0).getId());
            //Now your Query is ready to load the Form in the correct Version with your task.
            // That is not funny -> so much requests for a correct loaded Form. I hope there is a better way in future
            FormModelResponse data = flowableServiceFactory.getFormModelsApi().getFormModel(formRequest);
            return Optional.ofNullable(data);
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }
    return Optional.empty();
}
```
