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-applic....
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
Hello,
Please find bellow an example using PHP cURL :
$username = 'install';
$password = 'install';
$baseURL = 'http://127.0.0.1:8080/bonita/';function preparePostFields($array) { //from http://stackoverflow.com/a/5224895
$params = array();
foreach ($array as $key => $value) {
$params[] = $key . '=' . urlencode($value);
}
return implode('&', $params);
}$ch = curl_init();
//connect
$data = array('username' => $username, 'password' => $password, 'redirect' => 'false');
curl_setopt($ch, CURLOPT_URL, $baseURL.'/loginservice');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, preparePostFields($data));
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);//get list of users
curl_setopt($ch, CURLOPT_URL, $baseURL.'/API/identity/user?p=0&c=10&o=lastname%20ASC&f=enabled%3dtrue');
curl_setopt($ch, CURLOPT_POST, 0);
$content = curl_exec($ch);
echo $content;curl_close($ch);
?>
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
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
Comments
Sahil,
May be this is useful for you...
http://community.bonitasoft.com/answers/how-use-bonitasoft-rest-api-pyth...
Comments
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 :
Launch the script like this :
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 :
by
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
and
because as you can see here http://php.net/manual/en/function.curl-setopt.php, GET is the default :
For PUT and DELETE you can use 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:
where "1" is the user with id=1 but i need, something like this:
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-cr...
Kind regards,
Jérémy
Ok !