PHP webservices integration with bonita engine

I have been trying to follow how to at http://community.bonitasoft.com/blog/how-integrate-bos-engine-php-application.
 The how to seem to be in older version of bonita. I have bonita 6.2. I have been trying to expose rest api over http, but all efforts are going in vain.

Could someone at bonita guide me how to expose rest api for latest 6.2 version.

Any help will be appreciated

Thanks

Sahil

Sahil,

 

Check this page...

http://documentation.bonitasoft.com/web-rest-api-overview

Cheers

Hi Pablo

Thanks for the reply . I have tried with this url as well, Tried to post using PHP's Curl Method but no result

Can you provide any example php code. It would be a great help.

Thanks

Hello,

Please find bellow an example using PHP cURL :

<?php
$username = 'install';
$password = 'install';
$baseURL  = 'http://127.0.0.1:8080/bonita/';

<p>
	function preparePostFields($array) { //from http://stackoverflow.com/a/5224895<br />
	&nbsp; $params = array();<br />
	&nbsp; foreach ($array as $key =&gt; $value) {<br />
	&nbsp; &nbsp; $params[] = $key . '=' . urlencode($value);<br />
	&nbsp; }<br />
	&nbsp; return implode('&amp;', $params);<br />
	}</p>

<p>
	$ch = curl_init();<br />
	//connect<br />
	$data = array('username' =&gt; $username, 'password' =&gt; $password, 'redirect' =&gt; 'false');<br />
	curl_setopt($ch, CURLOPT_URL, $baseURL.'/loginservice');<br />
	curl_setopt($ch, CURLOPT_POST, 1);<br />
	curl_setopt($ch, CURLOPT_POSTFIELDS, preparePostFields($data));<br />
	curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');<br />
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br />
	$content = curl_exec($ch);</p>

<p>
	//get list of users<br />
	curl_setopt($ch, CURLOPT_URL, $baseURL.'/API/identity/user?p=0&amp;c=10&amp;o=lastname%20ASC&amp;f=enabled%3dtrue');<br />
	curl_setopt($ch, CURLOPT_POST, 0);<br />
	$content = curl_exec($ch);<br />
	echo $content;</p>

<p>
	curl_close($ch);<br />
	?&gt;</p>

 I've tested it successfully on 6.2.1

You can find here more examples in Python http://community.bonitasoft.com/blog/how-use-bonita-bpm-6-web-rest-api-python-create-accounts

Hope it helps.

Jérémy

i just try the code but didn’t work , i don’t know what it happens, only i would to login in BONITA API REST, using php curl library ,but my problem is , i don’t know how verify your code, i need your help . thanks!

Hi there, thats very useful thank… just one question:

its always necesary authenticate the user in order to use any other method from the API besides the login service?

drakezilla,

Yes, it is always necesary due the need of the engine of know who is performing the action and obviously by security reasons…

Sahil,

May be this is useful for you...

http://community.bonitasoft.com/answers/how-use-bonitasoft-rest-api-pythondjango

i tried this code and it doesn’t work .how you tried this code?

Hello claz08,

Edit a file, for example “test.php” and add the content listed above.
Install the following prerequisites on your system :

sudo apt-get install php5-cli php5-curl

Launch the script like this :

php test.php

Note that I’ve justed tested it with 7.0.1 and to avoid a 404 on GET /bonita//API/identity/user
You should replace into the script :

$baseURL = ‘http://127.0.0.1:8080/bonita/’;

by

$baseURL = ‘http://127.0.0.1:8080/bonita’;

With that change it works well.

hi Jeremy, thanks for your reply , i can login with post method but i don’t know , how i can to try the other methods(GET,PUT,DELETE).Also i would like to know , how i start a process with php curl.

Thanks in advanced

Hi claz08,

In fact in this example there are POST and GET, through the usage of

curl_setopt($ch, CURLOPT_POST, 1);

and

curl_setopt($ch, CURLOPT_POST, 0);

because as you can see here http://php.net/manual/en/function.curl-setopt.php, GET is the default :

CURLOPT_HTTPGET TRUE to reset the HTTP request method to GET. Since GET is the default, this is only necessary if the request method has been changed.

For PUT and DELETE you can use CURLOPT_CUSTOMREQUEST :

CURLOPT_CUSTOMREQUEST
A custom request method to use instead of “GET” or “HEAD” when doing a HTTP request. This is useful for doing “DELETE” or other, more obscure HTTP requests. Valid values are things like “GET”, “POST”, “CONNECT” and so on; i.e. Do not enter a whole HTTP request line here. For instance, entering “GET /index.html HTTP/1.0\r\n\r\n” would be incorrect.

Note:
Don’t do this without making sure the server supports the custom request method first.

see http://php.net/manual/en/function.curl-setopt.php#96056

see http://php.net/manual/en/function.curl-setopt.php#97206

To create a case you can take a look here http://documentation.bonitasoft.com/bpm-api-1#case
You will have to perform a POST with the processDefinitionId.

hi jeremy!!, thanks for your response,but the last words you said not understood .
do you know , how i start a proces through an button in my webpage, and how i obtain the information of the user that login in my system, because now i’m using the following sintax:

curl_setopt($ch, CURLOPT_URL, $baseURL.'/API/identity/user/1

where “1” is the user with id=1
but i need, something like this:

curl_setopt($ch, CURLOPT_URL, $baseURL.'/API/identity/user/."$username".

i hope that you help me .

Thanks in advanced.

hi Jeremy,
can you reply me at the last question?

Thanks!

Hi claz08,

To start a process your button should perform a POST as explained in my previous message.

Or if you use Bonita BPM 7.0.0 and would like to start a process using an instantiation contract your POST should be done on “/API/bpm/process/processId/instantiation” like described into http://documentation.bonitasoft.com/bpm-api-1#process see “Start a process using an instantiation contract”.

To obtain the information of the user that is logged in you should perform a GET towards “API/system/session/unusedid”
You will receive a payload which contains user_id and user_name.
See http://documentation.bonitasoft.com/system-api-0#session for more details.

Kind regards,

Jérémy

Thanks for your answer,now i have some problem , when i try to create an user ,
i have managed to create an user using API REST, but wheni trying to login in my system , using this user recently created , i not could, also i not could to see this user in Bonita Portal but when i go to reviewed in the “user_” table from bonita database , if really the user has been created , i can see yes, so how i solve this problem?

Thanks in advanced.

Hi claz08,

It’s a good idea to have open a new thread for this new problem. I think that it improves the readability.
So I have answered directly into http://community.bonitasoft.com//answers/how-i-activate-user-recently-created-api-rest-and-php-curl

Kind regards,

Jérémy

Ok !