Trying to pull variables via API call

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.
Throwaway
Posts: 44
Joined: Wed Apr 26, 2017 11:40 am
Country: Ukraine

Trying to pull variables via API call

Unread postby Throwaway » Wed Dec 06, 2017 4:37 pm

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,

amosbatto
Posts: 5566
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: Trying to pull variables via API call

Unread postby amosbatto » Wed Dec 06, 2017 9:14 pm

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?
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

Throwaway
Posts: 44
Joined: Wed Apr 26, 2017 11:40 am
Country: Ukraine

Re: Trying to pull variables via API call

Unread postby Throwaway » Thu Dec 07, 2017 12:03 am

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

dconorozzo
Posts: 5
Joined: Fri Dec 08, 2017 4:03 pm
Country: United States of America

Re: Trying to pull variables via API call

Unread postby dconorozzo » Fri Dec 08, 2017 6:58 pm

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...

amosbatto
Posts: 5566
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: Trying to pull variables via API call

Unread postby amosbatto » Tue Dec 12, 2017 2:22 am

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.
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)


Return to “Developing processes & programming”

Who is online

Users browsing this forum: No registered users and 1 guest