PHP

PHP codes to insert in Script tasks.

chevron-rightEnvironment Variableshashtag

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
// Create an instance of the environmentVariables API class
$apiInstance = $api->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
// Retrieve a specific environment variable by ID
$apiInstance = $api->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(),
];
?>

Get Environment Variable by ID

This example demonstrates how to create a new environment variable.

Example

<?php
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->environmentVariables();

// Delete the environment variable with ID 10
$apiInstance->deleteEnvironmentVariable(10);

// The environment variable is successfully deleted
return ['success' => true];
?>
chevron-rightFileshashtag

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
$apiInstance = $api->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
$apiInstance = $api->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'], 
    ],
];
?>

chevron-rightGroupshashtag

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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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];
?>
chevron-rightProcess Categorieshashtag

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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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];
?>
chevron-rightProcess Requestshashtag

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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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];
?>
chevron-rightProcesseshashtag

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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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
$apiInstance = $api->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']
];
?>

chevron-rightScreen Categorieshashtag

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

Get Screen Category

This example shows how to retrieve information about a specific screen category.

Example

Create Screen Category

This example demonstrates how to create a new screen category.

Example

Update Screen Category

This example demonstrates how to update an existing screen category.

Example

Delete Screen Category

This example demonstrates how to delete a screen category.

Example

chevron-rightScreenshashtag

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

Get screen

This example demonstrates how to retrieve information about a specific screen.

Example

Export screen

This example demonstrates how to export a screen from your ProcessMaker instance.

Example

Import screen

This example demonstrates how to import a screen into your ProcessMaker instance.

Example

chevron-rightTaskshashtag

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

Get Task

This example demonstrates how to retrieve information about a specific task.

Example

Update Task

This example demonstrates how to update or complete a specific task.

Example

chevron-rightUsershashtag

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

Get User

This example shows how to retrieve information about a specific user.

Example

Create User

This example illustrates how to create a new user in your ProcessMaker instance.

Example

Update User

This example demonstrates how to update an existing user in your ProcessMaker instance.

Example

Delete User

This example demonstrates how to delete a user from your ProcessMaker instance.

Example

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.

Last updated