|
| 1 | +# n8n Laravel Client |
| 2 | + |
| 3 | +A complete, expressive, and fluent Laravel client for the n8n public REST API and Webhooks Triggering, empowering PHP |
| 4 | +developers to interact |
| 5 | +seamlessly with n8n webhooks, workflows, executions, credentials, tags, users, variables, projects, and source control |
| 6 | +operations. |
| 7 | + |
| 8 | +## Table of Contents |
| 9 | + |
| 10 | +* [📦 Installation](#-installation) |
| 11 | +* [⚙️ Configuration](#-configuration) |
| 12 | +* [🚀 Quick Start](#-quick-start) |
| 13 | +* [⚡ Webhooks Trigger](#-webhooks-trigger) |
| 14 | +* [📚 Full API Resource Reference](#-full-api-resource-reference) |
| 15 | + * [🕵 Audit](#-audit) |
| 16 | + * [🔑 Credentials](#-credentials) |
| 17 | + * [⏯️ Executions](#-executions) |
| 18 | + * [🚧 Projects](#-projects) |
| 19 | + * [📝 Source Control](#-source-control) |
| 20 | + * [🏷️ Tags](#-tags) |
| 21 | + * [🙍 Users](#-users) |
| 22 | + * [🔠 Variables](#-variables) |
| 23 | + * [🔄 Workflows](#-workflows) |
| 24 | +* [🤝 Contributing](#-contributing) |
| 25 | +* [🛠 Support](#-support) |
| 26 | +* [📄 License](#-license) |
| 27 | + |
| 28 | +## 📦 Installation |
| 29 | + |
| 30 | +Install via Composer: |
| 31 | + |
| 32 | +```bash |
| 33 | +composer require kayedspace/n8n-laravel |
| 34 | +``` |
| 35 | + |
| 36 | +Service providers and facades are auto-discovered by Laravel. |
| 37 | + |
| 38 | +## ⚙️ Configuration |
| 39 | + |
| 40 | +Publish and customize the configuration file: |
| 41 | + |
| 42 | +```bash |
| 43 | +php artisan vendor:publish --tag=n8n-config |
| 44 | +``` |
| 45 | + |
| 46 | +Set environment variables in .env: |
| 47 | + |
| 48 | +```dotenv |
| 49 | +N8N_TIMEOUT=120 |
| 50 | +N8N_THROW=true |
| 51 | +N8N_RETRY=3 |
| 52 | +
|
| 53 | +N8N_BASE_URI=https://your-n8n-instance.com/api/v1 |
| 54 | +N8N_API_KEY=your_api_key |
| 55 | +
|
| 56 | +N8N_WEBHOOK_BASE_URI=https://your-n8n-instance.com/webhook |
| 57 | +N8N_WEBHOOK_USERNAME==your_webhook_username |
| 58 | +N8N_WEBHOOK_PASSWORD=your_webhook_password |
| 59 | +``` |
| 60 | + |
| 61 | +## 🚀 Quick Start |
| 62 | + |
| 63 | +```php |
| 64 | +use N8nClient; |
| 65 | + |
| 66 | +// trigger webhook |
| 67 | +$webhookTrigger =N8nClient::webhooks()->trigger("path-to-webhook",$payload); |
| 68 | + |
| 69 | +// List all workflows |
| 70 | +$workflows = N8nClient::workflows()->list(); |
| 71 | + |
| 72 | + |
| 73 | +// Retrieve execution status with data |
| 74 | +$status = N8nClient::executions()->get($execution['id'], includeData: true); |
| 75 | + |
| 76 | +``` |
| 77 | + |
| 78 | +## ⚡ Webhooks Trigger |
| 79 | + |
| 80 | +The Webhooks class enables sending HTTP requests to n8n workflow webhook trigger URLs, supporting multiple HTTP verbs ( |
| 81 | +GET, POST, etc.) and basic authentication (if configured). |
| 82 | + |
| 83 | +## 📚 Full API Resource Reference |
| 84 | + |
| 85 | +Below is an exhaustive reference covering every resource and method provided. |
| 86 | + |
| 87 | +### 🕵 Audit |
| 88 | + |
| 89 | +| Method | Description | HTTP Method & Path | |
| 90 | +|-------------------------------------------|----------------------------------------------------------------------|--------------------| |
| 91 | +| `generate(array $additionalOptions = [])` | Generate a full audit report based on optional categories or filters | `POST /audit` | |
| 92 | + |
| 93 | +**Description:** |
| 94 | +This endpoint performs a security audit of your n8n instance and returns diagnostics grouped by category. It must be |
| 95 | +invoked by an account with owner privileges. |
| 96 | + |
| 97 | +### 🔑 Credentials |
| 98 | + |
| 99 | +| Method Signature | HTTP Method & Path | Description | |
| 100 | +|------------------------------------------------------|--------------------------------------|--------------------------------------------------------| |
| 101 | +| `create(array $payload)` | `POST /credentials` | Create a credential using the appropriate type schema. | |
| 102 | +| `list(int $limit = 100, ?string $cursor = null)` | `GET /credentials` | List stored credentials with optional pagination. | |
| 103 | +| `get(string $id)` | `GET /credentials/{id}` | Retrieve details of a specific credential by ID. | |
| 104 | +| `delete(string $id)` | `DELETE /credentials/{id}` | Delete a credential permanently. | |
| 105 | +| `schema(string $typeName)` | `GET /credentials/schema/{typeName}` | Get the schema definition for a credential type. | |
| 106 | +| `transfer(string $id, string $destinationProjectId)` | `PUT /credentials/{id}/transfer` | Move a credential to another project using its ID. | |
| 107 | + |
| 108 | +**Example:** |
| 109 | + |
| 110 | +```php |
| 111 | +$schema = $n8n->credentials()->schema('slackApi'); |
| 112 | + |
| 113 | +$n8n->credentials()->create([ |
| 114 | + 'name' => 'Slack Token', |
| 115 | + 'type' => 'slackApi', |
| 116 | + 'data' => [ |
| 117 | + 'token' => 'xoxb-123456789', |
| 118 | + ] |
| 119 | +]); |
| 120 | +``` |
| 121 | + |
| 122 | +### ⏯️ Executions |
| 123 | + |
| 124 | +| Method Signature | HTTP Method & Path | Description | |
| 125 | +|-------------------------------------------|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| |
| 126 | +| `list(array $filters = [])` | `GET /executions` | Retrieve a paginated list of workflow executions. Supports filters such as `status`, `workflowId`, `projectId`, `includeData`, `limit`, `cursor`. | |
| 127 | +| `get(int $id, bool $includeData = false)` | `GET /executions/{id}` | Retrieve detailed information for a specific execution. Optionally include execution data. | |
| 128 | +| `delete(int $id)` | `DELETE /executions/{id}` | Delete an execution record by ID. | |
| 129 | + |
| 130 | +**Example:** |
| 131 | + |
| 132 | +```php |
| 133 | +// Get a list of executions filtered by status |
| 134 | +$executions = $n8n->executions()->list(['status' => 'success']); |
| 135 | + |
| 136 | +// Get detailed execution data |
| 137 | +$execution = $n8n->executions()->get(101, true); |
| 138 | + |
| 139 | +// Delete an execution |
| 140 | +$n8n->executions()->delete(101); |
| 141 | +``` |
| 142 | + |
| 143 | +### 🚧 Projects |
| 144 | + |
| 145 | +| Method Signature | HTTP Method & Path | Description | |
| 146 | +|-------------------------------------------------------------------|-----------------------------------------------|------------------------------------------------------------------------| |
| 147 | +| `create(array $payload)` | `POST /projects` | Create a new project with name, description, etc. | |
| 148 | +| `list(int $limit = 100, ?string $cursor = null)` | `GET /projects` | Retrieve a paginated list of projects. | |
| 149 | +| `update(string $projectId, array $payload)` | `PUT /projects/{projectId}` | Update project name or metadata. Returns 204 No Content on success. | |
| 150 | +| `delete(string $projectId)` | `DELETE /projects/{projectId}` | Delete a project by ID. Returns 204 No Content on success. | |
| 151 | +| `addUsers(string $projectId, array $relations)` | `POST /projects/{projectId}/users` | Add users to a project with specified roles via the `relations` array. | |
| 152 | +| `changeUserRole(string $projectId, string $userId, string $role)` | `PATCH /projects/{projectId}/users/{userId}` | Change the role of an existing user within a project. | |
| 153 | +| `removeUser(string $projectId, string $userId)` | `DELETE /projects/{projectId}/users/{userId}` | Remove a user from a project. | |
| 154 | + |
| 155 | +**Example Usage:** |
| 156 | + |
| 157 | +```php |
| 158 | +// Create a project |
| 159 | +$project = $n8n->projects()->create(['name' => 'DevOps', 'description' => 'CI/CD flows']); |
| 160 | + |
| 161 | +// Add users |
| 162 | +$n8n->projects()->addUsers($project['id'], [ |
| 163 | + ['userId' => 'abc123', 'role' => 'member'], |
| 164 | +]); |
| 165 | + |
| 166 | +// Promote user role |
| 167 | +$n8n->projects()->changeUserRole($project['id'], 'abc123', 'admin'); |
| 168 | + |
| 169 | +// Delete the project |
| 170 | +$n8n->projects()->delete($project['id']); |
| 171 | +``` |
| 172 | + |
| 173 | +### 📝 Source Control |
| 174 | + |
| 175 | +| Method Signature | HTTP Method & Path | Description | |
| 176 | +|------------------------|-----------------------------|--------------------------------------------------------------------------| |
| 177 | +| `pull(array $payload)` | `POST /source-control/pull` | Trigger a pull operation from the connected Git source for all projects. | |
| 178 | + |
| 179 | +**Example:** |
| 180 | + |
| 181 | +```php |
| 182 | +$syncStatus = $n8n->sourceControl()->pull([ |
| 183 | + 'projectIds' => ['project-1', 'project-2'], |
| 184 | +]); |
| 185 | +``` |
| 186 | + |
| 187 | +> Requires source control integration to be configured in the n8n instance. |
| 188 | +
|
| 189 | +### 🏷️ Tags |
| 190 | + |
| 191 | +| Method Signature | HTTP Method & Path | Description | |
| 192 | +|--------------------------------------------------|---------------------|------------------------------------------------------------| |
| 193 | +| `create(array $payload)` | `POST /tags` | Create a new tag with the given name or properties. | |
| 194 | +| `list(int $limit = 100, ?string $cursor = null)` | `GET /tags` | List all tags with optional pagination using limit/cursor. | |
| 195 | +| `get(string $id)` | `GET /tags/{id}` | Retrieve a single tag by its ID. | |
| 196 | +| `update(string $id, array $payload)` | `PUT /tags/{id}` | Update the name or properties of a specific tag. | |
| 197 | +| `delete(string $id)` | `DELETE /tags/{id}` | Delete a tag permanently by its ID. | |
| 198 | + |
| 199 | +**Example:** |
| 200 | + |
| 201 | +```php |
| 202 | +$tag = $n8n->tags()->create(['name' => 'Marketing']); |
| 203 | +$updated = $n8n->tags()->update($tag['id'], ['name' => 'Sales']); |
| 204 | +$all = $n8n->tags()->list(); |
| 205 | +``` |
| 206 | + |
| 207 | +### 🙍 Users |
| 208 | + |
| 209 | +| Method Signature | HTTP Method & Path | Description | |
| 210 | +|------------------------------------------------------|---------------------------------|----------------------------------------------------------------------------------| |
| 211 | +| `list(array $filters = [])` | `GET /users` | List users with optional filters: `limit`, `cursor`, `includeRole`, `projectId`. | |
| 212 | +| `create(array $userPayloads)` | `POST /users` | Create (invite) one or more users by providing user objects. | |
| 213 | +| `get(string $idOrEmail, bool $includeRole = false)` | `GET /users/{idOrEmail}` | Get a user by ID or email. Optionally include role. | |
| 214 | +| `delete(string $idOrEmail)` | `DELETE /users/{idOrEmail}` | Delete a user by ID or email. | |
| 215 | +| `changeRole(string $idOrEmail, string $newRoleName)` | `PATCH /users/{idOrEmail}/role` | Change the user's role to the new role name. | |
| 216 | + |
| 217 | +**Example:** |
| 218 | + |
| 219 | +```php |
| 220 | +// Invite users |
| 221 | +$n8n->users()->create([ |
| 222 | + ['email' => ' [email protected]', 'role' => 'member'] |
| 223 | +]); |
| 224 | + |
| 225 | +// Promote to admin |
| 226 | +$n8n->users()->changeRole(' [email protected]', 'admin'); |
| 227 | +``` |
| 228 | + |
| 229 | +### 🔠 Variables |
| 230 | + |
| 231 | +| Method Signature | HTTP Method & Path | Description | |
| 232 | +|--------------------------------------------------|--------------------------|-----------------------------------------------------------------| |
| 233 | +| `create(array $payload)` | `POST /variables` | Create a new variable with a key-value pair. | |
| 234 | +| `list(int $limit = 100, ?string $cursor = null)` | `GET /variables` | List variables with optional pagination using limit and cursor. | |
| 235 | +| `update(string $id, array $payload)` | `PUT /variables/{id}` | Update the value of an existing variable. | |
| 236 | +| `delete(string $id)` | `DELETE /variables/{id}` | Permanently delete a variable. | |
| 237 | + |
| 238 | +**Example:** |
| 239 | + |
| 240 | +```php |
| 241 | +// Create a new variable |
| 242 | +$n8n->variables()->create(['key' => 'ENV_MODE', 'value' => 'production']); |
| 243 | + |
| 244 | +// Update the variable |
| 245 | +$n8n->variables()->update('ENV_MODE', ['value' => 'staging']); |
| 246 | + |
| 247 | +// Delete the variable |
| 248 | +$n8n->variables()->delete('ENV_MODE'); |
| 249 | +``` |
| 250 | + |
| 251 | +### 🔄 Workflows |
| 252 | + |
| 253 | +| Method Signature | HTTP Method & Path | Description | |
| 254 | +|------------------------------------------------------|-----------------------------------|---------------------------------------------------------------------------| |
| 255 | +| `create(array $payload)` | `POST /workflows` | Create a new workflow using a flow definition. | |
| 256 | +| `list(array $filters = [])` | `GET /workflows` | List workflows with optional filters: `active`, `tags`, `projectId`, etc. | |
| 257 | +| `get(string $id, bool $excludePinnedData = false)` | `GET /workflows/{id}` | Retrieve a specific workflow; optionally exclude pinned node data. | |
| 258 | +| `update(string $id, array $payload)` | `PUT /workflows/{id}` | Update the workflow definition. | |
| 259 | +| `delete(string $id)` | `DELETE /workflows/{id}` | Delete the specified workflow. | |
| 260 | +| `activate(string $id)` | `POST /workflows/{id}/activate` | Activate the workflow. | |
| 261 | +| `deactivate(string $id)` | `POST /workflows/{id}/deactivate` | Deactivate the workflow. | |
| 262 | +| `transfer(string $id, string $destinationProjectId)` | `PUT /workflows/{id}/transfer` | Move a workflow to a different project. | |
| 263 | +| `tags(string $id)` | `GET /workflows/{id}/tags` | Get all tags associated with the workflow. | |
| 264 | +| `updateTags(string $id, array $tagIds)` | `PUT /workflows/{id}/tags` | Update the list of tag IDs for a workflow. | |
| 265 | + |
| 266 | +**Example:** |
| 267 | + |
| 268 | +```php |
| 269 | +// Create and activate a workflow |
| 270 | +$wf = $n8n->workflows()->create([...]); |
| 271 | +$n8n->workflows()->activate($wf['id']); |
| 272 | + |
| 273 | +``` |
| 274 | + |
| 275 | +## 🤝 Contributing |
| 276 | + |
| 277 | +Contributions are welcome! If you have a feature request, bug report, or improvement: |
| 278 | + |
| 279 | +1. Fork the repository |
| 280 | +2. Create your feature branch: `git checkout -b feature/my-feature` |
| 281 | +3. Commit your changes: `git commit -am 'Add new feature'` |
| 282 | +4. Push to the branch: `git push origin feature/my-feature` |
| 283 | +5. Open a pull request |
| 284 | + |
| 285 | +Please adhere to PSR-12 and include tests where applicable. |
| 286 | + |
| 287 | +## 🛠 Support |
| 288 | + |
| 289 | +If you encounter any issues or have questions: |
| 290 | + |
| 291 | +* Open an issue on the GitHub repository |
| 292 | +* Use Discussions for non-bug topics or feature proposals |
| 293 | +* Pull requests are always welcome for fixes and improvements |
| 294 | +* |
| 295 | + |
| 296 | +## 📄 License |
| 297 | + |
| 298 | +This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
0 commit comments