- Tue Jun 11, 2019 1:45 pm
#824837
Dear Amos,
I can call REST endpoints of processmaker for itself without any problem.( Existing Access Token Inside ProcessMaker ). However, there are some problems when I want to call REST endpoints for external applications. I explain whatever I did:
1) I registered the external application, and PM gave me Client ID and Client Secret.
2) For calling pmRestLogin() from a Web Page, I used the following code and copied them to loginForm.php. (the loginForm.php has been placed in my wamp: localhost/example/loginForm.php)
I would be very grateful if you could help me to solve it.
Best Regards
I can call REST endpoints of processmaker for itself without any problem.( Existing Access Token Inside ProcessMaker ). However, there are some problems when I want to call REST endpoints for external applications. I explain whatever I did:
1) I registered the external application, and PM gave me Client ID and Client Secret.
2) For calling pmRestLogin() from a Web Page, I used the following code and copied them to loginForm.php. (the loginForm.php has been placed in my wamp: localhost/example/loginForm.php)
Code: Select all
3) In the login.php file, placed following code to call the pmRestLogin() function ( There are some syntax errors in https://wiki.processmaker.com/3.1/OAuth ... a_web_page, and you can correct them, if you find some time)
<html>
<body>
<?php //print error message if any from previous login attempt:
if (isset($_GET['error']))
print "<p><font color=red>{$_GET['error']}</font></p>\n";
?>
<form action="login.php" method="post">
Client ID<br>
<input type="text" name="client_id" value="" width=32 /><br>
Client Secret<br>
<input type="text" name="client_secret" value="" width=32 /><br>
Username<br>
<input type="text" name="username" value="" width=20 /><br>
Password<br>
<input type="text" name="password" value="" width=20 /><br>
<input type="submit" value="Login"/>
</form>
</body>
</html>
Code: Select all
4) When I am going to run my wamp address (localhost/example/loginForm.php), after entering Client Id, client Secret, username and password, and submitting the form, I see this fatal error: Call to undefined function pmRestLogin() in D:\wamp64\www\example\login.php on line 16<?php
$error = "";
if (!isset($_POST['client_id'])){
$error = "No credentials POSTed to access ProcessMaker REST.";
} elseif ($_POST['client_id'] == "" or $_POST['client_secret'] == "") {
$error = "No client ID or secret specified to get authorization from ProcessMaker OAuth.";
}elseif ($_POST['username'] == "" or $_POST['password'] == ""){
$error = "No username or password specified to login to ProcessMaker.";
}
if ($error) {
header('location: loginForm.php?error=' . urlencode($error)); //pass error so login screen can display it to user.
die();
}
$oToken = pmRestLogin($_POST['client_id'], $_POST['client_secret'], $_POST['username'], $_POST['password']);
if (isset($oToken) and isset($oToken->access_token)) {
//can now call REST endpoints using $oToken->access_token
$oRet = pmRestRequest("POST", "/api/1.0/workflow/group", null, $oToken->access_token);
$apiServer = "http://localhost:67";
$postParams = array(
'grp_title' => "My group",
'grp_status' => "ACTIVE"
);
$ch = curl_init($apiServer . "/api/1.0/workflow/group");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $oToken "));
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$oGroup = json_decode(curl_exec($ch));
if (!isset($oGroup)) {
print "Error accessing $apiServer: \n" . curl_error($ch);
}
elseif (isset($oGroup->error)) {
print "Error in $apiServer: \nCode: {$oGroup->error->code}\nMessage: {$oGroup->error->message}\n";
}
else {
print "Group '{$oGroup->grp_title}' created with UID: {$oGroup->grp_uid}\n";
}
curl_close($ch);
}
I would be very grateful if you could help me to solve it.
Best Regards