1. Go to this page and download the library: Download php-n8n/client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-n8n / client example snippets
declare(strict_types=1);
use GuzzleHttp\Client as GuzzleClient;
use Nyholm\Psr7\Factory\Psr17Factory;
use PhpN8n\Client\N8nClient;
use PhpN8n\Client\Webhooks\Webhook;
use PhpN8n\Client\Webhooks\WebhookRequest;
$psr17Factory = new Psr17Factory();
$client = new N8nClient(
httpClient: new GuzzleClient(),
requestFactory: $psr17Factory,
streamFactory: $psr17Factory,
);
$response = $client->webhooks()->trigger(
Webhook::fromUri($psr17Factory->createUri('https://n8n.example.com/webhook/order-created')),
WebhookRequest::json([
'orderId' => 'ORD-1001',
'total' => 129.50,
]),
);
$body = $response->body();
use PhpN8n\Client\Config\ApiConfig;
use PhpN8n\Client\Config\ExecutionFetchOptions;
use PhpN8n\Client\Config\PollingConfig;
use PhpN8n\Client\Executions\ExecutionReference;
$client = new N8nClient(
httpClient: new GuzzleClient(),
requestFactory: $psr17Factory,
streamFactory: $psr17Factory,
apiConfig: new ApiConfig(
apiUri: $psr17Factory->createUri('https://n8n.example.com/api/v1'),
apiKey: $_ENV['N8N_API_KEY'],
),
);
$reference = ExecutionReference::fromId('123');
$result = $client->executions()->wait(
$reference,
new PollingConfig(
timeoutSeconds: 60,
intervalMilliseconds: 1000,
fetchOptions: ExecutionFetchOptions::withData(),
),
);