PHP code example of kayedspace / laravel-n8n

1. Go to this page and download the library: Download kayedspace/laravel-n8n 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/ */

    

kayedspace / laravel-n8n example snippets


use KayedSpace\N8n\Facades\N8nClient;

// trigger webhook
$webhookTrigger =N8nClient::webhooks()->request("path-to-webhook",$payload);

// List all workflows
$workflows = N8nClient::workflows()->list();


// Retrieve execution status with data
$status = N8nClient::executions()->get($execution['id'], 

//request a webhook
$webhookTrigger =N8nClient::webhooks()->request("path-to-webhook",$payload);

//request a webhook with custom basic auth credentials
//overwrites values provided on .env` file 
$webhookTrigger =N8nClient::withBasicAuth("custom-username","custom-password")->request("path-to-webhook",$payload);

//request a  webhook without  auth
$webhookTrigger =N8nClient::withoutBasicAuth()->request("path-to-webhook",$payload);


$schema = N8nClient::credentials()->schema('slackApi');

N8nClient::credentials()->create([
    'name' => 'Slack Token',
    'type' => 'slackApi',
    'data' => [
        'token' => 'xoxb-123456789',
    ]
]);

// Get a list of executions filtered by status
$executions = N8nClient::executions()->list(['status' => 'success']);

// Get detailed execution data
$execution = N8nClient::executions()->get(101, true);

// Delete an execution
N8nClient::executions()->delete(101);

// Create a project
$project = N8nClient::projects()->create(['name' => 'DevOps', 'description' => 'CI/CD flows']);

// Add users
N8nClient::projects()->addUsers($project['id'], [
  ['userId' => 'abc123', 'role' => 'member'],
]);

// Promote user role
N8nClient::projects()->changeUserRole($project['id'], 'abc123', 'admin');

// Delete the project
N8nClient::projects()->delete($project['id']);

$syncStatus = N8nClient::sourceControl()->pull([
    'projectIds' => ['project-1', 'project-2'],
]);

$tag = N8nClient::tags()->create(['name' => 'Marketing']);
$updated = N8nClient::tags()->update($tag['id'], ['name' => 'Sales']);
$all = N8nClient::tags()->list();

// Invite users
N8nClient::users()->create([
  ['email' => '[email protected]', 'role' => 'member']
]);

// Promote to admin
N8nClient::users()->changeRole('[email protected]', 'admin');

// Create a new variable
N8nClient::variables()->create(['key' => 'ENV_MODE', 'value' => 'production']);

// Update the variable
N8nClient::variables()->update('ENV_MODE', ['value' => 'staging']);

// Delete the variable
N8nClient::variables()->delete('ENV_MODE');

// Create and activate a workflow
$wf = N8nClient::workflows()->create([...]);
N8nClient::workflows()->activate($wf['id']);

bash
php artisan vendor:publish --tag=n8n-config