Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: ArturoRobles

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
User avatar
By RicardoMG
At the moment processmaker can not return all cases, but you can review what you can do REST API Cases - cases in this link:
An example similar to what you were asking was made.
First I got the token using Postman, see the attached images.
You must take into account that to obtain the token you first have to Registering an External Application to Use REST, you have to follow this steps:

Then you will have the client_id and client_secret, use that data with a user registered in processmaker to obtain the token.

Now i am going to perform using a trigger to get the number of cases started in processmaker, this is the code in the trigger:
Code: Select all
$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
    //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");
        case "DELETE":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
        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));
            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);
    if ($oRet->status == 401) { //if session has expired or bad login:
        header("Location: ./../login/login"); //change to match your login method
    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;
$oRet = $pmRestRequest('GET', "",'/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;
In the variable @@number obtaining the number of the cases started.

It should be noted that I only get the number of cases initiated by the user with which the token was obtained, in my case the user is "admin"

I hope this information helps you
image1.PNG (54.15 KiB) Viewed 1859 times
image2.PNG (44.94 KiB) Viewed 1859 times
image3.PNG (117.88 KiB) Viewed 1860 times
PM generating absolute URL

Hi, Please delete all files in this path and test […]

Hi, You must upgrade your program to version 3.5.8[…]

Hi, Please check this link for your problem: http[…]

Enabling SQL Server in Windows

panties very nice work here panties