n8n

    In the new boilerplate, you can create AI Agents with a Low-Code solution using n8n API
    If you want to use n8n API - you need to buy any paid plan, as there is no possibility to work with API in free plan
    Environment variables
    1. Log in to your n8n account and create a new workflow
    2. Copy your workflow path and paste in .env
    n8n1

    .env

  1. N8N_API_URL=https://your-domain.app.n8n.cloud/api/v1
  2. N8N_WEBHOOK_URL=https://your-domain.app.n8n.cloud/webhook
  3. 4. Create your API KEY here and paste in .env
    To use n8n API - you need to buy any paid plan, as there is no possibility to work with API in free plan
    n8n2

    .env

  4. N8N_API_KEY=
  5. Scenario templates
    1. Create a new workflow in n8n
    If you want to communicate with your workflow via HTTP requests, your workflow must start and end with the Webhook module (gateway-webhook)
    2. Add your workflow data to the workflows/page.tsx availableScenarios like this:

    scenarios/page.tsx

  6. {
  7. id: 'yourWorkflowId',
  8. image: '/workflows/n8n.png',
  9. name: 'yourWorkflowName',
  10. description: 'yourWorkflowDescription',
  11. fields: ['yourWorkflowFields'],
  12. route: '/api/workflows/yourWorkflowName',
  13. },
  14. 3. Create a new route in app/api/workflows. You must specify each connection and the initial webhook, if any. Like this:

    • Credentials are created like this:

    app/api/scenarios/yourScenarioName.ts

  15. // Creating OpenAI credentials
  16. const credentialsData: N8nCredentials = {
  17. name: 'OpenAI date',
  18. type: 'openAiApi',
  19. data: { apiKey: apiKey },
  20. }
  21. const credentialsResponse = await axios.post(
  22. 'N8N_BASE_URL/credentials',
  23. credentialsData,
  24. { headers }
  25. )
  26. const credentialsId = credentialsResponse.data.id
  27. if (!credentialsId) {
  28. throw new Error('Failed to create credentials')
  29. }
  30. 4. GET a blueprint of your workflow from /workflows/WORKFLOW_ID

    app/api/scenarios/yourScenarioName.ts

  31. // Getting the source workflow
  32. const workflowResponse = await axios.get(
  33. 'N8N_BASE_URL/workflows/id',
  34. { headers }
  35. )
  36. const workflow = workflowResponse.data
  37. const webhookPath = date.replace(/[^a-zA-Z0-9]/g, '')
  38. 5. Update the nodes configuration

    app/api/scenarios/yourScenarioName.ts

  39. // 4. Updating nodes configuration
  40. const updatedNodes: WorkflowNode[] = workflow.nodes.map(
  41. (node: WorkflowNode) => {
  42. if (node.type === 'n8n-nodes-base.webhook') {
  43. return {
  44. ...node,
  45. parameters: {
  46. ...node.parameters,
  47. path: webhookPath,
  48. },
  49. }
  50. }
  51. if (node.type === 'n8n-nodes-base.openAi') {
  52. return {
  53. ...node,
  54. credentials: {
  55. openAiApi: credentialsId,
  56. },
  57. parameters: {
  58. ...node.parameters,
  59. assistantId: assistantId,
  60. },
  61. }
  62. }
  63. return node
  64. }
  65. )
  66. 6. Create new workflow using new blueprint and synchronize it with Database
    Interaction with functionality
    If your trigger module is a getaway-webhook, you get a link to which you can send requests. The boilerplate already has a trial version of chat with scenario /chat/projectID/page.tsx