Departments

These are the REST endpoints to manage departments in ProcessMaker:

Get Departments List: GET /departments

Get a list of all the departments in the workspace, including departments with "INACTIVE" status.

GET /api/1.0/{workspace}/departments

URL Parameters:

Name Type Description
workspace String Workspace name

Result:

If successful, the HTTP status code is set to 200 and it returns a JSON array of department objects with the following structure:

Element Description Example
[ Start array.
{ Start department object
dep_uid, The department's unique ID. "11826545154db794ca22b52025081429"
dep_parent, The unique ID of the parent department. If this is a top-level deparment, then set to "" (empty string). ""
dep_title, The department's title. "Human Resources"
dep_status, The department's status, which can be "ACTIVE" or "INACTIVE". "ACTIVE"
dep_manager, The department's supervisor, to whom the other members of the department and the supervisors of the subdepartments report. By default, the supervisor is the first user assigned to the department. "14680180454ca4477335a27034362107"
dep_ldap_dn, The user's distinguished name if imported from LDAP. If a normal user whose account wasn't imported, then then set to "" (empty string). ""
dep_last, If the last department object in the current array, then set to 1. If not the last, then set to 0. 1
dep_manager_username, The username of the department's supervisor. "liliana"
dep_manager_firstname, The first name of the department's supervisor. "Liliana"
dep_manager_lastname, The last name of the department's supervisor. "Ortiz"
has_children, The number of subdepartments of this department. "2"
dep_children A array of subdepartment objects for this department. If there are no subdepartments, then an empty array. []
}, End the department object
{...} Any additional department objects.
] End array.

For example:

[
  {
    dep_uid:               "11826545154db794ca22b52025081429",
    dep_parent:            "",
    dep_title:             "Human  Resources",
    dep_status:            "ACTIVE",
    dep_manager:           "14680180454ca4477335a27034362107",
    dep_ldap_dn:           "",
    dep_last:              0,
    dep_manager_username:  "liliana",
    dep_manager_firstname: "Liliana",
    dep_manager_lastname:  "Ortiz",
    has_children:          "2",
    dep_children:
      [
        {
          dep_uid:              "54883398754db7993002ae1030708956",
          dep_parent:           "11826545154db794ca22b52025081429",
          dep_title:            "Crisis Management",
          dep_status:           "ACTIVE",
          dep_manager:          "91937880754ca444fc1e7b8079810120",
          dep_ldap_dn:          "",
          dep_last:             0,
          dep_manager_username: "sylvia",
          dep_manager_firstname:"Sylvia",
          dep_manager_lastname: "Herrero",
          has_children:         "0",
          dep_children:
            []
        },
        {
          dep_uid:               "98568611654e60da3ad38c3043219561",
          dep_parent:            "11826545154db794ca22b52025081429",
          dep_title:             "Employee Activities",
          dep_status:            "ACTIVE",
          dep_manager:           "66065213554dd1feb48fe79020620851",
          dep_ldap_dn:           "",
          dep_last:              1,
          dep_manager_username:  "johndoe",
          dep_manager_firstname: "John",
          dep_manager_lastname:  "Doe",
          has_children:          "0",
          dep_children:
            []
        }
      ]
  },
  {
    dep_uid:               "48474671254e60d7d9ac448055325161",
    dep_parent:            "",
    dep_title:             "Sales",
    dep_status:            "INACTIVE",
    dep_manager:           "00000000000000000000000000000001",
    dep_ldap_dn:           "",
    dep_last:              1,
    dep_manager_username:  "admin",
    dep_manager_firstname: "Administrator",
    dep_manager_lastname:  " ",
    has_children:          "0",
    dep_children:
      []
  }
]

PHP Example:

This example prints out the directory structure of an organization with the supervisor's name in parentheses.

    //recursive function to print department's name and supervisor's username: function printDeptArray($aDepts, $level)
    { foreach ($aDepts as $oDept) { //print spaces for the level of department: for ($ii = 0; $ii
    < $level;
        $ii++) { print "     "; } print "{$oDept->dep_title} ({$oDept->dep_manager_username})\n"; if ($oDept->has_children != 0) { printDeptArray($oDept->dep_children, $level + 1); } } } $apiServer = "https://example.com";
        //set to your ProcessMaker address $accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token']
        : getAccessToken(); $ch = curl_init($apiServer . "/api/1.0/workflow/departments"); curl_setopt($ch, CURLOPT_HTTPHEADER,
        array("Authorization: Bearer " . $accessToken)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $aDepts
        = json_decode(curl_exec($ch)); $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $aEmptyDepartments
        = array(); if ($statusCode != 200) { if (isset ($aDepts) and isset($aDepts->error)) print "Error code:
        {$aDepts->error->code}\nMessage: {$aDepts->error->message}\n"
; else print "Error: HTTP status code: $statusCode\n";
        } else { print "<pre>";   //only necessary if used in a web page
   printDeptArray($aDepts, 0);
   print "</pre>"; //only necessary if used in a web page }

For the departments shown in the example above, this script would print out:

Human Resources (liliana)
     Crisis Management (sylvia)
     Employee Activities (johndoe)
Sales (admin)

Get Department Information: GET /department/{dep_uid}

Get information about a specified department.

GET /api/1.0/{workspace}/department/{dep_uid}

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Department UID

Result:

If successful, the HTTP status code is 200 and a department object is returned like the GET departments endpoint, but it doesn't include the dep_children array. For example:

{
  dep_uid:               "54883398754db7993002ae1030708956",
  dep_parent:            "11826545154db794ca22b52025081429",
  dep_title:             "Crisis Management",
  dep_status:            "ACTIVE",
  dep_manager:           "91937880754ca444fc1e7b8079810120",
  dep_ldap_dn:           "",
  dep_last:              0,
  dep_manager_username:  "sylvia",
  dep_manager_firstname: "Sylvia",
  dep_manager_lastname:  "Herrero",
  has_children:          "0"
}

If unsuccessful, the HTTP status code is 400 or greater and a JSON error object is returned, such as:

{
  error: {
    code:    400,
    message: "Bad Request: The department with dep_uid: '54883398754db7993002ae1030708957' does not exist."
  }
}

PHP Example:

This example prints out the department's title and its supervisor's full name:

$apiServer = "https://example.com";              //set to your ProcessMaker address
$deptId    = "54883398754db7993002ae1030708956"; //set to a department's unique ID

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$ch = curl_init($apiServer . "/api/1.0/workflow/department/$deptId");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $accessToken));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$oDept = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($statusCode != 200) {
   if (isset ($oDept) and isset($oDept->error))
      print "Error code: {$oDept->error->code}\nMessage: {$oDept->error->message}\n";
   else
      print "Error: HTTP status code: $statusCode\n";
}
else {
   print "{$oDept->dep_title} Department supervisor: {$oDept->dep_manager_firstname} {$oDept->dep_manager_lastname}";
}

Create Department: POST /department

Create a new department.

Permission:

The logged-in user needs to have the PM_USERS permission in his/her role in order to be able to perform this action.

Structure:

POST /api/1.0/{workspace}/department

URL Parameters:

Name Type Description
workspace String Workspace name

POST Fields:

Name Type Description
dep_title String Department's title (name). Note that the department's title must be unique, so an error will occur if trying to create a department title which already exists.
dep_parent String Optional. Parent department's unique ID. If not included or set to "" (empty string), then this is a top-level department.
dep_manager String Optional. Department supervisor's unique ID. Users may only be assigned to ONE department, so the supervisor may NOT be a member of another department.
dep_status String Optional. Department status, which can be "ACTIVE" or "INACTIVE". If not included, then "ACTIVE" by default.

Result:

If the new department was created, the HTTP status code is 201 (Created) and a department object is returned, like the following:

{
  dep_uid:               "53126763454e62dc3284a75021962206",
  dep_parent:            "48474671254e60d7d9ac448055325161",
  dep_title:             "International Sales",
  dep_status:            "ACTIVE",
  dep_manager:           "61875549854e62c9c0bc823037974404",
  dep_ldap_dn:           "",
  dep_last:              0,
  dep_manager_username:  "kendrick",
  dep_manager_firstname: "Kendrick",
  dep_manager_lastname:  "Hillman",
  has_children:          "0"
}
Note: The dep_last element in the returned object is always set to 0 and is not correct. To check whether the new department is the last department at the current level, call the GET /departments or GET /department/{dep_uid} endpoint and check the value of the dep_last element.

If an error occurred, the HTTP status code is 400 or greater and an error object is returned, like the following:

{
  error: {
    code:    400,
    message: "Bad Request: The department with dep_parent: '48474671254e60d7d9ac448055325160' does not exist."
  }
}


PHP Example:

$apiServer = "https://example.com"; //set to your ProcessMaker address

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$postParams = array(
   'dep_title'   => 'International Sales',
   'dep_manager' => '61875549854e62c9c0bc823037974404',
   'dep_parent'  => '48474671254e60d7d9ac448055325161',
   'dep_status'  => 'ACTIVE'
);

$ch = curl_init($apiServer . "/api/1.0/workflow/department");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $accessToken"));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$oDept = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($statusCode == 201) {
   print "Department '{$oDept->dep_title}' created with UID: {$oDept->dep_uid}\n";
}
else {
   if (isset($oDept) and isset($oDept->error)) {
      print "Error in $apiServer: \nCode: {$oDept->error->code}\nMessage: {$oDept->error->message}\n";
   }
   else {
      print "Error: HTTP status code: $statusCode\n";
   }
}
curl_close($ch);

Update Department: PUT /department/{dep_uid}

Update the information about a department.

Permission:

The logged-in user needs to have the PM_USERS permission in his/her role in order to be able to perform this action.

Structure:

PUT /api/1.0/{workspace}/department/{dep_uid}

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Department UID.

Optional Fields:

Name Type Description
dep_title String The department title (name), which must be unique.
dep_parent String Unique ID of the parent department. Set to "" (empty string) to make a top-level department.
dep_manager String Unique ID of the department supervisor, to whom the members of the department [[1]], as well as the supervisors of subdepartments.
dep_status String Department status, which can be "ACTIVE" or "INACTIVE".

Result:

If the department was successfully updated, then the HTTP status code is set to 200 and there is no return object. Otherwise, it is set to 400 and greater and returns an error object, such as:

{
  error: {
    code:    400,
    message: "Bad Request: The user with dep_manager: '91937880754ca444fc1e7b8079810121' does not exist."
  }
}

PHP Example:

$apiServer = "https://example.com";            //set to your ProcessMaker address
$deptId = "75740355754dd28ba73d7d6082172937";  //set to the unique ID of a department

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$postParams = array(
   'dep_title'   => 'International Sales',
   'dep_manager' => '91937880754ca444fc1e7b8079810121',
   'dep_parent'  => '48474671254e60d7d9ac448055325161',
   'dep_status'  => 'INACTIVE'
);

$ch = curl_init($apiServer . "/api/1.0/workflow/department/" . $deptId);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $accessToken"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postParams));
$oResult = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($statusCode != 200) {
   if (isset($oResult) and isset($oResult->error))
      print "Error Code: {$oResult->error->code}\nMessage: {$oResult->error->message}\n";
   else
      print "Error: HTTP status code: $statusCode\n";
}
curl_close($ch);

Delete Department: DELETE /department/{dep_uid}

Delete a specified department. Note that it is not possible to delete a department while it has assigned users, so all the users must be unassigned from the department before deleting it.

Permission:

The logged-in user needs to have the PM_USERS permission in his/her role in order to be able to perform this action.

Structure:

DELETE /api/1.0/{workspace}/department/{dep_uid}

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Unique ID of the department to be deleted.

Result:

If the department was deleted, the HTTP status code is set to 200 and nothing is returned. Otherwise, it is set to 400 or greater and an error object is returned like the following:

{
  error: {
    code:    400,
    message: "Bad Request: Department cannot be deleted while has assigned users."
  }
}

PHP Example:

$apiServer = "https://example.com";              //set to your ProcessMaker address
$deptId   = "75740355754dd28ba73d7d6082172937";  //set to a department ID to delete it

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$ch = curl_init($apiServer . "/api/1.0/workflow/department/" . $deptId);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $accessToken"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$oResult = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($statusCode != 200) {
   if (isset($oResult) and isset($oResult->error))
      print "Error Code: {$oResult->error->code}\nMessage: {$oResult->error->message}\n";
   else
      print "Error: HTTP status code: $statusCode\n";
}
curl_close($ch);

Departments - Users:

Get Users List for Department: GET /department/{dep_uid}/assigned-user

Get a list of the users assigned to a specified department.

GET /api/1.0/{workspace}/department/{dep_uid}/assigned-user

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Unique ID of department.

Result:

If successful, the HTTP status code is 200 and an array of user objects is returned, like the following:

[
  {
    usr_uid:        "91937880754ca444fc1e7b8079810120",
    usr_username:   "sylvia",
    usr_firstname:  "Sylvia",
    usr_lastname:   "Herrero",
    usr_status:     "VACATION",
    usr_supervisor: true
  },
  {
    usr_uid:        "98883020754dd1f052ee1f1034403381",
    usr_username:   "janedoe",
    usr_firstname:  "Jane",
    usr_lastname:   "Doe",
    usr_status:     "ACTIVE",
    usr_supervisor: false
  }
]

PHP Example:

This example cycles through all the departments, looking for the username "janedoe" and prints out her department. First it calls the GET /departments endpoint to get a list of departments, then it calls the GET /department/{dep_uid}/assigned-user endpoint for each department and searches for the user.

//recursive function to search in the array of departments for a username in the list of members:
function searchInDepts($username, $aDepts) {
   global $apiServer, $accessToken;

   foreach ($aDepts as $oDept) {
      $ch = curl_init($apiServer . "/api/1.0/workflow/department/{$oDept->dep_uid}/assigned-user");
      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $accessToken"));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $aUsers = json_decode(curl_exec($ch));
      $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);

      if ($statusCode != 200) {
         if (isset($aUsers) and isset($aUsers->error))
            exit("Error Code: {$aUsers->error->code}\nMessage: {$aUsers->error->message}\n");
         else
            exit("Error: HTTP status code: $statusCode\n");
      }

      foreach ($aUsers as $oUser) {
         if ($oUser->usr_username == $username) {
            return $oDept;
         }
      }

      if ($oDept->has_children != 0) {
         $oRet = searchInDepts($username, $oDept->dep_children);
         if ($oRet)  //if username found, return the department object
            return $oRet;
      }
   }
   return null; //username not found
}

$apiServer = "shttp://example.com"; //set to your ProcessMaker address
$usernameToFind = "janedoe";        //set to a username to find

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$ch = curl_init($apiServer . "/api/1.0/workflow/departments");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $accessToken));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$aDepts = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($statusCode != 200) {
   if (isset ($aDepts) and isset($aDepts->error))
      exit("Error code: {$aDepts->error->code}\nMessage: {$aDepts->error->message}\n");
   else
      exit("Error: HTTP status code: $statusCode\n");
}
else {
   $oDeptFound = searchInDepts($usernameToFind, $aDepts);
   if ($oDeptFound)
      print "User '$usernameToFind' is a member of the {$oDeptFound->dep_title} Department.\n";
   else
      print "User '$usernameToFind' is not a member of any department.\n";
}

Available Users List for Department: GET /department/{dep_uid}/available-user

Get a list of the available users, which can be assigned to a specified department. The list contains all users which aren't yet assigned to any department (including users which have "INACTIVE" and "VACATION" status).

GET /api/1.0/{workspace}/department/{dep_uid}/available-user

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Unique ID of department.

Result:

If successful, the HTTP status code is set to 200 and it returns an array of user objects, like the following:

[
  {
    usr_uid:       "43239845654e76a70ccb5a1012787498",
    usr_username:  "sally",
    usr_firstname: "Sally",
    usr_lastname:  "Slim",
    usr_status:    "INACTIVE"
  },
  {
    usr_uid:       "66065213554dd1feb48fe79020620851",
    usr_username:  "johndoe",
    usr_firstname: "John",
    usr_lastname:  "Doe",
    usr_status:    "ACTIVE"
  }
]

Note that the user objects are not arranged in any particular order.

If an error occurred, the HTTP status code is set to 400 or greater, and an error object is returned, such as:

{
  error: {
    code:    400,
    message: "Bad Request: The department with dep_uid: '54883398754db7993002ae1030708955' does not exist."
  }
}

PHP Example:

Get a list of available users and sort them in alphabetical order according to their full names and print them. All the user objects are placed in the $aUsersWithKeys array which has the full names as the keys and then they are sorted using the ksort() function.

$apiServer = "https://example.com";              //set to your ProcessMaker address
$deptId    = "54883398754db7993002ae1030708956"; //set to a department's unique ID

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$ch = curl_init($apiServer . "/api/1.0/workflow/department/$deptId/available-user");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $accessToken));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$aUsers = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($statusCode != 200) {
   if (isset ($oDept) and isset($oDept->error))
      print "Error code: {$oDept->error->code}\nMessage: {$oDept->error->message}\n";
   else
      print "Error: HTTP status code: $statusCode\n";
}
else {
   $aUsersWithKeys = array();
   foreach ($aUsers as $oUser) {
      $fullname = $oUser->usr_firstname . ' ' . $oUser->usr_lastname . ' (' . $oUser->username . ')';
      $aUsersWithKeys[$fullname] = $oUser;
   }
   ksort($aUsersWithKeys, SORT_NATURAL | SORT_FLAG_CASE));

   foreach ($aUsersWithKeys as $oUser) {
      print $oUser->usr_firstname . ' ' . $oUser->usr_lastname . ' (' . $oUser->username . ")\n";
   }
}

Assign User to Department: POST /department/{dep_uid}/assign-user

Assign a user to a specified department. If the user is already a member of another department, the user will be transfered to the specified department. If reassigning a user who is a supervisor of another department, see this bug.

Permission:

The logged-in user needs to have the PM_USERS permission in his/her role in order to be able to perform this action.

Structure:

POST /api/1.0/{workspace}/department/{dep_uid}/assign-user

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Unique ID of department.

POST Fields:

Name Type Description
usr_uid String Unique ID of a user to assign to the department.

Result:

If the user was assigned to the department, the HTTP status code is 201 and there is no return object. Otherwise, the HTTP status code is 300 or greater and there is a return object such as:

{
  error: {
    code:    400,
    message: "Bad Request: The user with usr_uid: '43239845654e76a70ccb5a1012787499' does not exist."
  }
}

PHP Example:

$oToken = pmRestLogin("IAIERTORPBHIJZXEPNSUANXLKYPKODJU", "71308091055cb7094026089092397336", "amos", "p4sSw0rD");

$userId = '55625662755e0e42fe83f41018778834';
$deptId = '49874200755e894791651c7054311031';

$aVars = array(
   'usr_uid' => $userId
);

$url = "/api/1.0/workflow/department/$deptId/assign-user";
$oRet = pmRestRequest("POST", $url, $aVars, $oToken->access_token);

if ($oRet->status == 200) {
   print "User $userId added to the Accounting Department.\n";
}

Unassign User from Department: DELETE /department/{dep_uid}/unassign-user/{usr_uid}

Unassign a user from a department, so no longer a member of the department. If unassigning a supervisor from a department, see this bug.

Permission:

The logged-in user needs to have the PM_USERS permission in his/her role in order to be able to perform this action.

Structure:

DELETE /api/1.0/{workspace}/department/{dep_uid}/unassign-user/{usr_uid}

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Unique ID of department.
usr_uid String Unique ID of the user to unassign from the department.

Result:

If the user was unassigned from the department, the HTTP status code is 200 and there is no return object. Otherwise, the HTTP status code is 400 or greater and there is a return object such as:

{
  error: {
    code:    400,
    message: "Bad Request: The user with usr_uid: '43239845654e76a70ccb5a1012787499' does not exist."
  }
}


PHP Example:

$apiServer = "https://example.com";            //set to your ProcessMaker address
$deptId = "75740355754dd28ba73d7d6082172937";  //set to the unique ID of a department
$userId = "14680180454ca4477335a27034362107";  //set to unique ID of user to remove from department

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$postParams = array('usr_uid' => $userId);

$ch = curl_init($apiServer . "/api/1.0/workflow/department/$deptId/unassign-user/$userId");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $accessToken"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$oResult = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($statusCode != 200) {
   if isset($oResult) and isset($oResult->error)) {
      print "Error Code: {$oResult->error->code}\nMessage: {$oResult->error->message}\n";
   }
   else {
      print "Error: HTTP status code $statusCode\n";
   }
}
curl_close($ch);

Set Manager for Department: PUT /department/{dep_uid}/set-manager/{usr_uid}

Set a user to be the manager (supervisor) for a department. The other members of the department will report to the manager, as well as the managers of subdepartments. Note that this endpoint has a number of outstanding bugs.

Permission:

The logged-in user needs to have the PM_USERS permission in his/her role in order to be able to perform this action.

Structure:

PUT /api/1.0/{workspace}/department/{dep_uid}/set-manager/{usr_uid}

URL Parameters:

Name Type Description
workspace String Workspace name
dep_uid String Unique ID of the department.
usr_uid String Unique ID of the user to become the the manager of the department.

Result:

If the manager was successfully set, then the HTTP status code is 200 and there is no return object. Otherwise, the HTTP status code is 400 or greater and an error object is returned, like the following:

{
  error: {
    code:    400,
    message: "Bad Request: The user with usr_uid: '43239845654e76a70ccb5a1012787499' does not exist."
  }
}

PHP Example:

$apiServer = "https://example.com";            //set to your ProcessMaker address
$deptId = "75740355754dd28ba73d7d6082172937";  //set to the unique ID of a department
$userId = "14680180454ca4477335a27034362107";  //set to unique ID of user to become supervisor

$accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();

$postParams = array('usr_uid' => $userId);

$ch = curl_init($apiServer . "/api/1.0/workflow/department/$deptId/set-manager/$userId");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $accessToken"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$oResult = json_decode(curl_exec($ch));
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($statusCode != 200) {
   if isset($oResult) and isset($oResult->error)) {
      print "Error Code: {$oResult->error->code}\nMessage: {$oResult->error->message}\n";
   }
   else {
      print "Error: HTTP status code $statusCode\n";
   }
}
curl_close($ch);