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

Moderator: amosbatto

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.
By Throwaway
#812452
Hello,


I am getting a "401 unauthorized response" when trying to pull variables with an API call. It's successfully grabbing the access token and It works successfully on other processes, but for some reason, it doesn't work for admin or regular users on one particular process and the data being sent is all correct, it just won't grab the variables. Any ideas? :?:


Best regards,
By amosbatto
#812456
Which REST endpoint are you using? There are several to get variables.
Are you passing the access token in the header of the REST call?
Can you provide your code or screen shots if you are using postman or httprequester?
Is the logged-in user assigned to the current task in the case?
By Throwaway
#812466
amosbatto wrote:Which REST endpoint are you using? There are several to get variables.
We are using GET, but it works in every process besides one. Could there be some sort of permission/oauth issue that we are missing?
amosbatto wrote:Are you passing the access token in the header of the REST call?

Yep
amosbatto wrote:Is the logged-in user assigned to the current task in the case?
Yes, the logged in user is logged in when submitting the task into a script.
amosbatto wrote:Can you provide your code or screen shots if you are using postman or httprequester?
I wouldn't know what specifically to send as there is so much, but I can try to give more insight.

It's failing in /opt/processmaker_workflow/workflow/engine/src/ProcessMaker/Services/Api/Cases.php in the __isAllowed function, specifically ln 55:

return $oCases->checkUserHasPermissionsOrSupervisor($userUid, $applicationUid, $dynaformUid);

it's returning empty to this process and returns 1 (true) for the other processes where it works fine getting the variables. It fails when retrieving the app id
#812489
I don't think you answered what was being looked for as the endpoint. Were you using Process Variables Endpoints or Case Variables Endpoints or something else? What was the call? Was it GET /cases/{app_uid}/variables or GET project/{prj_uid}/process-variables or something else? The documentation at: http://wiki.processmaker.com/3.1/developer_info under the REST tab is broken down into 3 areas and under those areas there are subareas and items in there are specifically referred to as Endpoints. I think that is what amosbatto was asking for. Anyway, you could try going into your process design and adding the user you have logged in as through REST as a supervisor and see if that changes anything, as a starting point...
By amosbatto
#812514
Throwaway,
I finally got around to testing the endpoint GET /cases/{app_uid}/variables

Here is what I found:
1. The endpoint GET /cases/{app_uid}/variables can be called without any problems if 1) the user who logins in with REST has been assigned to a completed or current task in the case or 2) the logged-in user is assigned as a process supervisor to the process.

2. If the user who logins in with REST has process permissions to view a task in the case, then specify the ID of a DynaForm which is a step in that task:
GET /cases/{app_uid}/variables?dyn_uid={dyn_uid}

For example:
Code: Select all
    $caseId     = '3540246925a2f65f53a60f8083269189';
    $dynaformId = '8675766055a03a97145b0c4022233429';
    $url = "/api/1.0/workflow/cases/$caseId/variables?dyn_uid=$dynaformId";

    $oRet = pmRestRequest("GET", $url, null, $oToken->access_token);
    if (isset($oRet) and isset($oRet->status) and $oRet->status == 200) {
        $address = isset($oRet->response->address) ? $oRet->response->address : ''; 
    }
 
Note: Using Process Permissions will only work if the case is currently in the task with the specified DynaForm. To get around this problem, set the Target Task to "All Tasks" in the properties of the Process Permissions.

It is working. Thanks a lot.

Hi, I saw an old topic in this forum with this err[…]

Grid, difference between 2 dates

Hello, You could use this code instead of yours: […]

hello, I have one dynaform with grid. In grid the[…]