--- title: "PHP" slug: "php" updated: 2025-10-21T03:01:58Z published: 2025-10-21T03:01:58Z canonical: "docs.processmaker.com/php" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.processmaker.com/llms.txt > Use this file to discover all available pages before exploring further. # PHP PHP codes to insert in Script tasks. **Environment Variables** Environment variables store configuration values and sensitive information for processes. #### Get Environment Variables This example demonstrates how to get all environment variables of your ProcessMaker instance. **Example** ```php environmentVariables(); // Call the getEnvironmentVariables() method to retrieve a list of environment variables $result = $apiInstance->getEnvironmentVariables(); // Initialize an array to store the environment variable details $envVars = []; // Iterate over each environment variable in the result foreach ($result->getData() as $envVar) {    // Extract the name and description of the environment variable    $envVars[] = [        'name' => $envVar->getName(),        'description' => $envVar->getDescription(),    ]; } // Return all the environment variables return ['environmentVariables' => $envVars]; ?> ``` #### Get Environment Variable by ID This example illustrates how to retrieve a specific environment variable by its ID. **Example** ```php environmentVariables(); // Retrieve environment variable with ID 4 $envVar = $apiInstance->getEnvironmentVariableById(4); // Return the name and description of the environment variable return [    'name' => $envVar->getName(),    'description' => $envVar->getDescription(), ]; ?> ``` #### Create a Environment Variable This example demonstrates how to create a new environment variable. **Example** ```php environmentVariables(); // Create a new editable environment variable object $environment_variable_editable = new \ProcessMaker\Client\Model\EnvironmentVariableEditable(); // Define the name of your environment  variable $environment_variable_editable->setName('myNewVariable'); // Define the description of your environment variable $environment_variable_editable->setDescription('My global variable'); // Set the value for your new environment variable $environment_variable_editable->setValue('12345'); // Create the environment variable using the API $newEnvVar = $apiInstance->createEnvironmentVariable($environment_variable_editable); // Return the ID of the newly created environment variable return ['newEnvVarId' => $newEnvVar->getId()]; ?> ``` #### Update Environment Variable This example showcases how to update an existing environment variable. **Example** ```php environmentVariables(); // Retrieve the environment variable with ID 10 $envVar = $apiInstance->getEnvironmentVariableById(10); // Update the properties of the environment variable $envVar->setName('myVariable'); // Set a new name for the environment variable $envVar->setDescription('My updated variable'); // Update the description of the environment variable $envVar->setValue('123456'); // Update the value of the environment variable // Call the updateEnvironmentVariable() method to update the environment variable $apiInstance->updateEnvironmentVariable(    $envVar->getId(),    $envVar ); // If no errors are thrown, the environment variable was successfully updated return ['success' => true]; ?> ``` #### Delete Environment Variable This example demonstrates how to delete an existing environment variable. **Example** ```php environmentVariables(); // Delete the environment variable with ID 10 $apiInstance->deleteEnvironmentVariable(10); // The environment variable is successfully deleted return ['success' => true]; ?> ``` **Files** Files can be associated with different processes in the ProcessMaker platform and contain relevant information or attachments. #### Get Files This example demonstrates how to retrieve all the list of files inside the instance. **Example** ```php files(); $files = []; // Retrieve all files in the system $result = $apiInstance->getFiles(); // Iterate over each file and extract its details foreach ($result->getData() as $file) {    $files[] = [        'id' => $file->getId(),        'file_name' => $file->getFileName(),        'model_type' => $file->getModelType(),        'model_id' => $file->getModelId(),        // Variable name in the request data        'data_name' => $file->getCustomProperties()['data_name'],    ]; } // Return the list of files return ['files', $files]; ?> ``` #### Get File This example demonstrates how to retrieve information about a specific file in the ProcessMaker instance. **Example** ```php files(); $fileId = 1; // ID of the file to retrieve information for $file = $apiInstance->getFileById($fileId); return [    'file' => [        'file_name' => $file->getFileName(),        'model_type' => $file->getModelType(),        'model_id' => $file->getModelId(),        'data_name' => $file->getCustomProperties()['data_name'],    ], ]; ?> ``` **Groups** A group is a logical collection of users with similar roles, responsibilities, or permissions within an organization. It provides a convenient way to organize and manage users based on common attributes. By grouping users together, administrators can efficiently assign access rights, permissions, and privileges to multiple users simultaneously. This simplifies user management, enhances security, and improves overall administrative efficiency. #### Get Groups This example demonstrates how to retrieve information about all the groups in the ProcessMaker instance. **Example** ```php groups(); $groups = []; // Retrieve all groups $result = $apiInstance->getGroups(); // Iterate over each group and extract its details foreach ($result->getData() as $group) {    $groups[] = [        'id' => $group->getId(),        'name' => $group->getName(),        'description' => $group->getDescription(),        'status' => $group->getStatus()    ]; } // Optional: Filter and sort groups with additional arguments $status = 'ACTIVE'; $filter = 'designers'; $order_by = 'name'; $order_direction = 'asc'; $per_page = 10; $include = ''; $result = $apiInstance->getGroups($status, $filter, $order_by, $order_direction, $per_page, $include); // Iterate over the filtered and sorted groups to extract their details foreach ($result->getData() as $group) {    $groups[] = [        'id' => $group->getId(),        'name' => $group->getName(),        'description' => $group->getDescription(),        'status' => $group->getStatus()    ]; } // Return the list of groups return ['groups', $groups]; ?> ``` #### Get All Users in a Group This example demonstrates how to retrieve information about all users belonging to a specific group. **Example** ```php groups(); $users = []; $groupId = 5; // ID of the group to retrieve users from // Retrieve users belonging to the specified group $result = $apiInstance->getGroupUsers($groupId); // Iterate over each user and extract their details foreach ($result->getData() as $user) {    $users[] = [        'id' => $user->getId(),        'name' => $user->getUsername(),        'email' => $user->getEmail(),        'status' => $user->getStatus(),    ]; } // Return the list of users in the group return ['usersInGroup' => $users]; ?> ``` #### Get Group This example demonstrates how to retrieve information about a specific group. **Example** ```php groups(); $groupId = 2; // ID of the group to retrieve information for $group = $apiInstance->getGroupById($groupId); // Return the Name, Description, and Status of the group return [    'group' => [        'name' => $group->getName(),        'description' => $group->getDescription(),        'status' => $group->getStatus(),    ], ]; ?> ``` #### Create Group This example demonstrates how to create a new group in the ProcessMaker instance. **Example** ```php groups(); // Create a new editable group object $group = new \ProcessMaker\Client\Model\GroupsEditable(); $group->setName("New group"); $group->setDescription("New group description"); $group->setStatus("ACTIVE"); // Create the group using the API $newGroup = $apiInstance->createGroup($group); // Return the ID of the newly created group return ['newGroupId' => $newGroup->getId()]; ?> ``` #### Update Group This example demonstrates how to update an existing group in the ProcessMaker instance. **Example** ```php groups(); $groupId = 9; // ID of the group to update $group = $apiInstance->getGroupById($groupId); $group->setName("Updated group name"); // Update the name of the group $group->setDescription("Updated group description"); // Update the description of the group $group->setStatus("INACTIVE"); // Update the status of the group $apiInstance->updateGroup($groupId, $group); // If no errors are thrown, the group was successfully updated return ['success' => true]; ?> ``` #### Delete Group This example demonstrates how to delete an existing group in the ProcessMaker instance. **Example** ```php groups(); $groupId = 9; // ID of the group to delete $apiInstance->deleteGroup($groupId); // If no errors are thrown, the group was successfully deleted return ['success' => true]; ?> ``` **Process Categories** Process categories are an essential organizational tool that enables the grouping of processes based on specific criteria or common characteristics. They offer a convenient and efficient method to structure and manage processes within the ProcessMaker platform. This categorization system enhances overall process organization, providing users with an intuitive way to locate and access relevant processes efficiently. #### Get Process Categories This example demonstrates how to retrieve information about all process categories in your ProcessMaker instance. **Example** ```php processCategories(); $processCategories = []; $result = $apiInstance->getProcessCategories(); // Iterate over each process category and extract its details foreach($result->getData() as $processCategory) {    $processCategories[] = [        'name' => $processCategory->getName(),        'status' => $processCategory->getStatus(),    ]; } // Return the list of process categories return ['processCategories' => $processCategories]; ?> ``` #### Get Process Category This example demonstrates how to retrieve the category of a specific process. **Example** ```php processCategories(); $processCategory = $apiInstance->getProcessCategoryById(2); // Set the process ID // Return the details of the process category return [    'name' => $processCategory->getName(),    'status' => $processCategory->getStatus(), ]; ?> ``` #### Create Process Category This example demonstrates how to create a new process category. **Example** ```php processCategories(); // Create a new editable process category object $process_category_editable = new \ProcessMaker\Client\Model\ProcessCategoryEditable(); $process_category_editable->setName('newCategory'); $process_category_editable->setStatus('ACTIVE'); // Create the process category using the API $newProcessCategory = $apiInstance->createProcessCategory($process_category_editable); // Return the ID of the newly created process category return ['newProcessCategoryId' => $newProcessCategory->getId()]; ?> ``` #### Update Process Category This example demonstrates how to update an existing process category. **Example** ```php processCategories(); // Retrieve the process category to be updated $processCategory = $apiInstance->getProcessCategoryById(21); // Update the name of the process category $processCategory->setName("Procurement"); // Update the process category using the API $apiInstance->updateProcessCategory($processCategory->getId(), $processCategory); // If no errors are thrown, the process category was successfully updated return ['success' => true]; ?> ``` #### Delete Process Category This example demonstrates how to delete an existing process category. **Example** ```php processCategories(); // Delete the process category with the specified ID $apiInstance->deleteProcessCategory(21); // If no errors are thrown, the process category was successfully deleted return ['success' => true]; ?> ``` **Process Requests** Process requests represent instances of processes that have been submitted or are in progress within the ProcessMaker application. #### Get Process Requests This example demonstrates how to retrieve all the requests of a logged-in user. **Example** ```php processRequests(); $processRequests = []; // Retrieve all process requests accessible to the user $result = $apiInstance->getProcessesRequests(); foreach ($result->getData() as $processRequest) {    $processRequests[] = [        'id' => $processRequest->getId(),        'status' => $processRequest->getStatus(),        'processId' => $processRequest->getProcessId()    ]; } // Include additional data and associated process information $type = null; // Specify the type of requests to retrieve (canceled|progress|completed|error) $filter = null; // Filter results by a specific string (searches Name, Description, and Status) $order_by = 'id'; // Field to order results by $order_direction = 'asc'; // Order direction (asc|desc) $per_page = null; // Number of results per page (default: null) $include = 'process,data'; // Include data from related models in the payload (comma-separated list) $result = $apiInstance->getProcessesRequests($type, $filter, $order_by, $order_direction, $per_page, $include); foreach ($result->getData() as $processRequest) {    $processRequests[] = [        'id' => $processRequest->getId(),        'status' => $processRequest->getStatus(),        'processName' => $processRequest->getProcess()['name'],        'requestData' => $processRequest->getData(),    ]; } // Return the list of process requests return ['processRequests' => $processRequests]; ?> ``` #### Update Process Request This example demonstrates how to update an existing process request. **Example** ```php processRequests(); $processRequestId = 4; // ID of the process request to update $include = 'data'; // Include the request data in the retrieved process request $processRequest = $apiInstance->getProcessRequestById($processRequestId, $include); $data = $processRequest->getData(); $data['newItem'] = 'test2'; // Modify the request data as desired $processRequestEditable = new \ProcessMaker\Client\Model\ProcessRequestEditable(); $processRequestEditable->setData($data); $apiInstance->updateProcessRequest($processRequestId, $processRequestEditable); // If no errors are thrown, the process request was successfully updated return ['success' => true]; ?> ``` #### Delete Process Request This example demonstrates how to delete an existing process request. **Example** ```php processRequests(); $processRequestId = 4; // ID of the process request to delete $apiInstance->deleteProcessRequest($processRequestId); // If no errors are thrown, the process request was successfully deleted return ['success' => true]; ?> ``` **Processes** Processes are essential components in the ProcessMaker application, as they represent the workflows designed and developed by business architects and developers. These workflows define the sequence of tasks, actions, and decisions required to accomplish specific business objectives. #### Start a New Process Request This example demonstrates how to start a new process request. **Example** ```php processes(); $process_id = 1; // ID of the process to start $event = 'node_1'; // Node ID of the start event $body = new \stdClass; // Object to store request data $body->foo = 'bar'; // Customize the request data as desired $processRequest = $apiInstance->triggerStartEvent($process_id, $event, $body); // Return the ID of the newly created process request return ['newProcessRequestId' => $processRequest->getId()]; ?> ``` #### Get Processes This example demonstrates how to retrieve information about all the processes the user has access to. **Example** ```php processes(); $processes = []; // Retrieve all processes accessible to the user $result = $apiInstance->getProcesses(); foreach ($result->getData() as $process) {    $processes[] = [        'id' => $process->getId(),        'name' => $process->getName(),        'process_category_id' => $process->getProcessCategoryId(),        'status' => $process->getStatus(),    ]; } // Optional Parameters $filter = 'test'; // Filter results by a specific string $order_by = 'id'; // Field to order results by $order_direction = 'asc'; // Order direction (asc|desc) $per_page = 5; // Number of results per page $status = 'ACTIVE'; // Filter results by process status (ACTIVE or INACTIVE) $include = 'category'; // Include data from related models in the payload (comma-separated list) $result = $apiInstance->getProcesses($filter, $order_by, $order_direction, $per_page, $status, $include); foreach ($result->getData() as $process) {    $processes[] = [        'id' => $process->getId(),        'name' => $process->getName(),        'categoryName' => $process->getCategory()['name'],        'status' => $process->getStatus(),    ]; } // Return the list of processes return ['processes' => $processes]; ?> ``` #### Get Process This example demonstrates how to retrieve information about a specific process. **Example** ```php processes(); $process = $apiInstance->getProcessById(12); // ID of the process to retrieve // Return the details of the process return [    'name' => $process->getName(),    'categoryName' => $process->getCategory()['name'],    'status' => $process->getStatus(), ]; ?> ``` #### Delete Process This example demonstrates how to delete an existing process. **Example** ```php processes(); $process = $apiInstance->deleteProcess(81); // ID of the process to delete // If no errors are thrown, the process was successfully deleted return ['success' => true]; ?> ``` #### Export Process This example demonstrates how to export a process from your ProcessMaker instance. **Example** ```php processes(); $process_id = 1; // ID of the process to export $result = $apiInstance->exportProcess($process_id); // Return the download URL of the exported process return [    'downloadUrl' => $result->getUrl(), ]; ?> ``` #### Import Process This example demonstrates how to import a process into your ProcessMaker instance. **Example** ```php processes(); $exportedProcess = 'https://my-server/my-process.json'; // URL of the exported process file $tmpFile = '/tmp/my-process.json'; // Temporary file to store the downloaded process file copy($exportedProcess, $tmpFile); // Download the process file $result = $apiInstance->importProcess($tmpFile); // Import the process // Return the ID of the imported process return [    'importedProcessId' => $result->getProcess()['id'] ]; ?> ``` **Screen Categories** Screen categories play a crucial role in the ProcessMaker application as they provide a structured way to organize screens, enabling users to maintain better control over their workflow processes. #### Get Screen Categories This example demonstrates how to retrieve information about screen categories. **Example** ```php screenCategories(); $screenCategories = []; $result = $apiInstance->getScreenCategories(); // Iterate over each screen category object returned by the API foreach ($result->getData() as $screenCategory) {    $screenCategories[] = [        'id' => $screenCategory->getId(),        'name' => $screenCategory->getName(),        'status' => $screenCategory->getStatus(),    ]; } // Return an array of screen categories with its respective IDs, names, and statuses return ['screenCategories' => $screenCategories]; ?> ``` #### Get Screen Category This example shows how to retrieve information about a specific screen category. **Example** ```php screenCategories(); $screenCategory = $apiInstance->getScreenCategoryById(10); // ID of the screen category to retrieve // Return the details of the screen category return [    'name' => $screenCategory->getName(),    'status' => $screenCategory->getStatus(), ]; ?> ``` #### Create Screen Category This example demonstrates how to create a new screen category. **Example** ```php screenCategories(); $screen_category_editable = new \ProcessMaker\Client\Model\ScreenCategoryEditable(); $screen_category_editable->setName('Procurement'); // Set the name of the new screen category $screen_category_editable->setStatus('ACTIVE'); // Set the status of the new screen category $newScreenCategory = $apiInstance->createScreenCategory($screen_category_editable); // Return the ID of the newly created screen category return ['newScreenCategoryId' => $newScreenCategory->getId()]; ?> ``` #### Update Screen Category This example demonstrates how to update an existing screen category. **Example** ```php screenCategories(); $screenCategory = $apiInstance->getScreenCategoryById(20); // ID of the screen category to update $screenCategory->setName("Healthcare"); // Set the new name for the screen category $apiInstance->updateScreenCategory($screenCategory->getId(), $screenCategory); // If no errors are thrown, then the screen category was successfully updated return ['success' => true]; ?> ``` #### Delete Screen Category This example demonstrates how to delete a screen category. **Example** ```php screenCategories(); $apiInstance->deleteScreenCategory(20); // ID of the screen category to delete // If no errors are thrown, then the screen category was successfully deleted return ['success' => true]; ?> ``` **Screens** Screens are essential components within the ProcessMaker application that facilitate interaction with end users and enable data capture. These web-based forms play a crucial role in gathering input and displaying information during workflow processes. #### Get Screens This example shows how to retrieve all the screens the user has access to. **Example** ```php screens(); $screens = []; // Get all screens $result = $apiInstance->getScreens(); foreach ($result->getData() as $screen) {    $screens[] = [        'id' => $screen->getId(),        'title' => $screen->getTitle(),        'config' => $screen->getConfig(),    ]; } // Return the list of screens return ['screens' => $screens]; ?> ``` #### Get screen This example demonstrates how to retrieve information about a specific screen. **Example** ```php screens(); $screen = $apiInstance->getScreensById(63); // ID of the screen to retrieve // Return the details of the screen return [    'screen' => [        'title' => $screen->getTitle(),        'config' => $screen->getConfig(),    ], ]; ?> ``` #### Export screen This example demonstrates how to export a screen from your ProcessMaker instance. **Example** ```php screens(); $result = $apiInstance->exportScreen(14); // ID of the screen to export // Return the download URL of the exported screen return ['downloadUrl' => $result->getUrl()]; ?> ``` #### Import screen This example demonstrates how to import a screen into your ProcessMaker instance. **Example** ```php screens(); $exportedScreen = 'http://my-server/my-screen.json'; // URL or local path of the exported screen file $tmpFile = '/tmp/my-screen.json'; // Temporary file to store the exported screen copy($exportedScreen, $tmpFile); // Download or copy the exported screen to the temporary file $result = $apiInstance->importScreen($tmpFile); // Return the import result status return ['importResult' => $result->getStatus()]; ?> ``` **Tasks** Tasks represent specific activities or steps within a workflow process that require user action or intervention. #### Get Tasks This example demonstrates how to retrieve information about all the tasks of your instance. **Example** ```php tasks(); $tasks = []; // Returns all tasks that the user has access to $result = $apiInstance->getTasks(); foreach ($result->getData() as $task) {    $tasks[] = [        'id' => $task->getId(),        'name' => $task->getElementName(),        'processRequestId' => $task->getProcessRequestId(),        'status' => $task->getStatus(),        'userId' => $task->getUserId(),    ]; } // Optional arguments $process_request_id = 5; // int | Process request ID $filter = 'Form Task'; // string | Filter by task ID, node name, or request data $order_by = 'id'; // string | Field to order results by $order_direction = 'asc'; // string | Order direction (ascending or descending) $include = 'process,user'; // string | Include data from related models in payload. Comma-separated list. $result = $apiInstance->getTasks($process_request_id, $filter, $order_by, $order_direction, $include); foreach ($result->getData() as $task) {    $tasks[] = [        'id' => $task->getId(),        'name' => $task->getElementName(),        'status' => $task->getStatus(),        'userEmail' => $task->getUser()['email'],        'processName' => $task->getProcess()['name'],    ]; } // Return the list of tasks return ['tasks' => $tasks]; ?> ``` #### Get Task This example demonstrates how to retrieve information about a specific task. **Example** ```php tasks(); $taskId = 7; // ID of the task to retrieve $task = $apiInstance->getTasksById($taskId); // Return the details of the task return [    'task' => [        'name' => $task->getElementName(),        'status' => $task->getStatus(),        'userId' => $task->getUserId(),    ], ]; ?> ``` #### Update Task This example demonstrates how to update or complete a specific task. **Example** ```php tasks(); $taskId = 130; // ID of the task to update $task = $apiInstance->getTasksById($taskId); $process_request_token_editable = new \ProcessMaker\Client\Model\ProcessRequestTokenEditable(); $process_request_token_editable->setStatus('COMPLETED'); $process_request_token_editable->setData(['addToRequestData' => 'a value']); $result = $apiInstance->updateTask($taskId, $process_request_token_editable); // If no errors are thrown, then the task was successfully updated return ['success' => true]; ?> ``` **Users** Users are individuals who have access to the ProcessMaker application and can interact with workflow processes. #### Get Users This example demonstrates how to retrieve all the users of your ProcessMaker instance. **Example** ```php users(); $users = []; // Get all users $result = $apiInstance->getUsers(); foreach ($result->getData() as $user) {    $users[] = ['username' => $user->getUsername(), 'email' => $user->getEmail()]; } // Optional arguments $status = 'ACTIVE'; // string | Filter results by status (ACTIVE or INACTIVE) $filter = 'admin'; // string $order_by = 'id'; // string | Field results by ID $order_direction = 'asc'; // string | Order direction (ascending or descending) $per_page = 1; // int | Number of users to retrieve per page $include = ''; // string | Include data from related models in payload. Comma-separated list. $result = $apiInstance->getUsers($status, $filter, $order_by, $order_direction, $per_page, $include); foreach ($result->getData() as $user) {    $users[] = ['username' => $user->getUsername(), 'email' => $user->getEmail()]; } // Return the list of users return ['users' => $users]; ?> ``` #### Get User This example shows how to retrieve information about a specific user. **Example** ```php users(); $user = $apiInstance->getUserById(5); // Set the user ID // Return the details of the user return [    'user' => [        'username' => $user->getUsername(),        'email' => $user->getEmail(),        'status' => $user->getStatus(),    ], ]; ?> ``` #### Create User This example illustrates how to create a new user in your ProcessMaker instance. **Example** ```php users(); $user = new \ProcessMaker\Client\Model\UsersEditable(); $user->setFirstname('John'); $user->setLastname('Due'); $user->setUsername('johndue'); $user->setPassword('Passcode123'); $user->setEmail('john.due@processmaker.com'); $user->setStatus('ACTIVE'); $newUser = $apiInstance->createUser($user); // Return the ID of the newly created user return ["newUserId" => $newUser->getId()]; ?> ``` #### Update User This example demonstrates how to update an existing user in your ProcessMaker instance. **Example** ```php users(); $userId = 14; $user = $apiInstance->getUserById($userId); // Update user details $user->setFirstname('John Waters'); $user->setEmail('john.waters@processmaker.com'); // Call the updateUser method to update the user $result = $apiInstance->updateUser($userId, $user); // If no errors are thrown, then the user was successfully updated return ['success' => true]; ?> ``` #### Delete User This example demonstrates how to delete a user from your ProcessMaker instance. **Example** ```php users(); // Set the user ID to be deleted $userId = 14; $apiInstance->deleteUser($userId); // If no errors are thrown, then the user was successfully deleted return ['success' => true]; ?> ``` ## Conclusion In conclusion, this guide provides developers with a wealth of practical examples to leverage the capabilities of ProcessMaker effectively. These examples cover a range of use cases, offering insights into best practices and time-saving techniques for process development. By incorporating these examples into the script tasks within the ProcessMaker platform, developers can enhance their productivity and streamline their workflow automation projects.