A lightweight PHP SDK for n8n, the open-source workflow automation tool. Control your n8n instance directly from PHP: manage workflows, trigger webhooks, handle users, and more.
Install via Composer:
composer require usmanzahid/n8n-phpConnect and start using:
use UsmanZahid\N8n\N8nClient;
N8nClient::connect(
'https://your-n8n-instance.com',
'your-api-key'
);
// Get all users
$response = N8nClient::users()->listUsers();
if ($response->success) {
foreach ($response->data->items as $user) {
echo $user->email . PHP_EOL;
}
}That's it. You're ready to go.
- Installation
- Configuration
- Understanding Responses
- Working with Workflows
- Working with Webhooks
- Working with Users
- Working with Tags
- Working with Variables
- Working with Projects
- Working with Executions
- Working with Credentials
- Working with Audit
- Pagination
- Contributing
- License
composer require usmanzahid/n8n-phpRequires PHP 7.4 or higher.
Before making any requests, connect to your n8n instance:
use UsmanZahid\N8n\N8nClient;
N8nClient::connect(
'https://your-n8n-instance.com', // Your n8n instance URL
'your-api-key' // Your n8n API key
);Optional webhook authentication:
N8nClient::connect(
'https://your-n8n-instance.com',
'your-api-key',
'webhook-username', // Optional
'webhook-password' // Optional
);Every method returns an N8nResponse object with these properties:
$response->success; // bool: true if successful, false otherwise
$response->data; // object: The actual data returned (workflows, users, etc.)
$response->message; // string: Error message if something went wrong
$response->statusCode; // int: HTTP status codeAlways check for success:
$response = N8nClient::workflows()->getWorkflow('workflow-id');
if ($response->success) {
$workflow = $response->data;
// Use the workflow
} else {
echo "Error: " . $response->message;
}No exceptions are thrown. Everything is handled through the response object.
// Get first page (default: 20 workflows)
$response = N8nClient::workflows()->listWorkflows();
// Get with custom limit
$response = N8nClient::workflows()->listWorkflows(['limit' => 50]);$response = N8nClient::workflows()->listWorkflowsAll();
if ($response->success) {
foreach ($response->data->items as $workflow) {
echo $workflow->name . PHP_EOL;
}
}$response = N8nClient::workflows()->getWorkflow('workflow-id');$response = N8nClient::workflows()->createWorkflow([
'name' => 'My New Workflow',
'nodes' => [],
'connections' => []
]);$response = N8nClient::workflows()->updateWorkflow('workflow-id', [
'name' => 'Updated Workflow Name'
]);$response = N8nClient::workflows()->deleteWorkflow('workflow-id');N8nClient::workflows()->activateWorkflow('workflow-id');
N8nClient::workflows()->deactivateWorkflow('workflow-id');N8nClient::workflows()->transferWorkflow('workflow-id', 'destination-project-id');// Get tags
$response = N8nClient::workflows()->getTags('workflow-id');
// Update tags (provide array of tag IDs)
N8nClient::workflows()->updateTags('workflow-id', ['tag-id-1', 'tag-id-2']);Trigger webhooks programmatically:
use UsmanZahid\N8n\Enums\WebhookMode;
use UsmanZahid\N8n\Enums\RequestMethod;
$response = N8nClient::webhook(WebhookMode::Production, RequestMethod::Post)
->send('your-webhook-id', [
'key' => 'value',
'data' => 'your data here'
]);
if ($response->success) {
echo "Webhook triggered successfully!";
}Webhook modes:
WebhookMode::Production- Live workflowsWebhookMode::Test- Test mode webhooks
Request methods:
RequestMethod::GetRequestMethod::PostRequestMethod::PutRequestMethod::PatchRequestMethod::Delete
$response = N8nClient::users()->listUsers();$response = N8nClient::users()->listUsersAll();$response = N8nClient::users()->createUser([
[
'email' => '[email protected]',
'firstName' => 'John',
'lastName' => 'Doe',
'role' => 'member'
]
]);$response = N8nClient::users()->getUser('[email protected]');$response = N8nClient::users()->deleteUser('[email protected]');$response = N8nClient::users()->changeUserRole('[email protected]', 'admin');Available roles: member, admin, owner
$response = N8nClient::tags()->listTags();$response = N8nClient::tags()->listTagsAll();$response = N8nClient::tags()->createTag([
'name' => 'Production'
]);$response = N8nClient::tags()->getTag('tag-id');$response = N8nClient::tags()->updateTag('tag-id', [
'name' => 'Updated Tag Name'
]);$response = N8nClient::tags()->deleteTag('tag-id');$response = N8nClient::variables()->listVariables();$response = N8nClient::variables()->listVariablesAll();$response = N8nClient::variables()->createVariable([
'key' => 'API_KEY',
'value' => 'secret-value'
]);$response = N8nClient::variables()->updateVariable('variable-id', [
'value' => 'new-secret-value'
]);$response = N8nClient::variables()->deleteVariable('variable-id');$response = N8nClient::projects()->listProjects();$response = N8nClient::projects()->listProjectsAll();$response = N8nClient::projects()->createProject([
'name' => 'My New Project'
]);$response = N8nClient::projects()->updateProject('project-id', [
'name' => 'Updated Project Name'
]);$response = N8nClient::projects()->deleteProject('project-id');$response = N8nClient::projects()->addUsers('project-id', [
[
'userId' => 'user-id-1',
'role' => 'member'
],
[
'userId' => 'user-id-2',
'role' => 'admin'
]
]);$response = N8nClient::projects()->changeUserRole('project-id', 'user-id', 'admin');$response = N8nClient::projects()->deleteUser('project-id', 'user-id');// Get first 10 executions
$response = N8nClient::executions()->listExecutions(10);$response = N8nClient::executions()->listExecutionsAll();// Get execution details by ID (basic info only)
$response = N8nClient::executions()->getExecution('execution-id');
// Get execution with full workflow and input/output data
// When $includeData = true, the SDK fetches all execution data from n8n,
// including the workflow structure and the data present when the workflow started.
$includeData = true;
$response = N8nClient::executions()->getExecution('execution-id', $includeData);$response = N8nClient::executions()->deleteExecution('execution-id');$response = N8nClient::executions()->stopExecution('execution-id');$response = N8nClient::executions()->retryExecution('execution-id', [
'inputData' => [] // Optional custom input data
]);$response = N8nClient::credentials()->getCredentialSchema('githubApi');$response = N8nClient::credentials()->createCredential([
'name' => 'My GitHub Token',
'type' => 'githubApi',
'data' => [
'token' => 'your-github-token'
]
]);$response = N8nClient::credentials()->deleteCredential('credential-id');Generate audit logs:
$response = N8nClient::audit()->generateAudit([
'action' => 'workflow_created',
'additionalData' => []
]);Most list methods support pagination. There are three ways to handle it:
$response = N8nClient::workflows()->listWorkflows(['limit' => 10]);$response = N8nClient::workflows()->listWorkflowsAll();
// Fetches all pages automatically$response = N8nClient::tags()->listTags();
$tagList = $response->data;
$tagsClient = N8nClient::tags();
// Check if more pages exist
while ($tagsClient->hasMore($tagList)) {
// Append next page to existing list
$tagsClient->appendNextTagPage($tagList);
}
// Now $tagList contains all tags from all pages
foreach ($tagList->items as $tag) {
echo $tag->name . PHP_EOL;
}Available append methods:
appendNextWorkflowPage()appendNextUserPage()appendNextTagPage()appendNextVariablePage()appendNextProjectPage()appendNextExecutionPage()
Contributions are welcome! If you have ideas, find bugs, or want to add features:
- Fork this repository
- Create your feature branch
- Submit a pull request
Every contribution helps make this SDK better for the PHP community.
MIT © Usman Zahid
I needed a clean way to integrate n8n into my PHP projects. Instead of writing the same API calls over and over, I built this SDK to make n8n integration simple and straightforward for PHP developers.
It's feature-complete for core use cases and ready for production. If you find it useful, star the repo and share it with others!
