-
-
Notifications
You must be signed in to change notification settings - Fork 177
PHP client
Akram El Assas edited this page Jul 18, 2025
·
4 revisions
- Install PHP
- On Windows, enable
curl
inphp.ini
:
extension_dir = "ext"
extension=curl
Here is a sample PHP client client.php
:
<?php
$baseUrl = 'http://localhost:8000/api/v1';
$username = 'admin';
$password = 'wexflow2018';
$workflowId = 1;
/**
* Sends a login request and returns the access token.
*/
function login($username, $password, $stayConnected = false)
{
global $baseUrl;
$url = $baseUrl . '/login';
$payload = json_encode([
'username' => $username,
'password' => $password,
'stayConnected' => $stayConnected
]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => $payload
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("Login failed: HTTP $httpCode - $response");
}
$data = json_decode($response, true);
return $data['access_token'] ?? null;
}
/**
* Starts the workflow with the given ID using the access token.
*/
function startWorkflow($workflowId, $token)
{
global $baseUrl;
$url = $baseUrl . '/start?w=' . urlencode($workflowId);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Content-Length: 0",
"Authorization: Bearer $token"
),
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("Start workflow failed: HTTP $httpCode - $response");
}
$data = json_decode($response, true);
return $data;
}
try {
$token = login($username, $password);
$jobId = startWorkflow($workflowId, $token);
echo "Workflow $workflowId started successfully. Job ID: " . json_encode($jobId) . "\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
?>
To run the client, use the following command:
php client.php
Copyright © Akram El Assas. All rights reserved.
- Install Guide
- HTTPS/SSL
- Screenshots
- Docker
- Configuration Guide
- Persistence Providers
- Getting Started
- Android App
- Local Variables
- Global Variables
- REST Variables
- Functions
- Cron Scheduling
- Command Line Interface (CLI)
- REST API Reference
- Samples
- Logging
- Custom Tasks
-
Built-in Tasks
- File system tasks
- Encryption tasks
- Compression tasks
- Iso tasks
- Speech tasks
- Hashing tasks
- Process tasks
- Network tasks
- XML tasks
- SQL tasks
- WMI tasks
- Image tasks
- Audio and video tasks
- Email tasks
- Workflow tasks
- Social media tasks
- Waitable tasks
- Reporting tasks
- Web tasks
- Script tasks
- JSON and YAML tasks
- Entities tasks
- Flowchart tasks
- Approval tasks
- Notification tasks
- SMS tasks
- Run from Source
- Fork, Customize, and Sync