How to integrate BOS engine into a PHP application

bouquetf's picture

Integrating processes into your web applications may be a good idea in many cases. Developing your processes from scratch may be a bit overkill when a solution such as Bonita Open Solution already exists on the internet.

In this article, I will explain the basic steps on how to integrate Bonita processes into a PHP web application.

Install a server
Bonita engine is written in JAVA, so it may be hard to access it in a different language. Fortunately, BOS provides an API over HTTP: the REST API. So, let’s modify a bundle to expose the engine over HTTP.

Firstly, download the Tomcat bundle and extract it into a directory. Let’s name this directory BONITA_SERVER.

We’ll then need to expose the REST API. There are two possible solutions to do this:

  1. Get it from the deploy bundle or
  2. Use the advanced export from Bonita Studio.

As we’ll need a process to test our code, we’ll opt for the second solution (from Bonita Studio). Now start Bonita Studio, go to File > Advanced export... Skip to the last step, untick everything and select Export the runtime and then REST.

Click on Export. In the destination directory, you’ll find get a .war file named bonita-server-rest.war in the web folder. Copy it to the BONITA_SERVER/webapps directory. Go to the BONITA_SERVER/bin folder and launch the startup script.

Deploy a simple process in the userXP (http://localhost:8080/bonita/ user: admin, password: bpm)

We’ll now test the installation by using a REST client user interface like the one you can download here: Select the POST method.

Click on the Headers tab, add a header with the name options and the value, user:admin. Don’t forget to click on the “+” button.

Go to the Auth tab, select Basic authentication and fill in the fields using the following information username:restuser, password:restbpm

In the address field enter: http://localhost:8080/bonita-server-rest/API/queryDefinitionAPI/getLight... and click the >> button.

At the bottom the status, you should see HTTP/1.1 200 OK and in the body tab, you should get an XML representation of the list of processes deployed.
Query the API from PHP
Now that the engine is accessible from HTTP, let’s integrate it into a PHP application. Basically, you just need to write the same query in PHP. To do this, create a new .php file, for example list_processes.php:

We’ll create the query using the HTTP_Request class with this code:

[cc lang=php] addHeader("options","user:admin"); $req->setBasicAuth("restuser", "restbpm"); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->sendRequest(); echo $req->getResponseBody(); ?> [/cc]

When launching the code, the same result should be obtained.

The last thing to do is to parse the XML. Use the following code to display each process name and description:

[cc lang=php] $xml = new SimpleXMLElement($response);

foreach ($xml->LightProcessDefinition as $process) { echo $process->name.' - '.$process->description.' '; } [/cc]

Go to the user experience and check the instances:


Submitted by sahil.agarwal on Wed, 02/05/2014 - 13:53


I have been scratcing my head with tutorial. I have been trying to follow it completely but getting no where , I always get 404 Not Found Error when I try to connect using google rest api client. Also it is for older version.

So could someone please guide me how to get going.

Thanks in advance

Submitted by thiagoaugs on Thu, 09/29/2016 - 16:13

You have example for this case??