Skip to content

PHP n8n Client

Strongly typed PHP client for n8n webhooks

Trigger n8n webhooks and track workflow executions with PSR-7, PSR-17, and PSR-18.

PHP n8n Client

What This Package Does

php-n8n/client is a lightweight PHP library for applications that need to trigger n8n workflows through webhooks and optionally track executions through the n8n API.

It is designed around standards rather than framework integrations. The runtime dependencies are PSR interfaces:

DependencyPurpose
psr/http-clientSends PSR-7 requests through a PSR-18 client.
psr/http-factoryCreates PSR-7 requests and streams.
psr/http-messageRepresents requests, responses, streams, and URIs.

You install concrete implementations yourself, for example Guzzle for PSR-18 and Nyholm PSR-7 for PSR-17/PSR-7.

bash
composer require php-n8n/client guzzlehttp/guzzle nyholm/psr7

Minimal Example

php
<?php

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;

$psr17 = new Psr17Factory();

$client = new N8nClient(
    httpClient: new GuzzleClient(),
    requestFactory: $psr17,
    streamFactory: $psr17,
);

$response = $client->webhooks()->trigger(
    Webhook::fromUri($psr17->createUri('https://n8n.example.com/webhook/order-created')),
    WebhookRequest::json([
        'orderId' => 'ORD-1001',
        'total' => 129.50,
    ]),
);

$body = $response->body();

Next Steps

  • Start with Getting Started for installation and the first webhook call.
  • Read Webhooks for request bodies, headers, query parameters, and responses.
  • Read Execution Tracking if you need to poll n8n workflow executions.
  • Read Laravel Usage for a practical service-provider setup.

Released under the MIT License.