Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
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.
#814571
I'm using the REST API to upload documents to any process. It works great for some processes but this morning, I tried to upload the same document to any of the 3 input documents (every extension is allowed) of my process but I always get this error:

Error code: 400 Message: Bad Request: The user is supervisor, but it does not have an associated input document\n400

I have a processmaker account with the role 'ADMIN' and I'm supervisor of every process with all accesses. I don,t see it in the documentation of REST API or Error Messages from REST
#814586
First use POST /light/case/{app_uid}/upload to create a Case Document record in the APP_DOCUMENT table. Set appDocType to be "ATTACHED".

Then, call POST /light/case/{app_uid}/upload/{app_doc_uid} to upload the file. Sorry, there is no documentation for this endpoint, but I will prepare a code example for you tomorrow.
#814699
Everything works great but I'm trying to get the oResponse json that is returned. It's NULL when I use json_decode(curl_exec($ch)) because:

Undefined index: usr_uid in /opt/processmaker/workflow/engine/plugins/extraRest/src/Services/Api/ExtraRest/Extra.php on line 1003
Undefined variable: loggedUserUid in /opt/processmaker/workflow/engine/plugins/extraRest/src/Services/Api/ExtraRest/Extra.php on line 1003

I use the same access Token that I used to connect to the processmaker REST API. Is there another way to connect to extrarest that I don,t know ?

Edit: I found a fix to the problem by doing this:
Code: Select all
$oResponse = curl_exec($ch);
$start = strpos($oResponse,'{');
$end = strpos($oResponse,'}');
$length = $end - $start;
$oResponse = substr($oResponse,$start,$length+1);
$oResponse = json_decode($oResponse);
I know it's awful to parse the string like that but for now, it'll have to do until I get an answer :)
#814700
I'm not sure why you get an undefined index in the array. Let's change /opt/processmaker/workflow/engine/plugins/extraRest/src/Services/Api/ExtraRest/Extra.php, line 1003 from:
Code: Select all
                     if ($aSupervisorInfo['usr_uid'] == $loggedUserUid) {
To:
Code: Select all
                     if (isset($aSupervisorInfo['usr_uid']) and $aSupervisorInfo['usr_uid'] == $userUid) {
I have uploaded a new version 1.6 of the plugin with this change which you can install or you can directly edit the source code.
#814715
Thanks, slightly better now.

I had this error:
Message: Bad Request: Logged-in user '37424258059493e06d7fbe3022197180' must be assigned to task of delegation index 21 or be a Supervisor for process '6794906935aba325fda6e06063066799'.

I was in the 'Developpers' group which is Supervisor of the process. The only way I made it work was to assign my account to supervisor of each process (doesn't work if the group is supervisor, my account must be supervisor of the process)
#827446
I am also facing the same issue, i.e the value of $oResponse is null.

I am trying to upload single/multiple files using react.

But when I call my php file which uploads input document in processmaker.
I get the value of $httpStatus as 0. And the files are not uploaded.
Code: Select all
<?php
$inputDocId = '2699784865e2155c3e04a43081494049';
$taskId     = '6255531755e0dff921e5466035447157';
$caseId     = '2992109955e26871503f671072958707';
$url        = "http://workflow.rest.com:8805/api/1.0/workflow/cases/$caseId/input-document";
$nFiles = count($_FILES['file']['name']);
$access_token = '3a21f7a2e052d1ad31a91fb24deb50da8a5d9196';


for ($i = 0; $i < $nFiles; $i++) {
   $path = $_FILES['file']['tmp_name'][$i];
   $type = $_FILES['file']['type'][$i];
   $filename = $_FILES['file']['name'][$i];
   //rename file from temp name to real name:
   rename($path, sys_get_temp_dir() .'/'. $filename); //reverse \ for windows systems

   $aVars = array(
      'inp_doc_uid'     => $inputDocId,
      'tas_uid'         => $taskId,
      'app_doc_comment' => '',
      'form'            => (phpversion() >= "5.5") ? new CurlFile($path, $type) : '@'.$path
   );


   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $access_token));
   curl_setopt($ch, CURLOPT_POSTFIELDS, $aVars);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $oResponse = json_decode(curl_exec($ch)); // returns null in my case.
   $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
   curl_close($ch);
//    unlink(sys_get_temp_dir() .'/'. $filename); //delete file

    if ($httpStatus == 200) {
        print "File ". $oResponse->app_doc_uid ." uploaded.\n";
    }
    elseif (is_object($oResponse) and isset($oResponse->error)) {
        print "Error code: {$oResponse->error->code}\n" .
            "Message: {$oResponse->error->message}\n";
    }
    else {
        print "Error code: $httpStatus";
    }

}
?>
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]