Total cases using REST
Posted: Thu Mar 26, 2020 7:17 am
I want to get total number of created cases using REST service.
How can I get this?
How can I get this?
workflow simplified
https://forum.processmaker.com/
$pmRestRequest = function ($method, $pmServer, $endpoint, $aVars = null, $accessToken = null) {
echo ($pmServer.$endpoint);
if (empty($accessToken) and isset($_COOKIE['access_token']))
$accessToken = $_COOKIE['access_token'];
if (empty($accessToken)) { //if the access token has expired
//To check if the PM login session has expired: !isset($_COOKIE['PHPSESSID'])
header("Location: ./../login/login"); //change to match your login method
die();
}
//add beginning / to endpoint if it doesn't exist:
if (!empty($endpoint) and $endpoint[0] != "/")
$endpoint = "/" . $endpoint;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pmServer . $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $accessToken));
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$method = strtoupper($method);
switch ($method) {
case "GET":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
break;
case "DELETE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
case "POST":
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aVars));
break;
default:
throw new Exception("Error: Invalid HTTP method '$method' $endpoint");
return null;
}
$ret = curl_exec($ch);
$oRet = new StdClass;
$oRet->response = json_decode($ret);
$oRet->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($oRet->status == 401) { //if session has expired or bad login:
header("Location: ./../login/login"); //change to match your login method
die();
}
elseif ($oRet->status != 200 and $oRet->status != 201) { //if error
if ($oRet->response and isset($oRet->response->error)) {
print "Error in $pmServer:\nCode: {$oRet->response->error->code}\n" .
"Message: {$oRet->response->error->message}\n";
}
else {
print "Error: HTTP status code: $oRet->status\n";
}
}
return $oRet;
};
$cases=1;
$token="7ee4ff6dcadd345b07349e92c12e087bb849d27d";
$oRet = $pmRestRequest('GET', "http://192.168.0.109:8080",'/api/1.0/workflow/case/start-cases', null, $token);
if ($oRet and $oRet->status == 200) {
foreach ($oRet->response as $oUser) {
$cases = $cases + 1;
print "{$oUser->usr_firstname} {$oUser->usr_lastname} ({$oUser->usr_username})\n";
}
@@number = $cases;
}