Invoking REST API inside a process/diagram



What's the correct way to invoke the REST API from inside a BPM/process? I'm getting the 401 Unauthorized response when trying to use the REST Connector to a bonita API.

When invoking it externally, I understand that you need to call the login service and use the received X-Bonita-API-Token cookie. But inside a BPM what's the proper way? Should we use the same logic, with the execution of a REST Connector to the login service, processing the response headers and then send it as a cookie?

If i'm already executing the process inside the bonita scope, it seems that you'd have to do this kind of logic. Is there any other way?

Thanks in advance


Submitted by gulack on Wed, 08/08/2018 - 15:31

The final goal is to read all BDM entities/objects (in a specific state). Maybe there's some better way for that, without using the REST Connector.

2 answers

This one is the BEST answer!

What about using the Java API (from a Groovy Script Connector) instead of REST API Connector? Usually, REST API is a good choice when your client does not use Java language.

Here is the official documentation in case you wanna give a try.


Hi Pierrick,

That sent me in the right direction. I hadn't come back to this since your reply, but in a couple of minutes I'm already being able to read/search for processes.

For now, and for future reference, here's how it is:

import org.bonitasoft.engine.api.LoginAPI
import org.bonitasoft.engine.api.ProcessAPI
import org.bonitasoft.engine.api.TenantAPIAccessor
import org.bonitasoft.engine.bpm.flownode.ArchivedActivityInstanceSearchDescriptor
import org.bonitasoft.engine.bpm.flownode.impl.internal.UserTaskInstanceImpl
import org.bonitasoft.engine.session.APISession

LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
APISession session = loginAPI.login("%USERNAME%", "%PASSWORD%");

ProcessAPI papi = TenantAPIAccessor.getProcessAPI(session);

SearchOptionsBuilder searchBuilder = new SearchOptionsBuilder(0, 100);
//searchBuilder.filter(ArchivedActivityInstanceSearchDescriptor.ROOT_PROCESS_INSTANCE_ID, processInstance.getId());
//searchBuilder.filter(ArchivedActivityInstanceSearchDescriptor.ASSIGNEE_ID, myUser.getId());
searchBuilder.sort(ArchivedActivityInstanceSearchDescriptor.NAME, Order.ASC);

SearchOptions so = searchBuilder.done();
SearchResult res = papi.searchAssignedAndPendingHumanTasks(so);

Iterator it = res.getResult().iterator();

while (it.hasNext()){
    UserTaskInstanceImpl o =;

    // Do whatever

return "whatever";

Thank you very much!


Submitted by gulack on Fri, 08/24/2018 - 15:37

For completion/correction of my previous answer, if you're using this in a groovy script inside a process, you won't need to perform the API login. You may get the ProcessAPI (and others) directly from the apiAccessor variable.