Error: Authenticating external requests to bpm'online web-services
Hi guys:
I have problem when call authentication service (AuthService.svc) from other Server with PHP.The call return a new login form (with user and pass) instead of the creation of cookie auth.
Please your help... Thanks a lot
Manuel
The code is:
$url = "http://***:82/0/ServiceModel/AuthService.svc/Login";
$post = "UserName=***r&UserPassword=***";
print_r($url);
print_r($post );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Like
Try this.
<?php
// Auth
$url = 'https://some-site.bpmonline.com/ServiceModel/AuthService.svc/Login';
$requestData["UserName"] = "MyLogin";
$requestData["UserPassword"] = "MyPass";
$jcres = json_encode($requestData);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jcres);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($jcres))
);
$result = curl_exec($ch);
curl_close($ch);
// Call something
$urlGetCardInfo = 'https://some-site.bpmonline.com/0/ServiceModel/EntityDataService.svc/Le…';
$ch = curl_init($urlGetCardInfo);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo "";
echo var_dump($result);
?>
Dear Manuel,
We do not provide support regarding PHP scripts, since the main two programming languages used in bpm'online are JavaScript and C#. However, please see the example below. which can help you call the authentication service from external resources:
<?php // Auth $url = 'https://demo.bpmonline.com/ServiceModel/AuthService.svc/Login'; $requestData["UserName"] = "Login"; $requestData["UserPassword"] = "password"; $jcres = json_encode($requestData); $ch = curl_init($url); curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $jcres); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($jcres)) ); $result = curl_exec($ch); curl_close($ch); // Call something $urlGetCardInfo = 'https://demo.bpmonline.com/0/ServiceModel/EntityDataService.svc/LeadCollection?$select='; $ch = curl_init($urlGetCardInfo); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); echo ""; echo var_dump($result); ?>
Also, here is a supporting matterial regarding external requests to bpm'online:
Have a nice day!
{"Code":0,"Message":"","Exception":null,"PasswordChangeUrl":null,"RedirectUrl":null} is returned for success, and the cookies are created. It does seem a success message should be created, instead of an empty string. very miss leading. I got these results using postman.
I'm working on classings to connect to bpm'online. One of those classes I developed in PHP.
I have published a repository on Github with the source code.
https://github.com/idevol/bpmonline-dataservice-connectors