# update API response

**URL:** <https://community.ofelia.com/t/update-api-response/9364>\
**Category:** Q&A\
**Created:** [11 December 2018 14:47 UTC](https://community.ofelia.com/t/update-api-response/9364 "2018-12-11T14:47:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhonata.v.t\_1373703](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jhonata.v.t\_1373703](https://community.ofelia.com/u/jhonata.v.t_1373703)\
**Post date:** [11 December 2018 14:47 UTC](https://community.ofelia.com/t/update-api-response/9364/1 "2018-12-11T14:47:50Z")

</div>

I use an API call on my application page to return the tasks of a process, for example: Process 01 with the Tasks (Step1, Step2, Step3).

I need to create a javascript code that recognizes when a change from Step1 to Step 2 occurs. That is, when one task completes and moves on to the next. The problem is, the API always returns the outdated value from my task list. When a task is executed, the return of my API does not change automatically, I need something that does this.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [12 December 2018 18:21 UTC](https://community.ofelia.com/t/update-api-response/9364/2 "2018-12-12T18:21:24Z")

</div>

Hello - when you say that the “return of my API does not change automatically”, are you talking about a “REST API extension” variable that you use in a page built using the UI Designer?

---

<div class="post-metadata">

**Author:** ![jhonata.v.t\_1373703](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jhonata.v.t\_1373703](https://community.ofelia.com/u/jhonata.v.t_1373703)\
**Post date:** [13 December 2018 13:41 UTC](https://community.ofelia.com/t/update-api-response/9364/3 "2018-12-13T13:41:05Z")

</div>

Yes, I use a “Rest APi extension” variable.

As I said above, I use an API to return information about tasks related to a process. One of the information that the API returns is the name of the task (displayName), but when the task is executed the information it should return is different.

For example:

Process 01 - Tasks (Step1, Step2, Step3)

API return

[“displayDescription”: “”, “executedBy”: “0”, “rootContainerId”: “51026”, “assigned\_date”: “”, “displayName”: “Step2”, “executedBySubstitute”: “0”, "dueDate “” “” “” “” “” “” “” “” “” “” “” “” “” “” “” “” “” “” “” 51026 “,” name “:” Step2 “,” reached\_state\_date “:” 2018-12-11 “,” rootCaseId “:” 51026 “,” id “:” 1140126 “,” state “:” ready “,” parentCaseId " : “51026”, “last\_update\_date”: “2018-12-11 13:45: 32,566”, “assigned\_id”: “”, “person”: “”}

I execute the Step2 task - API return is the same as the previous one.

I refresh the page - API return is updated.

My problem is that: I can not refresh the page, the information is not shown in a div, ie AJAX is not useful.  
I need some method that only updates API return because I need the updated information to execute a javascript code.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [13 December 2018 14:02 UTC](https://community.ofelia.com/t/update-api-response/9364/4 "2018-12-13T14:02:32Z")

</div>

Thank you for the clarification. The REST API Extension does not work like this, it basically makes the call at page load and that’s it. If you need to poll periodically I think the best is to create a dedicated custom widget with a bidirectional property.

HIH,

---

<div class="post-metadata">

**Author:** ![jhonata.v.t\_1373703](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jhonata.v.t\_1373703](https://community.ofelia.com/u/jhonata.v.t_1373703)\
**Post date:** [13 December 2018 14:52 UTC](https://community.ofelia.com/t/update-api-response/9364/5 "2018-12-13T14:52:50Z")

</div>

Thanks a lot for the help.

Could you explain me better how this “bidirectional property” works and how can I implement it? It would be a great help.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [13 December 2018 14:57 UTC](https://community.ofelia.com/t/update-api-response/9364/6 "2018-12-13T14:57:51Z")

</div>

Sure, here is some literature about [Custom Widget](https://documentation.bonitasoft.com/bonita/7.8/custom-widgets) and [property types](https://documentation.bonitasoft.com/bonita/7.8/widget-properties) .

---

<div class="post-metadata">

**Author:** ![jhonata.v.t\_1373703](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jhonata.v.t\_1373703](https://community.ofelia.com/u/jhonata.v.t_1373703)\
**Post date:** [13 December 2018 15:18 UTC](https://community.ofelia.com/t/update-api-response/9364/7 "2018-12-13T15:18:26Z")

</div>

I thought you were referring to “data binding” when you said “bi-directional ownership” - as described in these references:

[https://gist.github.com/emchateau/e3057c7e76a50d895e98b6d6bd7404ac](https://gist.github.com/emchateau/e3057c7e76a50d895e98b6d6bd7404ac)

[https://stackoverflow.com/questions/45490004/2-way-data-binding-in-javascript](https://stackoverflow.com/questions/45490004/2-way-data-binding-in-javascript)

I could not figure out how to reach my ultimate goal through the literatures you mentioned.

Remember, briefly, I need to update an API callback. I did something related to http calls with the GET method, but I did not succeed.

---

<div class="post-metadata">

**Author:** ![jhonata.v.t\_1373703](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jhonata.v.t\_1373703](https://community.ofelia.com/u/jhonata.v.t_1373703)\
**Post date:** [13 December 2018 16:02 UTC](https://community.ofelia.com/t/update-api-response/9364/8 "2018-12-13T16:02:53Z")

</div>

I tried to do this: did not work

function update(){

var xmlhttp;  
xmlhttp = new XMLHttpRequest();  
xmlhttp.onreadystatechange = function(){  
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){  
callback(xmlhttp.responseText);  
}  
};  
xmlhttp.open(“GET”, “[http://localhost:8080/bonita/API/bpm/task?p=0&c=10](http://localhost:8080/bonita/API/bpm/task?p=0&c=10)”, false);  
xmlhttp.send();  
var serverResponse = xmlhttp.responseText;  
return serverResponse;

}

setInterval(update, 1000);

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [14 December 2018 14:39 UTC](https://community.ofelia.com/t/update-api-response/9364/9 "2018-12-14T14:39:49Z")

</div>

You should have a look into this [contributed Custom Wigdet](http://community.ofelia.com/project/widgetautoassign) . An HTTP call is being done to assign the current user to the current task (in a form). It should be a great example of what you need to do to make a valid REST API call to Bonita.

HIH,
