@caoscompanybr/merlin 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (762) hide show
  1. package/.claude/CLAUDE.md +216 -0
  2. package/.claude/hooks/README-license-gate.md +45 -0
  3. package/.claude/hooks/auto-summarize.js +47 -0
  4. package/.claude/hooks/context-monitor.js +60 -0
  5. package/.claude/hooks/doc-sync.js +111 -0
  6. package/.claude/hooks/license-gate.cjs +59 -0
  7. package/.claude/hooks/session-reset.js +27 -0
  8. package/.claude/hooks/thoughts-indexer.js +80 -0
  9. package/.claude/rules/merlin-constitution.md +27 -0
  10. package/.merlin-core/commands/README.md +19 -0
  11. package/.merlin-core/commands/founder-mode.md +51 -0
  12. package/.merlin-core/commands/git/commit.md +35 -0
  13. package/.merlin-core/commands/git/describe-pr.md +43 -0
  14. package/.merlin-core/commands/git/safe-commit.md +182 -0
  15. package/.merlin-core/commands/implementation/implement-plan.md +129 -0
  16. package/.merlin-core/commands/implementation/oneshot.md +63 -0
  17. package/.merlin-core/commands/implementation/tdd.md +152 -0
  18. package/.merlin-core/commands/planning/create-plan.md +184 -0
  19. package/.merlin-core/commands/planning/iterate-plan.md +45 -0
  20. package/.merlin-core/commands/planning/validate-plan.md +48 -0
  21. package/.merlin-core/commands/research/analyze-issue.md +155 -0
  22. package/.merlin-core/commands/research/research-codebase.md +157 -0
  23. package/.merlin-core/commands/review/adversarial-review.md +112 -0
  24. package/.merlin-core/commands/review/check.md +91 -0
  25. package/.merlin-core/commands/review/debug.md +135 -0
  26. package/.merlin-core/commands/review/doubts.md +178 -0
  27. package/.merlin-core/commands/review/engineering-audit.md +87 -0
  28. package/.merlin-core/commands/review/local-review.md +48 -0
  29. package/.merlin-core/commands/review/verify-goals.md +83 -0
  30. package/.merlin-core/commands/session/capture-feedback.md +74 -0
  31. package/.merlin-core/commands/session/capture-learning.md +155 -0
  32. package/.merlin-core/commands/session/check-objectives.md +85 -0
  33. package/.merlin-core/commands/session/conclude.md +125 -0
  34. package/.merlin-core/commands/session/create-handoff.md +88 -0
  35. package/.merlin-core/commands/session/create-objective.md +111 -0
  36. package/.merlin-core/commands/session/create-process.md +105 -0
  37. package/.merlin-core/commands/session/create-reminder.md +86 -0
  38. package/.merlin-core/commands/session/fast-start.md +261 -0
  39. package/.merlin-core/commands/session/recall-learnings.md +79 -0
  40. package/.merlin-core/commands/session/recall-processes.md +74 -0
  41. package/.merlin-core/commands/session/resume-handoff.md +51 -0
  42. package/.merlin-core/commands/session/run-process.md +53 -0
  43. package/.merlin-core/commands/special/beauty.md +89 -0
  44. package/.merlin-core/commands/special/common-ground.md +114 -0
  45. package/.merlin-core/commands/special/elicit.md +98 -0
  46. package/.merlin-core/commands/special/party.md +66 -0
  47. package/.merlin-core/commands/special/scrape.md +78 -0
  48. package/.merlin-core/commands/special/skill-audit.md +128 -0
  49. package/.merlin-core/commands/special/start-here.md +132 -0
  50. package/.merlin-core/constitution.md +442 -0
  51. package/.merlin-core/core/README.md +19 -0
  52. package/.merlin-core/core/alkimia/README.md +20 -0
  53. package/.merlin-core/core/alkimia/context/context-tracker.js +209 -0
  54. package/.merlin-core/core/alkimia/domain/domain-loader.js +215 -0
  55. package/.merlin-core/core/alkimia/engine.js +284 -0
  56. package/.merlin-core/core/alkimia/layers/l0-constitution.js +47 -0
  57. package/.merlin-core/core/alkimia/layers/l1-global.js +58 -0
  58. package/.merlin-core/core/alkimia/layers/l2-agent.js +58 -0
  59. package/.merlin-core/core/alkimia/layers/l3-workflow.js +54 -0
  60. package/.merlin-core/core/alkimia/layers/l4-task.js +45 -0
  61. package/.merlin-core/core/alkimia/layers/l5-squad.js +161 -0
  62. package/.merlin-core/core/alkimia/layers/l6-skill.js +520 -0
  63. package/.merlin-core/core/alkimia/layers/l7-star-command.js +87 -0
  64. package/.merlin-core/core/alkimia/layers/layer-processor.js +78 -0
  65. package/.merlin-core/core/alkimia/mandate.js +46 -0
  66. package/.merlin-core/core/alkimia/memory/doc-sync.js +201 -0
  67. package/.merlin-core/core/alkimia/memory/document-sharder.js +272 -0
  68. package/.merlin-core/core/alkimia/memory/git-history-retriever.js +225 -0
  69. package/.merlin-core/core/alkimia/memory/memory-bridge.js +97 -0
  70. package/.merlin-core/core/alkimia/memory/session-analyzer.js +400 -0
  71. package/.merlin-core/core/alkimia/memory/thoughts-indexer.js +477 -0
  72. package/.merlin-core/core/alkimia/memory/thoughts-provider.js +603 -0
  73. package/.merlin-core/core/alkimia/output/formatter.js +464 -0
  74. package/.merlin-core/core/alkimia/security/content-sanitizer.js +140 -0
  75. package/.merlin-core/core/alkimia/skill-importer.js +440 -0
  76. package/.merlin-core/core/alkimia/squads/default/.synapse/manifest +17 -0
  77. package/.merlin-core/core/alkimia/utils/frontmatter.js +321 -0
  78. package/.merlin-core/core/alkimia/utils/tokens.js +24 -0
  79. package/.merlin-core/core/approval/README.md +16 -0
  80. package/.merlin-core/core/approval/approval-engine.js +380 -0
  81. package/.merlin-core/core/approval/channels/cli-channel.js +50 -0
  82. package/.merlin-core/core/config/README.md +17 -0
  83. package/.merlin-core/core/config/config-cache.js +182 -0
  84. package/.merlin-core/core/config/config-loader.js +279 -0
  85. package/.merlin-core/core/config/config-resolver.js +411 -0
  86. package/.merlin-core/core/config/env-interpolator.js +123 -0
  87. package/.merlin-core/core/config/merge-utils.js +102 -0
  88. package/.merlin-core/core/config/schemas/core-config.schema.json +41 -0
  89. package/.merlin-core/core/config/schemas/framework-config.schema.json +24 -0
  90. package/.merlin-core/core/config/schemas/local-config.schema.json +23 -0
  91. package/.merlin-core/core/config/schemas/project-config.schema.json +189 -0
  92. package/.merlin-core/core/docs-consistency.js +140 -0
  93. package/.merlin-core/core/events/event-bus.js +344 -0
  94. package/.merlin-core/core/events/hook-handler.js +419 -0
  95. package/.merlin-core/core/execution/README.md +17 -0
  96. package/.merlin-core/core/execution/attempt-journal.js +380 -0
  97. package/.merlin-core/core/execution/autonomous-build-loop.js +637 -0
  98. package/.merlin-core/core/execution/build-orchestrator.js +296 -0
  99. package/.merlin-core/core/execution/build-state-manager.js +196 -0
  100. package/.merlin-core/core/execution/context-injector.js +204 -0
  101. package/.merlin-core/core/execution/cron-engine.js +247 -0
  102. package/.merlin-core/core/execution/cron-expression.js +148 -0
  103. package/.merlin-core/core/execution/env-preflight.js +423 -0
  104. package/.merlin-core/core/execution/guardrail-engine.js +745 -0
  105. package/.merlin-core/core/execution/heartbeat-engine.js +198 -0
  106. package/.merlin-core/core/execution/model-router.js +282 -0
  107. package/.merlin-core/core/execution/parallel-executor.js +378 -0
  108. package/.merlin-core/core/execution/parallel-monitor.js +201 -0
  109. package/.merlin-core/core/execution/party-session.js +311 -0
  110. package/.merlin-core/core/execution/rate-limit-manager.js +152 -0
  111. package/.merlin-core/core/execution/result-aggregator.js +215 -0
  112. package/.merlin-core/core/execution/semantic-merge-engine.js +320 -0
  113. package/.merlin-core/core/execution/subagent-dispatcher.js +721 -0
  114. package/.merlin-core/core/execution/success-verifier.js +227 -0
  115. package/.merlin-core/core/execution/task-metadata.js +105 -0
  116. package/.merlin-core/core/execution/team-executor.js +195 -0
  117. package/.merlin-core/core/execution/two-tier-editor.js +290 -0
  118. package/.merlin-core/core/execution/version-snapshot.js +294 -0
  119. package/.merlin-core/core/execution/wave-executor.js +224 -0
  120. package/.merlin-core/core/health-check/health-engine.js +415 -0
  121. package/.merlin-core/core/licensing/activation.js +281 -0
  122. package/.merlin-core/core/licensing/crc.js +103 -0
  123. package/.merlin-core/core/licensing/entitlement.js +99 -0
  124. package/.merlin-core/core/licensing/fingerprint.js +104 -0
  125. package/.merlin-core/core/licensing/gate.js +133 -0
  126. package/.merlin-core/core/licensing/hmac.js +42 -0
  127. package/.merlin-core/core/licensing/key.js +144 -0
  128. package/.merlin-core/core/licensing/license.js +212 -0
  129. package/.merlin-core/core/mcp/README.md +16 -0
  130. package/.merlin-core/core/mcp/browser-capability.js +191 -0
  131. package/.merlin-core/core/mcp/capability-mapper.js +92 -0
  132. package/.merlin-core/core/mcp/mcp-connector.js +278 -0
  133. package/.merlin-core/core/mcp/mcp-registry.js +101 -0
  134. package/.merlin-core/core/orchestration/README.md +17 -0
  135. package/.merlin-core/core/orchestration/agent-invoker.js +456 -0
  136. package/.merlin-core/core/orchestration/condition-evaluator.js +250 -0
  137. package/.merlin-core/core/orchestration/decision-tree.js +192 -0
  138. package/.merlin-core/core/orchestration/executor-assignment.js +372 -0
  139. package/.merlin-core/core/orchestration/gate-evaluator.js +653 -0
  140. package/.merlin-core/core/orchestration/intent-classifier.js +579 -0
  141. package/.merlin-core/core/orchestration/lock-manager.js +308 -0
  142. package/.merlin-core/core/orchestration/master-orchestrator.js +363 -0
  143. package/.merlin-core/core/orchestration/phase-tool-masks.js +194 -0
  144. package/.merlin-core/core/orchestration/recovery-handler.js +402 -0
  145. package/.merlin-core/core/orchestration/reflect-checkpoint.js +431 -0
  146. package/.merlin-core/core/orchestration/session-state.js +430 -0
  147. package/.merlin-core/core/orchestration/skill-dispatcher.js +255 -0
  148. package/.merlin-core/core/orchestration/step-loader.js +226 -0
  149. package/.merlin-core/core/orchestration/workflow-executor.js +864 -0
  150. package/.merlin-core/core/process/executor.js +231 -0
  151. package/.merlin-core/core/process/process-file.js +50 -0
  152. package/.merlin-core/core/process/secret-scan.js +86 -0
  153. package/.merlin-core/core/process/signature.js +77 -0
  154. package/.merlin-core/core/quality-gates/README.md +17 -0
  155. package/.merlin-core/core/quality-gates/layer1-precommit.js +110 -0
  156. package/.merlin-core/core/quality-gates/layer2-pr-automation.js +116 -0
  157. package/.merlin-core/core/quality-gates/layer3-human-review.js +133 -0
  158. package/.merlin-core/core/registry/service-registry.js +140 -0
  159. package/.merlin-core/core-config.yaml +159 -0
  160. package/.merlin-core/development/README.md +17 -0
  161. package/.merlin-core/development/agents/README.md +16 -0
  162. package/.merlin-core/development/agents/analyst.md +214 -0
  163. package/.merlin-core/development/agents/architect.md +166 -0
  164. package/.merlin-core/development/agents/data-engineer.md +154 -0
  165. package/.merlin-core/development/agents/dev.md +203 -0
  166. package/.merlin-core/development/agents/devops.md +236 -0
  167. package/.merlin-core/development/agents/grimorio.md +125 -0
  168. package/.merlin-core/development/agents/merlin-master.md +173 -0
  169. package/.merlin-core/development/agents/meta.md +190 -0
  170. package/.merlin-core/development/agents/pm.md +145 -0
  171. package/.merlin-core/development/agents/po.md +172 -0
  172. package/.merlin-core/development/agents/qa.md +275 -0
  173. package/.merlin-core/development/agents/researcher.md +218 -0
  174. package/.merlin-core/development/agents/scout.md +179 -0
  175. package/.merlin-core/development/agents/sm.md +148 -0
  176. package/.merlin-core/development/agents/ux.md +169 -0
  177. package/.merlin-core/development/agents/web-researcher.md +203 -0
  178. package/.merlin-core/development/checklists/adversarial-review-checklist.md +70 -0
  179. package/.merlin-core/development/checklists/operations-ci-checklist.md +40 -0
  180. package/.merlin-core/development/checklists/operations-deploy-checklist.md +54 -0
  181. package/.merlin-core/development/checklists/operations-publish-checklist.md +47 -0
  182. package/.merlin-core/development/checklists/source-verification-checklist.md +38 -0
  183. package/.merlin-core/development/templates/HEARTBEAT-template.md +46 -0
  184. package/.merlin-core/development/templates/ears-requirements-template.md +93 -0
  185. package/.merlin-core/development/templates/handoff-template.md +50 -0
  186. package/.merlin-core/development/templates/prd-template.md +62 -0
  187. package/.merlin-core/development/templates/research-template.md +53 -0
  188. package/.merlin-core/development/templates/spec-template.md +84 -0
  189. package/.merlin-core/development/workflows/brownfield-discovery.yaml +166 -0
  190. package/.merlin-core/development/workflows/brownfield-service.yaml +52 -0
  191. package/.merlin-core/development/workflows/development-cycle.yaml +57 -0
  192. package/.merlin-core/development/workflows/epic-orchestration.yaml +47 -0
  193. package/.merlin-core/development/workflows/folloni-funnel.yaml +177 -0
  194. package/.merlin-core/development/workflows/greenfield-fullstack.yaml +167 -0
  195. package/.merlin-core/development/workflows/greenfield-service.yaml +56 -0
  196. package/.merlin-core/development/workflows/qa-loop.yaml +115 -0
  197. package/.merlin-core/development/workflows/spec-pipeline.yaml +185 -0
  198. package/.merlin-core/development/workflows/steps/folloni-01-research.yaml +35 -0
  199. package/.merlin-core/development/workflows/steps/folloni-02-architecture.yaml +41 -0
  200. package/.merlin-core/development/workflows/steps/folloni-03-implementation.yaml +52 -0
  201. package/.merlin-core/development/workflows/story-development-cycle.yaml +67 -0
  202. package/.merlin-core/docs/GUIDE.md +413 -0
  203. package/.merlin-core/docs/merlin-commands-guide-pt.md +183 -0
  204. package/.merlin-core/framework-config.yaml +148 -0
  205. package/.merlin-core/hooks/README.md +16 -0
  206. package/.merlin-core/hooks/precompact-memory-flush.js +69 -0
  207. package/.merlin-core/hooks/pretooluse-remote-approve.js +113 -0
  208. package/.merlin-core/hooks/spikes/spike-b-hook.js +70 -0
  209. package/.merlin-core/hooks/spikes/spike-b-stub.js +70 -0
  210. package/.merlin-core/index.js +91 -0
  211. package/.merlin-core/local-config.yaml.template +31 -0
  212. package/.merlin-core/mcp-servers/lsp-bridge/index.js +397 -0
  213. package/.merlin-core/modules/scraping/module.json +23 -0
  214. package/.merlin-core/project-config.yaml +89 -0
  215. package/.merlin-core/schemas/README.md +18 -0
  216. package/.merlin-core/schemas/agent-hook-schema.json +152 -0
  217. package/.merlin-core/schemas/agent-schema.json +31 -0
  218. package/.merlin-core/schemas/command-schema.json +18 -0
  219. package/.merlin-core/schemas/feedback-schema.json +36 -0
  220. package/.merlin-core/schemas/handoff-schema.json +19 -0
  221. package/.merlin-core/schemas/learning-schema.json +51 -0
  222. package/.merlin-core/schemas/module.schema.json +124 -0
  223. package/.merlin-core/schemas/must-haves-schema.json +95 -0
  224. package/.merlin-core/schemas/objective-schema.json +23 -0
  225. package/.merlin-core/schemas/plan-schema.json +20 -0
  226. package/.merlin-core/schemas/process-schema.json +82 -0
  227. package/.merlin-core/schemas/reminder-schema.json +20 -0
  228. package/.merlin-core/schemas/skill-eval-schema.json +92 -0
  229. package/.merlin-core/schemas/skill-schema.json +77 -0
  230. package/.merlin-core/schemas/workflow-schema.json +38 -0
  231. package/.merlin-core/skills/README.md +16 -0
  232. package/.merlin-core/skills/domain/azure-cloud/SKILL.md +211 -0
  233. package/.merlin-core/skills/domain/azure-cloud/references/appinsights-instrumentation.md +63 -0
  234. package/.merlin-core/skills/domain/azure-cloud/references/azure-compliance.md +99 -0
  235. package/.merlin-core/skills/domain/azure-cloud/references/azure-cost-optimization.md +419 -0
  236. package/.merlin-core/skills/domain/azure-cloud/references/azure-deploy.md +82 -0
  237. package/.merlin-core/skills/domain/azure-cloud/references/azure-diagnostics.md +130 -0
  238. package/.merlin-core/skills/domain/azure-cloud/references/azure-prepare.md +134 -0
  239. package/.merlin-core/skills/domain/azure-cloud/references/azure-quotas.md +290 -0
  240. package/.merlin-core/skills/domain/azure-cloud/references/azure-rbac.md +11 -0
  241. package/.merlin-core/skills/domain/azure-cloud/references/azure-resource-lookup.md +97 -0
  242. package/.merlin-core/skills/domain/azure-cloud/references/azure-resource-visualizer.md +178 -0
  243. package/.merlin-core/skills/domain/azure-cloud/references/azure-storage.md +91 -0
  244. package/.merlin-core/skills/domain/azure-cloud/references/azure-validate.md +58 -0
  245. package/.merlin-core/skills/domain/azure-cloud/references/entra-app-registration.md +192 -0
  246. package/.merlin-core/skills/domain/browser-automation/SKILL.md +311 -0
  247. package/.merlin-core/skills/domain/browser-automation/references/agent-browser-skill.md +632 -0
  248. package/.merlin-core/skills/domain/browser-automation/references/authentication.md +308 -0
  249. package/.merlin-core/skills/domain/browser-automation/references/commands.md +266 -0
  250. package/.merlin-core/skills/domain/browser-automation/references/profiling.md +120 -0
  251. package/.merlin-core/skills/domain/browser-automation/references/proxy-support.md +194 -0
  252. package/.merlin-core/skills/domain/browser-automation/references/session-management.md +194 -0
  253. package/.merlin-core/skills/domain/browser-automation/references/snapshot-refs.md +196 -0
  254. package/.merlin-core/skills/domain/browser-automation/references/video-recording.md +173 -0
  255. package/.merlin-core/skills/domain/browser-automation/templates/authenticated-session.sh +105 -0
  256. package/.merlin-core/skills/domain/browser-automation/templates/capture-workflow.sh +69 -0
  257. package/.merlin-core/skills/domain/browser-automation/templates/form-automation.sh +62 -0
  258. package/.merlin-core/skills/domain/digital-marketing/SKILL.md +292 -0
  259. package/.merlin-core/skills/domain/digital-marketing/references/content-strategy.md +320 -0
  260. package/.merlin-core/skills/domain/digital-marketing/references/copy-formats.md +298 -0
  261. package/.merlin-core/skills/domain/digital-marketing/references/copy-methodology.md +180 -0
  262. package/.merlin-core/skills/domain/digital-marketing/references/email-sequences.md +135 -0
  263. package/.merlin-core/skills/domain/digital-marketing/references/launch-strategy.md +213 -0
  264. package/.merlin-core/skills/domain/digital-marketing/references/pricing-strategy.md +160 -0
  265. package/.merlin-core/skills/domain/digital-marketing/references/programmatic-seo.md +237 -0
  266. package/.merlin-core/skills/domain/digital-marketing/references/revops-lifecycle.md +170 -0
  267. package/.merlin-core/skills/domain/digital-marketing/references/revops-operations.md +167 -0
  268. package/.merlin-core/skills/domain/digital-marketing/references/schema-markup.md +190 -0
  269. package/.merlin-core/skills/domain/digital-marketing/references/strategy-frameworks.md +324 -0
  270. package/.merlin-core/skills/domain/digital-marketing/references/traffic-management.md +350 -0
  271. package/.merlin-core/skills/domain/expo-native-ui/SKILL.md +348 -0
  272. package/.merlin-core/skills/domain/expo-native-ui/references/animations.md +220 -0
  273. package/.merlin-core/skills/domain/expo-native-ui/references/api-routes.md +361 -0
  274. package/.merlin-core/skills/domain/expo-native-ui/references/cicd-workflows.md +84 -0
  275. package/.merlin-core/skills/domain/expo-native-ui/references/controls.md +266 -0
  276. package/.merlin-core/skills/domain/expo-native-ui/references/data-fetching.md +553 -0
  277. package/.merlin-core/skills/domain/expo-native-ui/references/deployment-stores.md +1353 -0
  278. package/.merlin-core/skills/domain/expo-native-ui/references/deployment.md +183 -0
  279. package/.merlin-core/skills/domain/expo-native-ui/references/dev-client.md +166 -0
  280. package/.merlin-core/skills/domain/expo-native-ui/references/dom-components.md +410 -0
  281. package/.merlin-core/skills/domain/expo-native-ui/references/form-sheet.md +253 -0
  282. package/.merlin-core/skills/domain/expo-native-ui/references/gradients.md +117 -0
  283. package/.merlin-core/skills/domain/expo-native-ui/references/icons.md +218 -0
  284. package/.merlin-core/skills/domain/expo-native-ui/references/media.md +245 -0
  285. package/.merlin-core/skills/domain/expo-native-ui/references/platform-native.md +75 -0
  286. package/.merlin-core/skills/domain/expo-native-ui/references/route-structure.md +229 -0
  287. package/.merlin-core/skills/domain/expo-native-ui/references/search.md +249 -0
  288. package/.merlin-core/skills/domain/expo-native-ui/references/storage.md +121 -0
  289. package/.merlin-core/skills/domain/expo-native-ui/references/tabs.md +433 -0
  290. package/.merlin-core/skills/domain/expo-native-ui/references/tailwind-native.md +473 -0
  291. package/.merlin-core/skills/domain/expo-native-ui/references/toolbar-and-headers.md +284 -0
  292. package/.merlin-core/skills/domain/expo-native-ui/references/upgrading-guides.md +674 -0
  293. package/.merlin-core/skills/domain/expo-native-ui/references/upgrading.md +127 -0
  294. package/.merlin-core/skills/domain/expo-native-ui/references/visual-effects.md +199 -0
  295. package/.merlin-core/skills/domain/expo-native-ui/references/webgpu-three.md +605 -0
  296. package/.merlin-core/skills/domain/expo-native-ui/references/zoom-transitions.md +161 -0
  297. package/.merlin-core/skills/domain/marketing-ops/SKILL.md +117 -0
  298. package/.merlin-core/skills/domain/marketing-ops/references/_index.md +78 -0
  299. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ad-creative/references/generative-tools.md +19 -0
  300. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ad-creative/references/platform-specs.md +19 -0
  301. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ad-creative.md +251 -0
  302. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ads/references/ad-copy-templates.md +19 -0
  303. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ads/references/audience-targeting.md +19 -0
  304. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ads/references/conversion-tracking.md +19 -0
  305. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ads/references/platform-setup-checklists.md +19 -0
  306. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ads.md +322 -0
  307. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ai-seo/references/content-patterns.md +19 -0
  308. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ai-seo/references/content-types.md +19 -0
  309. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ai-seo/references/platform-ranking-factors.md +19 -0
  310. package/.merlin-core/skills/domain/marketing-ops/references/acquire/ai-seo.md +388 -0
  311. package/.merlin-core/skills/domain/marketing-ops/references/acquire/aso/references/apple-specs.md +19 -0
  312. package/.merlin-core/skills/domain/marketing-ops/references/acquire/aso/references/benchmarks.md +19 -0
  313. package/.merlin-core/skills/domain/marketing-ops/references/acquire/aso/references/google-play-specs.md +19 -0
  314. package/.merlin-core/skills/domain/marketing-ops/references/acquire/aso/references/report-template.md +19 -0
  315. package/.merlin-core/skills/domain/marketing-ops/references/acquire/aso/references/scoring-criteria.md +19 -0
  316. package/.merlin-core/skills/domain/marketing-ops/references/acquire/aso.md +316 -0
  317. package/.merlin-core/skills/domain/marketing-ops/references/acquire/co-marketing.md +305 -0
  318. package/.merlin-core/skills/domain/marketing-ops/references/acquire/community-marketing.md +169 -0
  319. package/.merlin-core/skills/domain/marketing-ops/references/acquire/competitor-profiling/references/templates.md +19 -0
  320. package/.merlin-core/skills/domain/marketing-ops/references/acquire/competitor-profiling/references/tool-reference.md +19 -0
  321. package/.merlin-core/skills/domain/marketing-ops/references/acquire/competitor-profiling.md +442 -0
  322. package/.merlin-core/skills/domain/marketing-ops/references/acquire/competitors/references/content-architecture.md +19 -0
  323. package/.merlin-core/skills/domain/marketing-ops/references/acquire/competitors/references/templates.md +19 -0
  324. package/.merlin-core/skills/domain/marketing-ops/references/acquire/competitors.md +281 -0
  325. package/.merlin-core/skills/domain/marketing-ops/references/acquire/content-strategy.md +16 -0
  326. package/.merlin-core/skills/domain/marketing-ops/references/acquire/directory-submissions/references/directory-list.md +19 -0
  327. package/.merlin-core/skills/domain/marketing-ops/references/acquire/directory-submissions/references/positioning-variations.md +19 -0
  328. package/.merlin-core/skills/domain/marketing-ops/references/acquire/directory-submissions/references/submission-tracker-template.md +19 -0
  329. package/.merlin-core/skills/domain/marketing-ops/references/acquire/directory-submissions.md +396 -0
  330. package/.merlin-core/skills/domain/marketing-ops/references/acquire/free-tools/references/tool-types.md +19 -0
  331. package/.merlin-core/skills/domain/marketing-ops/references/acquire/free-tools.md +196 -0
  332. package/.merlin-core/skills/domain/marketing-ops/references/acquire/image/references/ai-image-prompting.md +19 -0
  333. package/.merlin-core/skills/domain/marketing-ops/references/acquire/image.md +352 -0
  334. package/.merlin-core/skills/domain/marketing-ops/references/acquire/launch.md +18 -0
  335. package/.merlin-core/skills/domain/marketing-ops/references/acquire/lead-magnets/references/benchmarks.md +19 -0
  336. package/.merlin-core/skills/domain/marketing-ops/references/acquire/lead-magnets/references/format-guide.md +19 -0
  337. package/.merlin-core/skills/domain/marketing-ops/references/acquire/lead-magnets.md +333 -0
  338. package/.merlin-core/skills/domain/marketing-ops/references/acquire/programmatic-seo.md +16 -0
  339. package/.merlin-core/skills/domain/marketing-ops/references/acquire/schema.md +16 -0
  340. package/.merlin-core/skills/domain/marketing-ops/references/acquire/seo-audit/references/ai-writing-detection.md +19 -0
  341. package/.merlin-core/skills/domain/marketing-ops/references/acquire/seo-audit/references/international-seo.md +19 -0
  342. package/.merlin-core/skills/domain/marketing-ops/references/acquire/seo-audit.md +546 -0
  343. package/.merlin-core/skills/domain/marketing-ops/references/acquire/site-architecture/references/mermaid-templates.md +19 -0
  344. package/.merlin-core/skills/domain/marketing-ops/references/acquire/site-architecture/references/navigation-patterns.md +19 -0
  345. package/.merlin-core/skills/domain/marketing-ops/references/acquire/site-architecture/references/site-type-templates.md +19 -0
  346. package/.merlin-core/skills/domain/marketing-ops/references/acquire/site-architecture.md +371 -0
  347. package/.merlin-core/skills/domain/marketing-ops/references/acquire/social/references/platform-limits.md +19 -0
  348. package/.merlin-core/skills/domain/marketing-ops/references/acquire/social/references/platforms.md +19 -0
  349. package/.merlin-core/skills/domain/marketing-ops/references/acquire/social/references/post-templates.md +19 -0
  350. package/.merlin-core/skills/domain/marketing-ops/references/acquire/social/references/reverse-engineering.md +19 -0
  351. package/.merlin-core/skills/domain/marketing-ops/references/acquire/social/references/short-form-video.md +19 -0
  352. package/.merlin-core/skills/domain/marketing-ops/references/acquire/social.md +431 -0
  353. package/.merlin-core/skills/domain/marketing-ops/references/acquire/video/references/ai-video-prompting.md +19 -0
  354. package/.merlin-core/skills/domain/marketing-ops/references/acquire/video.md +353 -0
  355. package/.merlin-core/skills/domain/marketing-ops/references/activate/ab-testing/references/sample-size-guide.md +19 -0
  356. package/.merlin-core/skills/domain/marketing-ops/references/activate/ab-testing/references/test-templates.md +19 -0
  357. package/.merlin-core/skills/domain/marketing-ops/references/activate/ab-testing.md +379 -0
  358. package/.merlin-core/skills/domain/marketing-ops/references/activate/analytics/references/event-library.md +19 -0
  359. package/.merlin-core/skills/domain/marketing-ops/references/activate/analytics/references/ga4-implementation.md +19 -0
  360. package/.merlin-core/skills/domain/marketing-ops/references/activate/analytics/references/gtm-implementation.md +19 -0
  361. package/.merlin-core/skills/domain/marketing-ops/references/activate/analytics.md +323 -0
  362. package/.merlin-core/skills/domain/marketing-ops/references/activate/copy-editing.md +18 -0
  363. package/.merlin-core/skills/domain/marketing-ops/references/activate/copywriting.md +18 -0
  364. package/.merlin-core/skills/domain/marketing-ops/references/activate/cro/references/experiments.md +19 -0
  365. package/.merlin-core/skills/domain/marketing-ops/references/activate/cro/references/form.md +19 -0
  366. package/.merlin-core/skills/domain/marketing-ops/references/activate/cro.md +211 -0
  367. package/.merlin-core/skills/domain/marketing-ops/references/activate/emails.md +18 -0
  368. package/.merlin-core/skills/domain/marketing-ops/references/activate/paywalls/references/experiments.md +19 -0
  369. package/.merlin-core/skills/domain/marketing-ops/references/activate/paywalls.md +255 -0
  370. package/.merlin-core/skills/domain/marketing-ops/references/activate/popups.md +518 -0
  371. package/.merlin-core/skills/domain/marketing-ops/references/activate/pricing.md +18 -0
  372. package/.merlin-core/skills/domain/marketing-ops/references/activate/sales-enablement/references/deck-frameworks.md +19 -0
  373. package/.merlin-core/skills/domain/marketing-ops/references/activate/sales-enablement/references/demo-scripts.md +19 -0
  374. package/.merlin-core/skills/domain/marketing-ops/references/activate/sales-enablement/references/objection-library.md +19 -0
  375. package/.merlin-core/skills/domain/marketing-ops/references/activate/sales-enablement/references/one-pager-templates.md +19 -0
  376. package/.merlin-core/skills/domain/marketing-ops/references/activate/sales-enablement.md +371 -0
  377. package/.merlin-core/skills/domain/marketing-ops/references/activate/signup.md +406 -0
  378. package/.merlin-core/skills/domain/marketing-ops/references/expand/co-marketing.md +18 -0
  379. package/.merlin-core/skills/domain/marketing-ops/references/expand/community-marketing.md +18 -0
  380. package/.merlin-core/skills/domain/marketing-ops/references/expand/referrals/references/affiliate-programs.md +19 -0
  381. package/.merlin-core/skills/domain/marketing-ops/references/expand/referrals/references/program-examples.md +19 -0
  382. package/.merlin-core/skills/domain/marketing-ops/references/expand/referrals.md +278 -0
  383. package/.merlin-core/skills/domain/marketing-ops/references/foundation/customer-research/references/source-guides.md +425 -0
  384. package/.merlin-core/skills/domain/marketing-ops/references/foundation/customer-research.md +284 -0
  385. package/.merlin-core/skills/domain/marketing-ops/references/foundation/marketing-ideas/references/ideas-by-category.md +216 -0
  386. package/.merlin-core/skills/domain/marketing-ops/references/foundation/marketing-ideas.md +188 -0
  387. package/.merlin-core/skills/domain/marketing-ops/references/foundation/marketing-psychology.md +532 -0
  388. package/.merlin-core/skills/domain/marketing-ops/references/foundation/product-marketing.md +276 -0
  389. package/.merlin-core/skills/domain/marketing-ops/references/retain/churn-prevention/references/cancel-flow-patterns.md +19 -0
  390. package/.merlin-core/skills/domain/marketing-ops/references/retain/churn-prevention/references/dunning-playbook.md +19 -0
  391. package/.merlin-core/skills/domain/marketing-ops/references/retain/churn-prevention.md +442 -0
  392. package/.merlin-core/skills/domain/marketing-ops/references/retain/onboarding/references/experiments.md +19 -0
  393. package/.merlin-core/skills/domain/marketing-ops/references/retain/onboarding.md +243 -0
  394. package/.merlin-core/skills/domain/marketing-ops/references/retain/revops-lifecycle.md +18 -0
  395. package/.merlin-core/skills/domain/marketing-ops/references/retain/revops-operations.md +18 -0
  396. package/.merlin-core/skills/domain/n8n-automation/SKILL.md +149 -0
  397. package/.merlin-core/skills/domain/n8n-automation/references/code-javascript.md +3744 -0
  398. package/.merlin-core/skills/domain/n8n-automation/references/code-python.md +3293 -0
  399. package/.merlin-core/skills/domain/n8n-automation/references/expression-syntax.md +1662 -0
  400. package/.merlin-core/skills/domain/n8n-automation/references/mcp-tools-expert.md +2111 -0
  401. package/.merlin-core/skills/domain/n8n-automation/references/node-configuration.md +2523 -0
  402. package/.merlin-core/skills/domain/n8n-automation/references/validation-expert.md +2491 -0
  403. package/.merlin-core/skills/domain/n8n-automation/references/workflow-patterns.md +4624 -0
  404. package/.merlin-core/skills/domain/ops-manual/SKILL.md +225 -0
  405. package/.merlin-core/skills/domain/ops-manual/references/elicitation-questions.md +141 -0
  406. package/.merlin-core/skills/domain/ops-manual/references/external-skills-registry.md +63 -0
  407. package/.merlin-core/skills/domain/ops-manual/references/operations-template.yaml +132 -0
  408. package/.merlin-core/skills/domain/remotion-best-practices/SKILL.md +99 -0
  409. package/.merlin-core/skills/domain/remotion-best-practices/rules/3d.md +86 -0
  410. package/.merlin-core/skills/domain/remotion-best-practices/rules/animations.md +27 -0
  411. package/.merlin-core/skills/domain/remotion-best-practices/rules/assets/charts-bar-chart.tsx +173 -0
  412. package/.merlin-core/skills/domain/remotion-best-practices/rules/assets/text-animations-typewriter.tsx +100 -0
  413. package/.merlin-core/skills/domain/remotion-best-practices/rules/assets/text-animations-word-highlight.tsx +108 -0
  414. package/.merlin-core/skills/domain/remotion-best-practices/rules/assets.md +78 -0
  415. package/.merlin-core/skills/domain/remotion-best-practices/rules/audio.md +172 -0
  416. package/.merlin-core/skills/domain/remotion-best-practices/rules/calculate-metadata.md +131 -0
  417. package/.merlin-core/skills/domain/remotion-best-practices/rules/can-decode.md +75 -0
  418. package/.merlin-core/skills/domain/remotion-best-practices/rules/charts.md +68 -0
  419. package/.merlin-core/skills/domain/remotion-best-practices/rules/compositions.md +154 -0
  420. package/.merlin-core/skills/domain/remotion-best-practices/rules/display-captions.md +126 -0
  421. package/.merlin-core/skills/domain/remotion-best-practices/rules/extract-frames.md +229 -0
  422. package/.merlin-core/skills/domain/remotion-best-practices/rules/fonts.md +152 -0
  423. package/.merlin-core/skills/domain/remotion-best-practices/rules/get-audio-duration.md +58 -0
  424. package/.merlin-core/skills/domain/remotion-best-practices/rules/get-video-dimensions.md +68 -0
  425. package/.merlin-core/skills/domain/remotion-best-practices/rules/get-video-duration.md +58 -0
  426. package/.merlin-core/skills/domain/remotion-best-practices/rules/gifs.md +144 -0
  427. package/.merlin-core/skills/domain/remotion-best-practices/rules/images.md +134 -0
  428. package/.merlin-core/skills/domain/remotion-best-practices/rules/import-srt-captions.md +67 -0
  429. package/.merlin-core/skills/domain/remotion-best-practices/rules/lottie.md +70 -0
  430. package/.merlin-core/skills/domain/remotion-best-practices/rules/maps.md +414 -0
  431. package/.merlin-core/skills/domain/remotion-best-practices/rules/measuring-dom-nodes.md +34 -0
  432. package/.merlin-core/skills/domain/remotion-best-practices/rules/measuring-text.md +143 -0
  433. package/.merlin-core/skills/domain/remotion-best-practices/rules/parameters.md +109 -0
  434. package/.merlin-core/skills/domain/remotion-best-practices/rules/sequencing.md +118 -0
  435. package/.merlin-core/skills/domain/remotion-best-practices/rules/tailwind.md +11 -0
  436. package/.merlin-core/skills/domain/remotion-best-practices/rules/text-animations.md +20 -0
  437. package/.merlin-core/skills/domain/remotion-best-practices/rules/timing.md +179 -0
  438. package/.merlin-core/skills/domain/remotion-best-practices/rules/transcribe-captions.md +19 -0
  439. package/.merlin-core/skills/domain/remotion-best-practices/rules/transitions.md +137 -0
  440. package/.merlin-core/skills/domain/remotion-best-practices/rules/transparent-videos.md +106 -0
  441. package/.merlin-core/skills/domain/remotion-best-practices/rules/trimming.md +51 -0
  442. package/.merlin-core/skills/domain/remotion-best-practices/rules/videos.md +171 -0
  443. package/.merlin-core/skills/domain/resend-email/SKILL.md +377 -0
  444. package/.merlin-core/skills/general/adversarial-review/SKILL.md +144 -0
  445. package/.merlin-core/skills/general/api-design/SKILL.md +513 -0
  446. package/.merlin-core/skills/general/apify-scrape/SKILL.md +137 -0
  447. package/.merlin-core/skills/general/apify-scrape/scripts/apify-scrape.sh +68 -0
  448. package/.merlin-core/skills/general/backup/SKILL.md +87 -0
  449. package/.merlin-core/skills/general/blkskrn/SKILL.md +392 -0
  450. package/.merlin-core/skills/general/blkskrn/references/animation-patterns.md +521 -0
  451. package/.merlin-core/skills/general/blkskrn/references/design-system.md +637 -0
  452. package/.merlin-core/skills/general/blkskrn/references/html-templates.md +440 -0
  453. package/.merlin-core/skills/general/blkskrn/references/presenter-template.md +45 -0
  454. package/.merlin-core/skills/general/blkskrn/references/slide-types.md +424 -0
  455. package/.merlin-core/skills/general/blkskrn/scripts/canvas-manager.js +502 -0
  456. package/.merlin-core/skills/general/blkskrn/scripts/presenter.js +90 -0
  457. package/.merlin-core/skills/general/blkskrn/templates/presenter.html +273 -0
  458. package/.merlin-core/skills/general/blkskrn/templates/slide-base.html +277 -0
  459. package/.merlin-core/skills/general/blkskrn/templates/viewer.html +165 -0
  460. package/.merlin-core/skills/general/browser-takeover/SKILL.md +53 -0
  461. package/.merlin-core/skills/general/claude-api/SKILL.md +90 -0
  462. package/.merlin-core/skills/general/code-javascript/SKILL.md +268 -0
  463. package/.merlin-core/skills/general/code-python/SKILL.md +424 -0
  464. package/.merlin-core/skills/general/code-style/SKILL.md +97 -0
  465. package/.merlin-core/skills/general/code-typescript/SKILL.md +361 -0
  466. package/.merlin-core/skills/general/cold-email/SKILL.md +164 -0
  467. package/.merlin-core/skills/general/cold-email/references/benchmarks.md +18 -0
  468. package/.merlin-core/skills/general/cold-email/references/follow-up-sequences.md +18 -0
  469. package/.merlin-core/skills/general/cold-email/references/frameworks.md +18 -0
  470. package/.merlin-core/skills/general/cold-email/references/personalization.md +18 -0
  471. package/.merlin-core/skills/general/cold-email/references/subject-lines.md +18 -0
  472. package/.merlin-core/skills/general/container-security/SKILL.md +462 -0
  473. package/.merlin-core/skills/general/context-management/SKILL.md +79 -0
  474. package/.merlin-core/skills/general/copy-editing/SKILL.md +501 -0
  475. package/.merlin-core/skills/general/copy-editing/references/checklist.md +18 -0
  476. package/.merlin-core/skills/general/copy-editing/references/content-refresh.md +18 -0
  477. package/.merlin-core/skills/general/copy-editing/references/plain-english-alternatives.md +18 -0
  478. package/.merlin-core/skills/general/copywriting/SKILL.md +294 -0
  479. package/.merlin-core/skills/general/copywriting/references/copy-frameworks.md +392 -0
  480. package/.merlin-core/skills/general/copywriting/references/natural-transitions.md +276 -0
  481. package/.merlin-core/skills/general/database/SKILL.md +561 -0
  482. package/.merlin-core/skills/general/database/references/postgres-concurrency.md +182 -0
  483. package/.merlin-core/skills/general/database/references/postgres-connections.md +97 -0
  484. package/.merlin-core/skills/general/database/references/postgres-data-patterns.md +159 -0
  485. package/.merlin-core/skills/general/database/references/postgres-monitoring.md +136 -0
  486. package/.merlin-core/skills/general/database/references/postgres-rls.md +140 -0
  487. package/.merlin-core/skills/general/database-provision/SKILL.md +56 -0
  488. package/.merlin-core/skills/general/deploy/SKILL.md +65 -0
  489. package/.merlin-core/skills/general/design-inspiration/SKILL.md +146 -0
  490. package/.merlin-core/skills/general/design-palette/SKILL.md +99 -0
  491. package/.merlin-core/skills/general/design-palette/references/full-palettes.md +144 -0
  492. package/.merlin-core/skills/general/design-system/SKILL.md +94 -0
  493. package/.merlin-core/skills/general/design-typography/SKILL.md +115 -0
  494. package/.merlin-core/skills/general/design-typography/references/full-pairings.md +144 -0
  495. package/.merlin-core/skills/general/design-ux-patterns/SKILL.md +155 -0
  496. package/.merlin-core/skills/general/design-ux-patterns/references/charts-data-guidelines.md +197 -0
  497. package/.merlin-core/skills/general/design-ux-patterns/references/landing-patterns.md +199 -0
  498. package/.merlin-core/skills/general/design-ux-patterns/references/professional-ui-checklist.md +56 -0
  499. package/.merlin-core/skills/general/design-ux-patterns/references/style-catalog.md +89 -0
  500. package/.merlin-core/skills/general/design-ux-patterns/references/ux-guidelines.md +837 -0
  501. package/.merlin-core/skills/general/discover-cloud/SKILL.md +108 -0
  502. package/.merlin-core/skills/general/doc-sync/SKILL.md +52 -0
  503. package/.merlin-core/skills/general/document-sharding/SKILL.md +53 -0
  504. package/.merlin-core/skills/general/docx/SKILL.md +418 -0
  505. package/.merlin-core/skills/general/docx/references/windows-setup.md +27 -0
  506. package/.merlin-core/skills/general/docx/scripts/__init__.py +1 -0
  507. package/.merlin-core/skills/general/docx/scripts/accept_changes.py +135 -0
  508. package/.merlin-core/skills/general/docx/scripts/comment.py +318 -0
  509. package/.merlin-core/skills/general/docx/scripts/office/__init__.py +0 -0
  510. package/.merlin-core/skills/general/docx/scripts/office/helpers/__init__.py +0 -0
  511. package/.merlin-core/skills/general/docx/scripts/office/helpers/merge_runs.py +199 -0
  512. package/.merlin-core/skills/general/docx/scripts/office/helpers/simplify_redlines.py +197 -0
  513. package/.merlin-core/skills/general/docx/scripts/office/pack.py +159 -0
  514. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  515. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  516. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  517. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  518. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  519. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  520. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  521. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  522. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  523. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  524. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  525. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  526. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  527. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  528. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  529. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  530. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  531. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  532. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  533. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  534. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  535. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  536. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  537. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  538. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  539. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  540. package/.merlin-core/skills/general/docx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  541. package/.merlin-core/skills/general/docx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  542. package/.merlin-core/skills/general/docx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  543. package/.merlin-core/skills/general/docx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  544. package/.merlin-core/skills/general/docx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  545. package/.merlin-core/skills/general/docx/scripts/office/schemas/mce/mc.xsd +75 -0
  546. package/.merlin-core/skills/general/docx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  547. package/.merlin-core/skills/general/docx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  548. package/.merlin-core/skills/general/docx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  549. package/.merlin-core/skills/general/docx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  550. package/.merlin-core/skills/general/docx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  551. package/.merlin-core/skills/general/docx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  552. package/.merlin-core/skills/general/docx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  553. package/.merlin-core/skills/general/docx/scripts/office/soffice.py +183 -0
  554. package/.merlin-core/skills/general/docx/scripts/office/unpack.py +132 -0
  555. package/.merlin-core/skills/general/docx/scripts/office/validate.py +111 -0
  556. package/.merlin-core/skills/general/docx/scripts/office/validators/__init__.py +15 -0
  557. package/.merlin-core/skills/general/docx/scripts/office/validators/base.py +847 -0
  558. package/.merlin-core/skills/general/docx/scripts/office/validators/docx.py +446 -0
  559. package/.merlin-core/skills/general/docx/scripts/office/validators/pptx.py +275 -0
  560. package/.merlin-core/skills/general/docx/scripts/office/validators/redlining.py +247 -0
  561. package/.merlin-core/skills/general/docx/scripts/templates/comments.xml +3 -0
  562. package/.merlin-core/skills/general/docx/scripts/templates/commentsExtended.xml +3 -0
  563. package/.merlin-core/skills/general/docx/scripts/templates/commentsExtensible.xml +3 -0
  564. package/.merlin-core/skills/general/docx/scripts/templates/commentsIds.xml +3 -0
  565. package/.merlin-core/skills/general/docx/scripts/templates/people.xml +3 -0
  566. package/.merlin-core/skills/general/elicitation/SKILL.md +188 -0
  567. package/.merlin-core/skills/general/engineering-audit/SKILL.md +122 -0
  568. package/.merlin-core/skills/general/find-and-edit/SKILL.md +102 -0
  569. package/.merlin-core/skills/general/first-party-docs/SKILL.md +51 -0
  570. package/.merlin-core/skills/general/frontend-design/SKILL.md +204 -0
  571. package/.merlin-core/skills/general/guardrails/SKILL.md +144 -0
  572. package/.merlin-core/skills/general/image-gen/SKILL.md +49 -0
  573. package/.merlin-core/skills/general/learning-capture/SKILL.md +192 -0
  574. package/.merlin-core/skills/general/lgpd-compliance-audit/SKILL.md +448 -0
  575. package/.merlin-core/skills/general/load-testing/SKILL.md +114 -0
  576. package/.merlin-core/skills/general/load-testing/docker/Dockerfile.dashboard +21 -0
  577. package/.merlin-core/skills/general/load-testing/docker/docker-compose.locust.yml +39 -0
  578. package/.merlin-core/skills/general/load-testing/requirements.txt +1 -0
  579. package/.merlin-core/skills/general/load-testing/scripts/compare_baseline.py +172 -0
  580. package/.merlin-core/skills/general/load-testing/scripts/run_local.py +245 -0
  581. package/.merlin-core/skills/general/load-testing/templates/load_shape_stepped.py +35 -0
  582. package/.merlin-core/skills/general/load-testing/templates/locustfile_dashboard.py +47 -0
  583. package/.merlin-core/skills/general/load-testing/templates/threshold_hook.py +36 -0
  584. package/.merlin-core/skills/general/mage-beauty/SKILL.md +89 -0
  585. package/.merlin-core/skills/general/mage-beauty/references/anti-patterns.md +148 -0
  586. package/.merlin-core/skills/general/mage-beauty/references/color-and-contrast.md +87 -0
  587. package/.merlin-core/skills/general/mage-beauty/references/interaction-design.md +99 -0
  588. package/.merlin-core/skills/general/mage-beauty/references/motion-design.md +90 -0
  589. package/.merlin-core/skills/general/mage-beauty/references/remotion-bridge.md +187 -0
  590. package/.merlin-core/skills/general/mage-beauty/references/responsive-and-multi-format.md +98 -0
  591. package/.merlin-core/skills/general/mage-beauty/references/spatial-design.md +88 -0
  592. package/.merlin-core/skills/general/mage-beauty/references/typography.md +60 -0
  593. package/.merlin-core/skills/general/mage-beauty/references/verb-adapt.md +102 -0
  594. package/.merlin-core/skills/general/mage-beauty/references/verb-animate.md +97 -0
  595. package/.merlin-core/skills/general/mage-beauty/references/verb-audit.md +99 -0
  596. package/.merlin-core/skills/general/mage-beauty/references/verb-bolder.md +94 -0
  597. package/.merlin-core/skills/general/mage-beauty/references/verb-cinematic.md +128 -0
  598. package/.merlin-core/skills/general/mage-beauty/references/verb-clarify.md +107 -0
  599. package/.merlin-core/skills/general/mage-beauty/references/verb-colorize.md +106 -0
  600. package/.merlin-core/skills/general/mage-beauty/references/verb-critique.md +88 -0
  601. package/.merlin-core/skills/general/mage-beauty/references/verb-delight.md +98 -0
  602. package/.merlin-core/skills/general/mage-beauty/references/verb-distill.md +97 -0
  603. package/.merlin-core/skills/general/mage-beauty/references/verb-harden.md +79 -0
  604. package/.merlin-core/skills/general/mage-beauty/references/verb-layout.md +104 -0
  605. package/.merlin-core/skills/general/mage-beauty/references/verb-onboard.md +98 -0
  606. package/.merlin-core/skills/general/mage-beauty/references/verb-optimize.md +124 -0
  607. package/.merlin-core/skills/general/mage-beauty/references/verb-overdrive.md +105 -0
  608. package/.merlin-core/skills/general/mage-beauty/references/verb-polish.md +91 -0
  609. package/.merlin-core/skills/general/mage-beauty/references/verb-quieter.md +95 -0
  610. package/.merlin-core/skills/general/mage-beauty/references/verb-rebrand.md +127 -0
  611. package/.merlin-core/skills/general/mage-beauty/references/verb-shape.md +160 -0
  612. package/.merlin-core/skills/general/mage-beauty/references/verb-typeset.md +109 -0
  613. package/.merlin-core/skills/general/mage-beauty/references/voice-and-microcopy.md +137 -0
  614. package/.merlin-core/skills/general/mcp-builder/SKILL.md +92 -0
  615. package/.merlin-core/skills/general/network-debug/SKILL.md +51 -0
  616. package/.merlin-core/skills/general/next-best-practices/SKILL.md +177 -0
  617. package/.merlin-core/skills/general/next-best-practices/references/async-patterns.md +87 -0
  618. package/.merlin-core/skills/general/next-best-practices/references/bundling.md +182 -0
  619. package/.merlin-core/skills/general/next-best-practices/references/data-patterns.md +306 -0
  620. package/.merlin-core/skills/general/next-best-practices/references/debug-tricks.md +125 -0
  621. package/.merlin-core/skills/general/next-best-practices/references/directives.md +74 -0
  622. package/.merlin-core/skills/general/next-best-practices/references/error-handling.md +232 -0
  623. package/.merlin-core/skills/general/next-best-practices/references/file-conventions.md +141 -0
  624. package/.merlin-core/skills/general/next-best-practices/references/font.md +257 -0
  625. package/.merlin-core/skills/general/next-best-practices/references/functions.md +108 -0
  626. package/.merlin-core/skills/general/next-best-practices/references/hydration-error.md +88 -0
  627. package/.merlin-core/skills/general/next-best-practices/references/image.md +179 -0
  628. package/.merlin-core/skills/general/next-best-practices/references/metadata.md +296 -0
  629. package/.merlin-core/skills/general/next-best-practices/references/parallel-routes.md +298 -0
  630. package/.merlin-core/skills/general/next-best-practices/references/route-handlers.md +146 -0
  631. package/.merlin-core/skills/general/next-best-practices/references/rsc-boundaries.md +164 -0
  632. package/.merlin-core/skills/general/next-best-practices/references/runtime-selection.md +40 -0
  633. package/.merlin-core/skills/general/next-best-practices/references/scripts.md +141 -0
  634. package/.merlin-core/skills/general/next-best-practices/references/self-hosting.md +384 -0
  635. package/.merlin-core/skills/general/next-best-practices/references/suspense-boundaries.md +67 -0
  636. package/.merlin-core/skills/general/next-steps/SKILL.md +43 -0
  637. package/.merlin-core/skills/general/party-mode/SKILL.md +57 -0
  638. package/.merlin-core/skills/general/pdf/SKILL.md +298 -0
  639. package/.merlin-core/skills/general/pdf/references/forms.md +312 -0
  640. package/.merlin-core/skills/general/pdf/references/reference.md +640 -0
  641. package/.merlin-core/skills/general/pdf/references/windows-setup.md +40 -0
  642. package/.merlin-core/skills/general/pdf/scripts/check_bounding_boxes.py +65 -0
  643. package/.merlin-core/skills/general/pdf/scripts/check_fillable_fields.py +11 -0
  644. package/.merlin-core/skills/general/pdf/scripts/convert_pdf_to_images.py +33 -0
  645. package/.merlin-core/skills/general/pdf/scripts/create_validation_image.py +37 -0
  646. package/.merlin-core/skills/general/pdf/scripts/extract_form_field_info.py +122 -0
  647. package/.merlin-core/skills/general/pdf/scripts/extract_form_structure.py +115 -0
  648. package/.merlin-core/skills/general/pdf/scripts/fill_fillable_fields.py +98 -0
  649. package/.merlin-core/skills/general/pdf/scripts/fill_pdf_form_with_annotations.py +107 -0
  650. package/.merlin-core/skills/general/pptx/SKILL.md +133 -0
  651. package/.merlin-core/skills/general/pptx/references/editing.md +213 -0
  652. package/.merlin-core/skills/general/pptx/references/pptxgenjs.md +581 -0
  653. package/.merlin-core/skills/general/pptx/references/windows-setup.md +27 -0
  654. package/.merlin-core/skills/general/pptx/scripts/__init__.py +0 -0
  655. package/.merlin-core/skills/general/pptx/scripts/add_slide.py +195 -0
  656. package/.merlin-core/skills/general/pptx/scripts/clean.py +286 -0
  657. package/.merlin-core/skills/general/pptx/scripts/thumbnail.py +289 -0
  658. package/.merlin-core/skills/general/property-testing/SKILL.md +214 -0
  659. package/.merlin-core/skills/general/purge-leaked-secret/SKILL.md +383 -0
  660. package/.merlin-core/skills/general/reflection/SKILL.md +100 -0
  661. package/.merlin-core/skills/general/secret-safe-commit/SKILL.md +246 -0
  662. package/.merlin-core/skills/general/secret-safe-commit/templates/.gitleaks.toml +91 -0
  663. package/.merlin-core/skills/general/secret-safe-commit/templates/.pre-commit-config.yaml +57 -0
  664. package/.merlin-core/skills/general/secret-safe-commit/templates/secret-scan.yml +48 -0
  665. package/.merlin-core/skills/general/semantic-search/SKILL.md +79 -0
  666. package/.merlin-core/skills/general/skill-creator/SKILL.md +342 -0
  667. package/.merlin-core/skills/general/skill-creator/agents/analyzer.md +283 -0
  668. package/.merlin-core/skills/general/skill-creator/agents/comparator.md +211 -0
  669. package/.merlin-core/skills/general/skill-creator/agents/grader.md +227 -0
  670. package/.merlin-core/skills/general/skill-creator/assets/eval_review.html +146 -0
  671. package/.merlin-core/skills/general/skill-creator/eval-viewer/generate_review.py +471 -0
  672. package/.merlin-core/skills/general/skill-creator/eval-viewer/viewer.html +1325 -0
  673. package/.merlin-core/skills/general/skill-creator/references/schemas.md +439 -0
  674. package/.merlin-core/skills/general/skill-creator/scripts/__init__.py +0 -0
  675. package/.merlin-core/skills/general/skill-creator/scripts/aggregate_benchmark.py +401 -0
  676. package/.merlin-core/skills/general/skill-creator/scripts/generate_report.py +326 -0
  677. package/.merlin-core/skills/general/skill-creator/scripts/improve_description.py +247 -0
  678. package/.merlin-core/skills/general/skill-creator/scripts/package_skill.py +136 -0
  679. package/.merlin-core/skills/general/skill-creator/scripts/quick_validate.py +103 -0
  680. package/.merlin-core/skills/general/skill-creator/scripts/run_eval.py +310 -0
  681. package/.merlin-core/skills/general/skill-creator/scripts/run_loop.py +328 -0
  682. package/.merlin-core/skills/general/skill-creator/scripts/utils.py +47 -0
  683. package/.merlin-core/skills/general/start-here/SKILL.md +63 -0
  684. package/.merlin-core/skills/general/start-here/recipes.json +758 -0
  685. package/.merlin-core/skills/general/start-here/recipes.schema.json +57 -0
  686. package/.merlin-core/skills/general/static-analysis/SKILL.md +151 -0
  687. package/.merlin-core/skills/general/tailwind-design-system/SKILL.md +201 -0
  688. package/.merlin-core/skills/general/tailwind-design-system/references/advanced-v4.md +152 -0
  689. package/.merlin-core/skills/general/tailwind-design-system/references/component-patterns.md +353 -0
  690. package/.merlin-core/skills/general/teach-method/SKILL.md +86 -0
  691. package/.merlin-core/skills/general/team-execution/SKILL.md +67 -0
  692. package/.merlin-core/skills/general/testing/SKILL.md +412 -0
  693. package/.merlin-core/skills/general/token-economy/SKILL.md +55 -0
  694. package/.merlin-core/skills/general/vps-security-hardening/SKILL.md +406 -0
  695. package/.merlin-core/skills/general/web-quality/SKILL.md +180 -0
  696. package/.merlin-core/skills/general/webapp-testing/SKILL.md +153 -0
  697. package/.merlin-core/skills/general/webapp-testing/scripts/screenshot_compare.py +72 -0
  698. package/.merlin-core/skills/general/webapp-testing/scripts/with_server.py +103 -0
  699. package/.merlin-core/skills/general/xlsx/SKILL.md +167 -0
  700. package/.merlin-core/skills/general/xlsx/references/nodejs-sheetjs-styled-reports.md +141 -0
  701. package/.merlin-core/skills/general/xlsx/references/windows-setup.md +17 -0
  702. package/.merlin-core/skills/general/xlsx/scripts/recalc.py +184 -0
  703. package/.merlin-core/skills/general/xlsx/scripts/styled-report.js +130 -0
  704. package/.merlin-core/skills/general/yolo-mode/SKILL.md +60 -0
  705. package/.merlin-core/skills/general/youtube-transcript/SKILL.md +177 -0
  706. package/.merlin-core/skills/general/youtube-transcript/scripts/fetch_transcript.py +188 -0
  707. package/.merlin-core/skills/general/youtube-transcript/scripts/gladia_transcribe.mjs +230 -0
  708. package/.merlin-core/tools/commands/activate.js +72 -0
  709. package/.merlin-core/tools/commands/archive-thoughts.js +181 -0
  710. package/.merlin-core/tools/commands/backup.js +156 -0
  711. package/.merlin-core/tools/commands/certify-process.js +196 -0
  712. package/.merlin-core/tools/commands/convert.js +87 -0
  713. package/.merlin-core/tools/commands/cron.js +147 -0
  714. package/.merlin-core/tools/commands/disable.js +73 -0
  715. package/.merlin-core/tools/commands/doc-sync.js +127 -0
  716. package/.merlin-core/tools/commands/eval-skill.js +193 -0
  717. package/.merlin-core/tools/commands/frontmatter.js +49 -0
  718. package/.merlin-core/tools/commands/heartbeat.js +43 -0
  719. package/.merlin-core/tools/commands/index-thoughts.js +35 -0
  720. package/.merlin-core/tools/commands/install-remote-approve.js +184 -0
  721. package/.merlin-core/tools/commands/install.js +81 -0
  722. package/.merlin-core/tools/commands/lib/__verify__/diff-reports.js +170 -0
  723. package/.merlin-core/tools/commands/lib/fs-safe.js +186 -0
  724. package/.merlin-core/tools/commands/lib/preflight.js +607 -0
  725. package/.merlin-core/tools/commands/lib/preserve.js +232 -0
  726. package/.merlin-core/tools/commands/lib/project-config.template.yaml +69 -0
  727. package/.merlin-core/tools/commands/lib/report.js +231 -0
  728. package/.merlin-core/tools/commands/lib/settings-merge.js +134 -0
  729. package/.merlin-core/tools/commands/license.js +52 -0
  730. package/.merlin-core/tools/commands/list.js +125 -0
  731. package/.merlin-core/tools/commands/migrate-alkimia.js +271 -0
  732. package/.merlin-core/tools/commands/modules.js +68 -0
  733. package/.merlin-core/tools/commands/provision.js +83 -0
  734. package/.merlin-core/tools/commands/prune-feedback.js +114 -0
  735. package/.merlin-core/tools/commands/run-process.js +28 -0
  736. package/.merlin-core/tools/commands/state.js +79 -0
  737. package/.merlin-core/tools/commands/sync-bridges.js +197 -0
  738. package/.merlin-core/tools/commands/upgrade.js +1135 -0
  739. package/.merlin-core/tools/commands/validate-recipes.js +218 -0
  740. package/.merlin-core/tools/commands/validate.js +159 -0
  741. package/.merlin-core/tools/commands/yolo.js +82 -0
  742. package/.merlin-core/tools/compose-rules.mjs +179 -0
  743. package/.merlin-core/tools/disable-module.mjs +150 -0
  744. package/.merlin-core/tools/lib/deployer.mjs +131 -0
  745. package/.merlin-core/tools/lib/modules-activation.mjs +225 -0
  746. package/.merlin-core/tools/merlin-tools.js +153 -0
  747. package/.merlin-core/tools/migrate-frontmatter-v3.js +192 -0
  748. package/.merlin-core/tools/modules-catalog.mjs +174 -0
  749. package/.merlin-core/tools/provision-module.mjs +191 -0
  750. package/.merlin-core/tools/verify-module.mjs +99 -0
  751. package/.merlin-core/tools/vps-security-audit.sh +234 -0
  752. package/INSTALL.md +312 -0
  753. package/LICENSE +118 -0
  754. package/PRIVACY-LICENSING.md +65 -0
  755. package/README.md +391 -0
  756. package/bin/README.md +15 -0
  757. package/bin/convert-to-merlin.sh +109 -0
  758. package/bin/fleet-patch-hooks.sh +144 -0
  759. package/bin/fleet-patch-v3-fixes.sh +127 -0
  760. package/bin/merlin-init.js +232 -0
  761. package/bin/merlin.js +321 -0
  762. package/package.json +127 -0
@@ -0,0 +1,4624 @@
1
+ <!-- Adapted from czlonkowski/n8n-skills (MIT). Source files: SKILL.md, scheduled_tasks.md, webhook_processing.md, http_api_integration.md, database_operations.md, ai_agent_workflow.md -->
2
+
3
+ # n8n Workflow Patterns
4
+
5
+ Proven architectural patterns for building n8n workflows.
6
+
7
+ ---
8
+
9
+ ## The 5 Core Patterns
10
+
11
+ Based on analysis of real workflow usage:
12
+
13
+ 1. **Webhook Processing** (Most Common)
14
+ - Receive HTTP requests -> Process -> Output
15
+ - Pattern: Webhook -> Validate -> Transform -> Respond/Notify
16
+
17
+ 2. **HTTP API Integration**
18
+ - Fetch from REST APIs -> Transform -> Store/Use
19
+ - Pattern: Trigger -> HTTP Request -> Transform -> Action -> Error Handler
20
+
21
+ 3. **Database Operations**
22
+ - Read/Write/Sync database data
23
+ - Pattern: Schedule -> Query -> Transform -> Write -> Verify
24
+
25
+ 4. **AI Agent Workflow**
26
+ - AI agents with tools and memory
27
+ - Pattern: Trigger -> AI Agent (Model + Tools + Memory) -> Output
28
+
29
+ 5. **Scheduled Tasks**
30
+ - Recurring automation workflows
31
+ - Pattern: Schedule -> Fetch -> Process -> Deliver -> Log
32
+
33
+ ---
34
+
35
+ ## Pattern Selection Guide
36
+
37
+ ### When to use each pattern:
38
+
39
+ **Webhook Processing** - Use when:
40
+
41
+ - Receiving data from external systems
42
+ - Building integrations (Slack commands, form submissions, GitHub webhooks)
43
+ - Need instant response to events
44
+ - Example: "Receive Stripe payment webhook -> Update database -> Send confirmation"
45
+
46
+ **HTTP API Integration** - Use when:
47
+
48
+ - Fetching data from external APIs
49
+ - Synchronizing with third-party services
50
+ - Building data pipelines
51
+ - Example: "Fetch GitHub issues -> Transform -> Create Jira tickets"
52
+
53
+ **Database Operations** - Use when:
54
+
55
+ - Syncing between databases
56
+ - Running database queries on schedule
57
+ - ETL workflows
58
+ - Example: "Read Postgres records -> Transform -> Write to MySQL"
59
+
60
+ **AI Agent Workflow** - Use when:
61
+
62
+ - Building conversational AI
63
+ - Need AI with tool access
64
+ - Multi-step reasoning tasks
65
+ - Example: "Chat with AI that can search docs, query database, send emails"
66
+
67
+ **Scheduled Tasks** - Use when:
68
+
69
+ - Recurring reports or summaries
70
+ - Periodic data fetching
71
+ - Maintenance tasks
72
+ - Example: "Daily: Fetch analytics -> Generate report -> Email team"
73
+
74
+ ---
75
+
76
+ ## Common Workflow Components
77
+
78
+ All patterns share these building blocks:
79
+
80
+ ### 1. Triggers
81
+
82
+ - **Webhook** - HTTP endpoint (instant)
83
+ - **Schedule** - Cron-based timing (periodic)
84
+ - **Manual** - Click to execute (testing)
85
+ - **Polling** - Check for changes (intervals)
86
+
87
+ ### 2. Data Sources
88
+
89
+ - **HTTP Request** - REST APIs
90
+ - **Database nodes** - Postgres, MySQL, MongoDB
91
+ - **Service nodes** - Slack, Google Sheets, etc.
92
+ - **Code** - Custom JavaScript/Python
93
+
94
+ ### 3. Transformation
95
+
96
+ - **Set** - Map/transform fields
97
+ - **Code** - Complex logic
98
+ - **IF/Switch** - Conditional routing
99
+ - **Merge** - Combine data streams
100
+
101
+ ### 4. Outputs
102
+
103
+ - **HTTP Request** - Call APIs
104
+ - **Database** - Write data
105
+ - **Communication** - Email, Slack, Discord
106
+ - **Storage** - Files, cloud storage
107
+
108
+ ### 5. Error Handling
109
+
110
+ - **Error Trigger** - Catch workflow errors
111
+ - **IF** - Check for error conditions
112
+ - **Stop and Error** - Explicit failure
113
+ - **Continue On Fail** - Per-node setting
114
+
115
+ ---
116
+
117
+ ## Workflow Creation Checklist
118
+
119
+ When building ANY workflow, follow this checklist:
120
+
121
+ ### Planning Phase
122
+
123
+ - [ ] Identify the pattern (webhook, API, database, AI, scheduled)
124
+ - [ ] List required nodes (use search_nodes)
125
+ - [ ] Understand data flow (input -> transform -> output)
126
+ - [ ] Plan error handling strategy
127
+
128
+ ### Implementation Phase
129
+
130
+ - [ ] Create workflow with appropriate trigger
131
+ - [ ] Add data source nodes
132
+ - [ ] Configure authentication/credentials
133
+ - [ ] Add transformation nodes (Set, Code, IF)
134
+ - [ ] Add output/action nodes
135
+ - [ ] Configure error handling
136
+
137
+ ### Validation Phase
138
+
139
+ - [ ] Validate each node configuration (validate_node)
140
+ - [ ] Validate complete workflow (validate_workflow)
141
+ - [ ] Test with sample data
142
+ - [ ] Handle edge cases (empty data, errors)
143
+
144
+ ### Deployment Phase
145
+
146
+ - [ ] Review workflow settings (execution order, timeout, error handling)
147
+ - [ ] Activate workflow using `activateWorkflow` operation
148
+ - [ ] Monitor first executions
149
+ - [ ] Document workflow purpose and data flow
150
+
151
+ ---
152
+
153
+ ## Data Flow Patterns
154
+
155
+ ### Linear Flow
156
+
157
+ ```
158
+ Trigger -> Transform -> Action -> End
159
+ ```
160
+
161
+ **Use when**: Simple workflows with single path
162
+
163
+ ### Branching Flow
164
+
165
+ ```
166
+ Trigger -> IF -> [True Path]
167
+ └-> [False Path]
168
+ ```
169
+
170
+ **Use when**: Different actions based on conditions
171
+
172
+ ### Parallel Processing
173
+
174
+ ```
175
+ Trigger -> [Branch 1] -> Merge
176
+ └-> [Branch 2] ↗
177
+ ```
178
+
179
+ **Use when**: Independent operations that can run simultaneously
180
+
181
+ ### Loop Pattern
182
+
183
+ ```
184
+ Trigger -> Split in Batches -> Process -> Loop (until done)
185
+ ```
186
+
187
+ **Use when**: Processing large datasets in chunks
188
+
189
+ ### Error Handler Pattern
190
+
191
+ ```
192
+ Main Flow -> [Success Path]
193
+ └-> [Error Trigger -> Error Handler]
194
+ ```
195
+
196
+ **Use when**: Need separate error handling workflow
197
+
198
+ ---
199
+
200
+ ## Common Gotchas
201
+
202
+ ### 1. Webhook Data Structure
203
+
204
+ **Problem**: Can't access webhook payload data
205
+
206
+ **Solution**: Data is nested under `$json.body`
207
+
208
+ ```javascript
209
+ ❌ {{$json.email}}
210
+ ✅ {{$json.body.email}}
211
+ ```
212
+
213
+ See: [expression-syntax.md](../expression-syntax.md) for `{{}}` patterns
214
+
215
+ ### 2. Multiple Input Items
216
+
217
+ **Problem**: Node processes all input items, but I only want one
218
+
219
+ **Solution**: Use "Execute Once" mode or process first item only
220
+
221
+ ```javascript
222
+ {
223
+ {
224
+ $json[0].field;
225
+ }
226
+ } // First item only
227
+ ```
228
+
229
+ ### 3. Authentication Issues
230
+
231
+ **Problem**: API calls failing with 401/403
232
+
233
+ **Solution**:
234
+
235
+ - Configure credentials properly
236
+ - Use the "Credentials" section, not parameters
237
+ - Test credentials before workflow activation
238
+
239
+ ### 4. Node Execution Order
240
+
241
+ **Problem**: Nodes executing in unexpected order
242
+
243
+ **Solution**: Check workflow settings -> Execution Order
244
+
245
+ - v0: Top-to-bottom (legacy)
246
+ - v1: Connection-based (recommended)
247
+
248
+ ### 5. Expression Errors
249
+
250
+ **Problem**: Expressions showing as literal text
251
+
252
+ **Solution**: Use `{{}}` around expressions
253
+
254
+ - See [expression-syntax.md](../expression-syntax.md) for details
255
+
256
+ ---
257
+
258
+ ## Integration with Other Skills
259
+
260
+ These skills work together with Workflow Patterns:
261
+
262
+ **n8n MCP Tools Expert** - Use to:
263
+
264
+ - Find nodes for your pattern (search_nodes)
265
+ - Understand node operations (get_node)
266
+ - Create workflows (n8n_create_workflow)
267
+ - Deploy templates (n8n_deploy_template)
268
+ - Use ai_agents_guide for AI pattern guidance
269
+
270
+ **n8n Expression Syntax** - Use to:
271
+
272
+ - Write expressions in transformation nodes
273
+ - Access webhook data correctly (`{{$json.body.field}}`)
274
+ - Reference previous nodes (`{{$node["Node Name"].json.field}}`)
275
+
276
+ **n8n Node Configuration** - Use to:
277
+
278
+ - Configure specific operations for pattern nodes
279
+ - Understand node-specific requirements
280
+
281
+ **n8n Validation Expert** - Use to:
282
+
283
+ - Validate workflow structure
284
+ - Fix validation errors
285
+ - Ensure workflow correctness before deployment
286
+
287
+ ---
288
+
289
+ ## Pattern Statistics
290
+
291
+ Common workflow patterns:
292
+
293
+ **Most Common Triggers**:
294
+
295
+ 1. Webhook - 35%
296
+ 2. Schedule (periodic tasks) - 28%
297
+ 3. Manual (testing/admin) - 22%
298
+ 4. Service triggers (Slack, email, etc.) - 15%
299
+
300
+ **Most Common Transformations**:
301
+
302
+ 1. Set (field mapping) - 68%
303
+ 2. Code (custom logic) - 42%
304
+ 3. IF (conditional routing) - 38%
305
+ 4. Switch (multi-condition) - 18%
306
+
307
+ **Most Common Outputs**:
308
+
309
+ 1. HTTP Request (APIs) - 45%
310
+ 2. Slack - 32%
311
+ 3. Database writes - 28%
312
+ 4. Email - 24%
313
+
314
+ **Average Workflow Complexity**:
315
+
316
+ - Simple (3-5 nodes): 42%
317
+ - Medium (6-10 nodes): 38%
318
+ - Complex (11+ nodes): 20%
319
+
320
+ ---
321
+
322
+ ## Quick Start Examples
323
+
324
+ ### Example 1: Simple Webhook -> Slack
325
+
326
+ ```
327
+ 1. Webhook (path: "form-submit", POST)
328
+ 2. Set (map form fields)
329
+ 3. Slack (post message to #notifications)
330
+ ```
331
+
332
+ ### Example 2: Scheduled Report
333
+
334
+ ```
335
+ 1. Schedule (daily at 9 AM)
336
+ 2. HTTP Request (fetch analytics)
337
+ 3. Code (aggregate data)
338
+ 4. Email (send formatted report)
339
+ 5. Error Trigger -> Slack (notify on failure)
340
+ ```
341
+
342
+ ### Example 3: Database Sync
343
+
344
+ ```
345
+ 1. Schedule (every 15 minutes)
346
+ 2. Postgres (query new records)
347
+ 3. IF (check if records exist)
348
+ 4. MySQL (insert records)
349
+ 5. Postgres (update sync timestamp)
350
+ ```
351
+
352
+ ### Example 4: AI Assistant
353
+
354
+ ```
355
+ 1. Webhook (receive chat message)
356
+ 2. AI Agent
357
+ ├─ OpenAI Chat Model (ai_languageModel)
358
+ ├─ HTTP Request Tool (ai_tool)
359
+ ├─ Database Tool (ai_tool)
360
+ └─ Window Buffer Memory (ai_memory)
361
+ 3. Webhook Response (send AI reply)
362
+ ```
363
+
364
+ ### Example 5: API Integration
365
+
366
+ ```
367
+ 1. Manual Trigger (for testing)
368
+ 2. HTTP Request (GET /api/users)
369
+ 3. Split In Batches (process 100 at a time)
370
+ 4. Set (transform user data)
371
+ 5. Postgres (upsert users)
372
+ 6. Loop (back to step 3 until done)
373
+ ```
374
+
375
+ ---
376
+
377
+ ## Detailed Pattern Files
378
+
379
+ For comprehensive guidance on each pattern:
380
+
381
+ - **webhook_processing.md** - Webhook patterns, data structure, response handling
382
+ - **http_api_integration.md** - REST APIs, authentication, pagination, retries
383
+ - **database_operations.md** - Queries, sync, transactions, batch processing
384
+ - **ai_agent_workflow.md** - AI agents, tools, memory, langchain nodes
385
+ - **scheduled_tasks.md** - Cron schedules, reports, maintenance tasks
386
+
387
+ ---
388
+
389
+ ## Real Template Examples
390
+
391
+ From n8n template library:
392
+
393
+ **Template #2947**: Weather to Slack
394
+
395
+ - Pattern: Scheduled Task
396
+ - Nodes: Schedule -> HTTP Request (weather API) -> Set -> Slack
397
+ - Complexity: Simple (4 nodes)
398
+
399
+ **Webhook Processing**: Most common pattern
400
+
401
+ - Most common: Form submissions, payment webhooks, chat integrations
402
+
403
+ **HTTP API**: Common pattern
404
+
405
+ - Most common: Data fetching, third-party integrations
406
+
407
+ **Database Operations**: Common pattern
408
+
409
+ - Most common: ETL, data sync, backup workflows
410
+
411
+ **AI Agents**: Growing in usage
412
+
413
+ - Most common: Chatbots, content generation, data analysis
414
+
415
+ Use `search_templates` and `get_template` from n8n-mcp tools to find examples!
416
+
417
+ ---
418
+
419
+ ## Best Practices
420
+
421
+ ### Do
422
+
423
+ - Start with the simplest pattern that solves your problem
424
+ - Plan your workflow structure before building
425
+ - Use error handling on all workflows
426
+ - Test with sample data before activation
427
+ - Follow the workflow creation checklist
428
+ - Use descriptive node names
429
+ - Document complex workflows (notes field)
430
+ - Monitor workflow executions after deployment
431
+
432
+ ### Don't
433
+
434
+ - Build workflows in one shot (iterate! avg 56s between edits)
435
+ - Skip validation before activation
436
+ - Ignore error scenarios
437
+ - Use complex patterns when simple ones suffice
438
+ - Hardcode credentials in parameters
439
+ - Forget to handle empty data cases
440
+ - Mix multiple patterns without clear boundaries
441
+ - Deploy without testing
442
+
443
+ ---
444
+
445
+ ## Summary
446
+
447
+ **Key Points**:
448
+
449
+ 1. **5 core patterns** cover 90%+ of workflow use cases
450
+ 2. **Webhook processing** is the most common pattern
451
+ 3. Use the **workflow creation checklist** for every workflow
452
+ 4. **Plan pattern** -> **Select nodes** -> **Build** -> **Validate** -> **Deploy**
453
+ 5. Integrate with other skills for complete workflow development
454
+
455
+ **Next Steps**:
456
+
457
+ 1. Identify your use case pattern
458
+ 2. Read the detailed pattern file
459
+ 3. Use n8n MCP Tools Expert to find nodes
460
+ 4. Follow the workflow creation checklist
461
+ 5. Use n8n Validation Expert to validate
462
+
463
+ **Related Skills**:
464
+
465
+ - n8n MCP Tools Expert - Find and configure nodes
466
+ - n8n Expression Syntax - Write expressions correctly
467
+ - n8n Validation Expert - Validate and fix errors
468
+ - n8n Node Configuration - Configure specific operations
469
+
470
+ ---
471
+
472
+ ---
473
+
474
+ # Webhook Processing Pattern
475
+
476
+ **Use Case**: Receive HTTP requests from external systems and process them instantly.
477
+
478
+ ---
479
+
480
+ ## Pattern Structure
481
+
482
+ ```
483
+ Webhook -> [Validate] -> [Transform] -> [Action] -> [Response/Notify]
484
+ ```
485
+
486
+ **Key Characteristic**: Instant event-driven processing
487
+
488
+ ---
489
+
490
+ ## Core Components
491
+
492
+ ### 1. Webhook Node (Trigger)
493
+
494
+ **Purpose**: Create HTTP endpoint to receive data
495
+
496
+ **Configuration**:
497
+
498
+ ```javascript
499
+ {
500
+ path: "form-submit", // URL path: https://n8n.example.com/webhook/form-submit
501
+ httpMethod: "POST", // GET, POST, PUT, DELETE
502
+ responseMode: "onReceived", // or "lastNode" for custom response
503
+ responseData: "allEntries" // or "firstEntryJson"
504
+ }
505
+ ```
506
+
507
+ **Critical Gotcha**: Data is nested under `$json.body`
508
+
509
+ ```javascript
510
+ ❌ {{$json.email}}
511
+ ✅ {{$json.body.email}}
512
+ ```
513
+
514
+ > Cross-reference: See [expression-syntax.md](../expression-syntax.md) for full `{{}}` expression syntax.
515
+
516
+ ### 2. Validation (Optional but Recommended)
517
+
518
+ **Purpose**: Verify incoming data before processing
519
+
520
+ **Options**:
521
+
522
+ - **IF node** - Check required fields exist
523
+ - **Code node** - Custom validation logic
524
+ - **Stop and Error** - Fail gracefully with message
525
+
526
+ **Example**:
527
+
528
+ ```javascript
529
+ // IF node condition
530
+ {{$json.body.email}} is not empty AND
531
+ {{$json.body.name}} is not empty
532
+ ```
533
+
534
+ ### 3. Transformation
535
+
536
+ **Purpose**: Map webhook data to desired format
537
+
538
+ **Typical nodes**:
539
+
540
+ - **Set** - Field mapping
541
+ - **Code** - Complex transformations
542
+
543
+ **Example** (Set node):
544
+
545
+ ```javascript
546
+ {
547
+ "user_email": "={{$json.body.email}}",
548
+ "user_name": "={{$json.body.name}}",
549
+ "timestamp": "={{$now}}"
550
+ }
551
+ ```
552
+
553
+ > Cross-reference: See [expression-syntax.md](../expression-syntax.md) for `={{...}}` value expressions.
554
+
555
+ ### 4. Action
556
+
557
+ **Purpose**: Do something with the data
558
+
559
+ **Common actions**:
560
+
561
+ - Store in database (Postgres, MySQL, MongoDB)
562
+ - Send notification (Slack, Email, Discord)
563
+ - Call another API (HTTP Request)
564
+ - Update external system (CRM, support ticket)
565
+
566
+ ### 5. Response (If responseMode: "lastNode")
567
+
568
+ **Purpose**: Send custom HTTP response
569
+
570
+ **Webhook Response Node**:
571
+
572
+ ```javascript
573
+ {
574
+ statusCode: 200,
575
+ headers: {
576
+ "Content-Type": "application/json"
577
+ },
578
+ body: {
579
+ "status": "success",
580
+ "message": "Form received"
581
+ }
582
+ }
583
+ ```
584
+
585
+ ---
586
+
587
+ ## Common Use Cases
588
+
589
+ ### 1. Form Submissions
590
+
591
+ **Flow**: Form -> Webhook -> Validate -> Database -> Email Confirmation
592
+
593
+ **Example**:
594
+
595
+ ```
596
+ 1. Webhook (path: "contact-form", POST)
597
+ 2. IF (check email & message not empty)
598
+ 3. Postgres (insert into contacts table)
599
+ 4. Email (send confirmation to user)
600
+ 5. Slack (notify team in #leads)
601
+ 6. Webhook Response ({"status": "success"})
602
+ ```
603
+
604
+ **Real Data Access**:
605
+
606
+ ```javascript
607
+ Name: {
608
+ {
609
+ $json.body.name;
610
+ }
611
+ }
612
+ Email: {
613
+ {
614
+ $json.body.email;
615
+ }
616
+ }
617
+ Message: {
618
+ {
619
+ $json.body.message;
620
+ }
621
+ }
622
+ ```
623
+
624
+ ### 2. Payment Webhooks (Stripe, PayPal)
625
+
626
+ **Flow**: Payment Provider -> Webhook -> Verify -> Update Database -> Send Receipt
627
+
628
+ **Security**: Verify webhook signatures
629
+
630
+ ```javascript
631
+ // Code node - verify Stripe signature
632
+ const crypto = require("crypto");
633
+ const signature = $input.item.headers["stripe-signature"];
634
+ const secret = $credentials.stripeWebhookSecret;
635
+
636
+ // Verify signature matches
637
+ const expectedSig = crypto
638
+ .createHmac("sha256", secret)
639
+ .update($input.item.body)
640
+ .digest("hex");
641
+
642
+ if (signature !== expectedSig) {
643
+ throw new Error("Invalid webhook signature");
644
+ }
645
+
646
+ return $input.item.body; // Return validated body
647
+ ```
648
+
649
+ > Cross-reference: See [code-javascript.md](../code-javascript.md) for Code node patterns including `$input`, `$credentials`, and `require()`.
650
+
651
+ ### 3. Chat Platform Integrations (Slack, Discord, Teams)
652
+
653
+ **Flow**: Chat Command -> Webhook -> Process -> Respond
654
+
655
+ **Example** (Slack slash command):
656
+
657
+ ```
658
+ 1. Webhook (path: "slack-command", POST)
659
+ 2. Code (parse Slack payload: $json.body.text, $json.body.user_id)
660
+ 3. HTTP Request (fetch data from API)
661
+ 4. Set (format Slack message)
662
+ 5. Webhook Response (immediate Slack response)
663
+ ```
664
+
665
+ **Slack Data Access**:
666
+
667
+ ```javascript
668
+ Command: {{$json.body.command}}
669
+ Text: {{$json.body.text}}
670
+ User ID: {{$json.body.user_id}}
671
+ Channel ID: {{$json.body.channel_id}}
672
+ ```
673
+
674
+ ### 4. GitHub/GitLab Webhooks
675
+
676
+ **Flow**: Git Event -> Webhook -> Parse -> Notify/Deploy
677
+
678
+ **Example** (new PR notification):
679
+
680
+ ```
681
+ 1. Webhook (path: "github", POST)
682
+ 2. IF (check $json.body.action equals "opened")
683
+ 3. Set (extract PR details: title, author, url)
684
+ 4. Slack (notify #dev-team)
685
+ 5. Webhook Response (200 OK)
686
+ ```
687
+
688
+ **GitHub Data Access**:
689
+
690
+ ```javascript
691
+ Event Type: {{$json.headers['x-github-event']}}
692
+ Action: {{$json.body.action}}
693
+ PR Title: {{$json.body.pull_request.title}}
694
+ Author: {{$json.body.pull_request.user.login}}
695
+ URL: {{$json.body.pull_request.html_url}}
696
+ ```
697
+
698
+ ### 5. IoT Device Data
699
+
700
+ **Flow**: Device -> Webhook -> Validate -> Store -> Alert (if threshold)
701
+
702
+ **Example** (temperature sensor):
703
+
704
+ ```
705
+ 1. Webhook (path: "sensor-data", POST)
706
+ 2. Set (extract sensor readings)
707
+ 3. Postgres (insert into sensor_readings)
708
+ 4. IF (temperature > 80)
709
+ 5. Email (alert admin)
710
+ ```
711
+
712
+ ---
713
+
714
+ ## Webhook Data Structure
715
+
716
+ ### Standard Structure
717
+
718
+ ```json
719
+ {
720
+ "headers": {
721
+ "content-type": "application/json",
722
+ "user-agent": "...",
723
+ "x-custom-header": "..."
724
+ },
725
+ "params": {
726
+ "id": "123" // From URL: /webhook/form/:id
727
+ },
728
+ "query": {
729
+ "token": "abc" // From URL: /webhook/form?token=abc
730
+ },
731
+ "body": {
732
+ // YOUR DATA IS HERE!
733
+ "name": "John",
734
+ "email": "john@example.com"
735
+ }
736
+ }
737
+ ```
738
+
739
+ ### Accessing Different Parts
740
+
741
+ ```javascript
742
+ // Headers
743
+ {
744
+ {
745
+ $json.headers["content-type"];
746
+ }
747
+ }
748
+ {
749
+ {
750
+ $json.headers["x-api-key"];
751
+ }
752
+ }
753
+
754
+ // URL Parameters
755
+ {
756
+ {
757
+ $json.params.id;
758
+ }
759
+ }
760
+
761
+ // Query Parameters
762
+ {
763
+ {
764
+ $json.query.token;
765
+ }
766
+ }
767
+ {
768
+ {
769
+ $json.query.page;
770
+ }
771
+ }
772
+
773
+ // Body (MOST COMMON)
774
+ {
775
+ {
776
+ $json.body.email;
777
+ }
778
+ }
779
+ {
780
+ {
781
+ $json.body.user.name;
782
+ }
783
+ }
784
+ {
785
+ {
786
+ $json.body.items[0].price;
787
+ }
788
+ }
789
+ ```
790
+
791
+ > Cross-reference: See [expression-syntax.md](../expression-syntax.md) for bracket notation, array access, and nested path patterns.
792
+
793
+ ---
794
+
795
+ ## Authentication & Security
796
+
797
+ ### 1. Query Parameter Token
798
+
799
+ **Simple but less secure**
800
+
801
+ ```javascript
802
+ // IF node - validate token
803
+ {{$json.query.token}} equals "your-secret-token"
804
+ ```
805
+
806
+ ### 2. Header-Based Auth
807
+
808
+ **Better security**
809
+
810
+ ```javascript
811
+ // IF node - check header
812
+ {{$json.headers['x-api-key']}} equals "your-api-key"
813
+ ```
814
+
815
+ ### 3. Signature Verification
816
+
817
+ **Best security** (for webhooks from services like Stripe, GitHub)
818
+
819
+ ```javascript
820
+ // Code node
821
+ const crypto = require("crypto");
822
+ const signature = $input.item.headers["x-signature"];
823
+ const secret = $credentials.webhookSecret;
824
+
825
+ const calculatedSig = crypto
826
+ .createHmac("sha256", secret)
827
+ .update(JSON.stringify($input.item.body))
828
+ .digest("hex");
829
+
830
+ if (signature !== `sha256=${calculatedSig}`) {
831
+ throw new Error("Invalid signature");
832
+ }
833
+
834
+ return $input.item.body;
835
+ ```
836
+
837
+ ### 4. IP Whitelist
838
+
839
+ **Restrict access by IP** (n8n workflow settings)
840
+
841
+ - Configure in workflow settings
842
+ - Only allow specific IP ranges
843
+ - Use for internal systems
844
+
845
+ ---
846
+
847
+ ## Response Modes
848
+
849
+ ### onReceived (Default)
850
+
851
+ **Behavior**: Immediate 200 OK response, workflow continues in background
852
+
853
+ **Use when**:
854
+
855
+ - Long-running workflows
856
+ - Response doesn't depend on workflow result
857
+ - Fire-and-forget processing
858
+
859
+ **Configuration**:
860
+
861
+ ```javascript
862
+ {
863
+ responseMode: "onReceived",
864
+ responseCode: 200
865
+ }
866
+ ```
867
+
868
+ ### lastNode (Custom Response)
869
+
870
+ **Behavior**: Wait for workflow completion, send custom response
871
+
872
+ **Use when**:
873
+
874
+ - Need to return data to caller
875
+ - Synchronous processing required
876
+ - Form submissions with confirmation
877
+
878
+ **Configuration**:
879
+
880
+ ```javascript
881
+ {
882
+ responseMode: "lastNode";
883
+ }
884
+ ```
885
+
886
+ **Then add Webhook Response node**:
887
+
888
+ ```javascript
889
+ {
890
+ statusCode: 200,
891
+ headers: {
892
+ "Content-Type": "application/json"
893
+ },
894
+ body: {
895
+ "id": "={{$json.record_id}}",
896
+ "status": "success"
897
+ }
898
+ }
899
+ ```
900
+
901
+ > Cross-reference: See [node-configuration.md](../node-configuration.md) for Webhook and Webhook Response node setup.
902
+
903
+ ---
904
+
905
+ ## Error Handling
906
+
907
+ ### Pattern 1: Try-Catch with Error Trigger
908
+
909
+ ```
910
+ Main Flow:
911
+ Webhook -> [nodes...] -> Success Response
912
+
913
+ Error Flow:
914
+ Error Trigger -> Log Error -> Slack Alert -> Error Response
915
+ ```
916
+
917
+ **Error Trigger Configuration**:
918
+
919
+ ```javascript
920
+ {
921
+ workflowId: "current-workflow-id";
922
+ }
923
+ ```
924
+
925
+ **Error Response** (if responseMode: "lastNode"):
926
+
927
+ ```javascript
928
+ {
929
+ statusCode: 500,
930
+ body: {
931
+ "status": "error",
932
+ "message": "Processing failed"
933
+ }
934
+ }
935
+ ```
936
+
937
+ ### Pattern 2: Validation Early Exit
938
+
939
+ ```
940
+ Webhook -> IF (validate) -> [True: Process]
941
+ └-> [False: Error Response]
942
+ ```
943
+
944
+ **False Branch Response**:
945
+
946
+ ```javascript
947
+ {
948
+ statusCode: 400,
949
+ body: {
950
+ "status": "error",
951
+ "message": "Invalid data: missing email"
952
+ }
953
+ }
954
+ ```
955
+
956
+ ### Pattern 3: Continue On Fail
957
+
958
+ **Per-node setting**: Continue even if node fails
959
+
960
+ **Use case**: Non-critical notifications
961
+
962
+ ```
963
+ Webhook -> Database (critical) -> Slack (continueOnFail: true)
964
+ ```
965
+
966
+ ---
967
+
968
+ ## Testing Webhooks
969
+
970
+ ### 1. Use Manual Trigger
971
+
972
+ Replace Webhook with Manual Trigger for testing:
973
+
974
+ ```
975
+ Manual Trigger -> [set test data] -> rest of workflow
976
+ ```
977
+
978
+ ### 2. Use curl
979
+
980
+ ```bash
981
+ curl -X POST https://n8n.example.com/webhook/form-submit \
982
+ -H "Content-Type: application/json" \
983
+ -d '{"email": "test@example.com", "name": "Test User"}'
984
+ ```
985
+
986
+ ### 3. Use Postman/Insomnia
987
+
988
+ - Create request collection
989
+ - Test different payloads
990
+ - Verify responses
991
+
992
+ ### 4. Webhook.site
993
+
994
+ - Use webhook.site for testing
995
+ - Copy webhook.site URL to your service
996
+ - View requests and debug
997
+
998
+ ---
999
+
1000
+ ## Performance Considerations
1001
+
1002
+ ### Large Payloads
1003
+
1004
+ - Webhook timeout: 120 seconds (default)
1005
+ - For large data, consider async processing:
1006
+
1007
+ ```
1008
+ Webhook -> Queue (Redis/DB) -> Response (immediate)
1009
+
1010
+ Separate Workflow:
1011
+ Schedule -> Check Queue -> Process
1012
+ ```
1013
+
1014
+ ### High Volume
1015
+
1016
+ - Use "Execute Once" mode if processing all items together
1017
+ - Consider rate limiting
1018
+ - Monitor execution times
1019
+ - Scale n8n instance if needed
1020
+
1021
+ ### Retries
1022
+
1023
+ - Webhook calls typically don't retry automatically
1024
+ - Implement retry logic on caller side
1025
+ - Or use queue pattern for guaranteed processing
1026
+
1027
+ ---
1028
+
1029
+ ## Webhook Common Gotchas
1030
+
1031
+ ### 1. Wrong: Accessing webhook data
1032
+
1033
+ ```javascript
1034
+ {
1035
+ {
1036
+ $json.email;
1037
+ }
1038
+ } // Empty or undefined
1039
+ ```
1040
+
1041
+ ### Correct
1042
+
1043
+ ```javascript
1044
+ {
1045
+ {
1046
+ $json.body.email;
1047
+ }
1048
+ } // Data is under .body
1049
+ ```
1050
+
1051
+ ### 2. Wrong: Response mode confusion
1052
+
1053
+ Using Webhook Response node with responseMode: "onReceived" (ignored)
1054
+
1055
+ ### Correct
1056
+
1057
+ Set responseMode: "lastNode" to use Webhook Response node
1058
+
1059
+ ### 3. Wrong: No validation
1060
+
1061
+ Assuming data is always present and valid
1062
+
1063
+ ### Correct
1064
+
1065
+ Validate data early with IF node or Code node
1066
+
1067
+ ### 4. Wrong: Hardcoded paths
1068
+
1069
+ Using same path for dev/prod
1070
+
1071
+ ### Correct
1072
+
1073
+ Use environment variables: `{{$env.WEBHOOK_PATH_PREFIX}}/form-submit`
1074
+
1075
+ ---
1076
+
1077
+ ## Real Webhook Template Examples
1078
+
1079
+ From n8n template library (1,085 webhook templates):
1080
+
1081
+ **Simple Form to Slack**:
1082
+
1083
+ ```
1084
+ Webhook -> Set -> Slack
1085
+ ```
1086
+
1087
+ **Payment Processing**:
1088
+
1089
+ ```
1090
+ Webhook -> Verify Signature -> Update Database -> Send Receipt -> Notify Admin
1091
+ ```
1092
+
1093
+ **Chat Bot**:
1094
+
1095
+ ```
1096
+ Webhook -> Parse Command -> AI Agent -> Format Response -> Webhook Response
1097
+ ```
1098
+
1099
+ Use `search_templates({query: "webhook"})` to find more!
1100
+
1101
+ ---
1102
+
1103
+ ## Checklist for Webhook Workflows
1104
+
1105
+ ### Setup
1106
+
1107
+ - [ ] Choose descriptive webhook path
1108
+ - [ ] Configure HTTP method (POST most common)
1109
+ - [ ] Choose response mode (onReceived vs lastNode)
1110
+ - [ ] Test webhook URL before connecting services
1111
+
1112
+ ### Security
1113
+
1114
+ - [ ] Add authentication (token, signature, IP whitelist)
1115
+ - [ ] Validate incoming data
1116
+ - [ ] Sanitize user input (if storing/displaying)
1117
+ - [ ] Use HTTPS (always)
1118
+
1119
+ ### Data Handling
1120
+
1121
+ - [ ] Remember data is under $json.body
1122
+ - [ ] Handle missing fields gracefully
1123
+ - [ ] Transform data to desired format
1124
+ - [ ] Log important data (for debugging)
1125
+
1126
+ ### Error Handling
1127
+
1128
+ - [ ] Add Error Trigger workflow
1129
+ - [ ] Validate required fields
1130
+ - [ ] Return appropriate error responses
1131
+ - [ ] Alert team on failures
1132
+
1133
+ ### Testing
1134
+
1135
+ - [ ] Test with curl/Postman
1136
+ - [ ] Test error scenarios
1137
+ - [ ] Verify response format
1138
+ - [ ] Monitor first executions
1139
+
1140
+ ---
1141
+
1142
+ ## Webhook Summary
1143
+
1144
+ **Key Points**:
1145
+
1146
+ 1. **Data under $json.body** (most common mistake!)
1147
+ 2. **Validate early** to catch bad data
1148
+ 3. **Choose response mode** based on use case
1149
+ 4. **Secure webhooks** with auth
1150
+ 5. **Handle errors** gracefully
1151
+
1152
+ **Pattern**: Webhook -> Validate -> Transform -> Action -> Response
1153
+
1154
+ **Related**:
1155
+
1156
+ - [expression-syntax.md](../expression-syntax.md) - Accessing webhook data correctly
1157
+ - [code-javascript.md](../code-javascript.md) - Code node for signature verification and custom logic
1158
+
1159
+ ---
1160
+
1161
+ ---
1162
+
1163
+ # Scheduled Tasks Pattern
1164
+
1165
+ **Use Case**: Recurring automation workflows that run automatically on a schedule.
1166
+
1167
+ ---
1168
+
1169
+ ## Pattern Structure
1170
+
1171
+ ```
1172
+ Schedule Trigger -> [Fetch Data] -> [Process] -> [Deliver] -> [Log/Notify]
1173
+ ```
1174
+
1175
+ **Key Characteristic**: Time-based automated execution
1176
+
1177
+ ---
1178
+
1179
+ ## Core Components
1180
+
1181
+ ### 1. Schedule Trigger
1182
+
1183
+ **Purpose**: Execute workflow at specified times
1184
+
1185
+ **Modes**:
1186
+
1187
+ - **Interval** - Every X minutes/hours/days
1188
+ - **Cron** - Specific times (advanced)
1189
+ - **Days & Hours** - Simple recurring schedule
1190
+
1191
+ ### 2. Data Source
1192
+
1193
+ **Common sources**:
1194
+
1195
+ - HTTP Request (APIs)
1196
+ - Database queries
1197
+ - File reads
1198
+ - Service-specific nodes
1199
+
1200
+ ### 3. Processing
1201
+
1202
+ **Typical operations**:
1203
+
1204
+ - Filter/transform data
1205
+ - Aggregate statistics
1206
+ - Generate reports
1207
+ - Check conditions
1208
+
1209
+ ### 4. Delivery
1210
+
1211
+ **Output channels**:
1212
+
1213
+ - Email
1214
+ - Slack/Discord/Teams
1215
+ - File storage
1216
+ - Database writes
1217
+
1218
+ ### 5. Logging
1219
+
1220
+ **Purpose**: Track execution history
1221
+
1222
+ **Methods**:
1223
+
1224
+ - Database log entries
1225
+ - File append
1226
+ - Monitoring service
1227
+
1228
+ ---
1229
+
1230
+ ## Schedule Configuration
1231
+
1232
+ ### Interval Mode
1233
+
1234
+ **Best for**: Simple recurring tasks
1235
+
1236
+ **Examples**:
1237
+
1238
+ ```javascript
1239
+ // Every 15 minutes
1240
+ {
1241
+ mode: "interval",
1242
+ interval: 15,
1243
+ unit: "minutes"
1244
+ }
1245
+
1246
+ // Every 2 hours
1247
+ {
1248
+ mode: "interval",
1249
+ interval: 2,
1250
+ unit: "hours"
1251
+ }
1252
+
1253
+ // Every day at midnight
1254
+ {
1255
+ mode: "interval",
1256
+ interval: 1,
1257
+ unit: "days"
1258
+ }
1259
+ ```
1260
+
1261
+ ### Days & Hours Mode
1262
+
1263
+ **Best for**: Specific days and times
1264
+
1265
+ **Examples**:
1266
+
1267
+ ```javascript
1268
+ // Weekdays at 9 AM
1269
+ {
1270
+ mode: "daysAndHours",
1271
+ days: ["monday", "tuesday", "wednesday", "thursday", "friday"],
1272
+ hour: 9,
1273
+ minute: 0
1274
+ }
1275
+
1276
+ // Every Monday at 6 PM
1277
+ {
1278
+ mode: "daysAndHours",
1279
+ days: ["monday"],
1280
+ hour: 18,
1281
+ minute: 0
1282
+ }
1283
+ ```
1284
+
1285
+ ### Cron Mode (Advanced)
1286
+
1287
+ **Best for**: Complex schedules
1288
+
1289
+ **Examples**:
1290
+
1291
+ ```javascript
1292
+ // Every weekday at 9 AM
1293
+ {
1294
+ mode: "cron",
1295
+ expression: "0 9 * * 1-5"
1296
+ }
1297
+
1298
+ // First day of every month at midnight
1299
+ {
1300
+ mode: "cron",
1301
+ expression: "0 0 1 * *"
1302
+ }
1303
+
1304
+ // Every 15 minutes during business hours (9 AM - 5 PM) on weekdays
1305
+ {
1306
+ mode: "cron",
1307
+ expression: "*/15 9-17 * * 1-5"
1308
+ }
1309
+ ```
1310
+
1311
+ **Cron format**: `minute hour day month weekday`
1312
+
1313
+ - `*` = any value
1314
+ - `*/15` = every 15 units
1315
+ - `1-5` = range (Monday-Friday)
1316
+ - `1,15` = specific values
1317
+
1318
+ **Cron examples**:
1319
+
1320
+ ```
1321
+ 0 */6 * * * Every 6 hours
1322
+ 0 9,17 * * * At 9 AM and 5 PM daily
1323
+ 0 0 * * 0 Every Sunday at midnight
1324
+ */30 * * * * Every 30 minutes
1325
+ 0 0 1,15 * * 1st and 15th of each month
1326
+ ```
1327
+
1328
+ > Cross-reference: See [node-configuration.md](../node-configuration.md) for Schedule Trigger node setup details.
1329
+
1330
+ ---
1331
+
1332
+ ## Common Use Cases
1333
+
1334
+ ### 1. Daily Reports
1335
+
1336
+ **Flow**: Schedule -> Fetch data -> Aggregate -> Format -> Email
1337
+
1338
+ **Example** (Sales report):
1339
+
1340
+ ```
1341
+ 1. Schedule (daily at 9 AM)
1342
+
1343
+ 2. Postgres (query yesterday's sales)
1344
+ SELECT date, SUM(amount) as total, COUNT(*) as orders
1345
+ FROM orders
1346
+ WHERE date = CURRENT_DATE - INTERVAL '1 day'
1347
+ GROUP BY date
1348
+
1349
+ 3. Code (calculate metrics)
1350
+ - Total revenue
1351
+ - Order count
1352
+ - Average order value
1353
+ - Comparison to previous day
1354
+
1355
+ 4. Set (format email body)
1356
+ Subject: Daily Sales Report - {{$json.date}}
1357
+ Body: Formatted HTML with metrics
1358
+
1359
+ 5. Email (send to team@company.com)
1360
+
1361
+ 6. Slack (post summary to #sales)
1362
+ ```
1363
+
1364
+ ### 2. Data Synchronization
1365
+
1366
+ **Flow**: Schedule -> Fetch from source -> Transform -> Write to target
1367
+
1368
+ **Example** (CRM to data warehouse sync):
1369
+
1370
+ ```
1371
+ 1. Schedule (every hour)
1372
+
1373
+ 2. Set (store last sync time)
1374
+ SELECT MAX(synced_at) FROM sync_log
1375
+
1376
+ 3. HTTP Request (fetch new CRM contacts since last sync)
1377
+ GET /api/contacts?updated_since={{$json.last_sync}}
1378
+
1379
+ 4. IF (check if new records exist)
1380
+
1381
+ 5. Set (transform CRM schema to warehouse schema)
1382
+
1383
+ 6. Postgres (warehouse - INSERT new contacts)
1384
+
1385
+ 7. Postgres (UPDATE sync_log SET synced_at = NOW())
1386
+
1387
+ 8. IF (error occurred)
1388
+ └─ Slack (alert #data-team)
1389
+ ```
1390
+
1391
+ ### 3. Monitoring & Health Checks
1392
+
1393
+ **Flow**: Schedule -> Check endpoints -> Alert if down
1394
+
1395
+ **Example** (Website uptime monitor):
1396
+
1397
+ ```
1398
+ 1. Schedule (every 5 minutes)
1399
+
1400
+ 2. HTTP Request (GET https://example.com/health)
1401
+ - timeout: 10 seconds
1402
+ - continueOnFail: true
1403
+
1404
+ 3. IF (status !== 200 OR response_time > 2000ms)
1405
+
1406
+ 4. Redis (check alert cooldown - don't spam)
1407
+ - Key: alert:website_down
1408
+ - TTL: 30 minutes
1409
+
1410
+ 5. IF (no recent alert sent)
1411
+
1412
+ 6. [Alert Actions]
1413
+ ├─ Slack (notify #ops-team)
1414
+ ├─ PagerDuty (create incident)
1415
+ ├─ Email (alert@company.com)
1416
+ └─ Redis (set alert cooldown)
1417
+
1418
+ 7. Postgres (log uptime check result)
1419
+ ```
1420
+
1421
+ ### 4. Cleanup & Maintenance
1422
+
1423
+ **Flow**: Schedule -> Find old data -> Archive/Delete -> Report
1424
+
1425
+ **Example** (Database cleanup):
1426
+
1427
+ ```
1428
+ 1. Schedule (weekly on Sunday at 2 AM)
1429
+
1430
+ 2. Postgres (find old records)
1431
+ SELECT * FROM logs
1432
+ WHERE created_at < NOW() - INTERVAL '90 days'
1433
+ LIMIT 10000
1434
+
1435
+ 3. IF (records exist)
1436
+
1437
+ 4. Code (export to JSON for archive)
1438
+
1439
+ 5. Google Drive (upload archive file)
1440
+ - Filename: logs_archive_{{$now.format('YYYY-MM-DD')}}.json
1441
+
1442
+ 6. Postgres (DELETE archived records)
1443
+ DELETE FROM logs
1444
+ WHERE id IN ({{$json.archived_ids}})
1445
+
1446
+ 7. Slack (report: "Archived X records, deleted Y records")
1447
+ ```
1448
+
1449
+ ### 5. Data Enrichment
1450
+
1451
+ **Flow**: Schedule -> Find incomplete records -> Enrich -> Update
1452
+
1453
+ **Example** (Enrich contacts with company data):
1454
+
1455
+ ```
1456
+ 1. Schedule (nightly at 3 AM)
1457
+
1458
+ 2. Postgres (find contacts without company data)
1459
+ SELECT id, email, domain FROM contacts
1460
+ WHERE company_name IS NULL
1461
+ AND created_at > NOW() - INTERVAL '7 days'
1462
+ LIMIT 100
1463
+
1464
+ 3. Split In Batches (10 contacts per batch)
1465
+
1466
+ 4. HTTP Request (call Clearbit enrichment API)
1467
+ - For each contact domain
1468
+ - Rate limit: wait 1 second between batches
1469
+
1470
+ 5. Set (map API response to database schema)
1471
+
1472
+ 6. Postgres (UPDATE contacts with company data)
1473
+
1474
+ 7. Wait (1 second - rate limiting)
1475
+
1476
+ 8. Loop (back to step 4 until all batches processed)
1477
+
1478
+ 9. Email (summary: "Enriched X contacts")
1479
+ ```
1480
+
1481
+ ### 6. Backup Automation
1482
+
1483
+ **Flow**: Schedule -> Export data -> Compress -> Store -> Verify
1484
+
1485
+ **Example** (Database backup):
1486
+
1487
+ ```
1488
+ 1. Schedule (daily at 2 AM)
1489
+
1490
+ 2. Code (execute pg_dump)
1491
+ const { exec } = require('child_process');
1492
+ exec('pg_dump -h db.example.com mydb > backup.sql')
1493
+
1494
+ 3. Code (compress backup)
1495
+ const zlib = require('zlib');
1496
+ // Compress backup.sql to backup.sql.gz
1497
+
1498
+ 4. AWS S3 (upload compressed backup)
1499
+ - Bucket: backups
1500
+ - Key: db/backup-{{$now.format('YYYY-MM-DD')}}.sql.gz
1501
+
1502
+ 5. AWS S3 (list old backups)
1503
+ - Keep last 30 days only
1504
+
1505
+ 6. AWS S3 (delete old backups)
1506
+
1507
+ 7. IF (error occurred)
1508
+ ├─ PagerDuty (critical alert)
1509
+ └─ Email (backup failed!)
1510
+ ELSE
1511
+ └─ Slack (#devops: "Backup completed")
1512
+ ```
1513
+
1514
+ ### 7. Content Publishing
1515
+
1516
+ **Flow**: Schedule -> Fetch content -> Format -> Publish
1517
+
1518
+ **Example** (Automated social media posts):
1519
+
1520
+ ```
1521
+ 1. Schedule (every 3 hours during business hours)
1522
+ - Cron: 0 9,12,15,18 * * 1-5
1523
+
1524
+ 2. Google Sheets (read content queue)
1525
+ - Sheet: "Scheduled Posts"
1526
+ - Filter: status=pending AND publish_time <= NOW()
1527
+
1528
+ 3. IF (posts available)
1529
+
1530
+ 4. HTTP Request (shorten URLs in post)
1531
+
1532
+ 5. HTTP Request (POST to Twitter API)
1533
+
1534
+ 6. HTTP Request (POST to LinkedIn API)
1535
+
1536
+ 7. Google Sheets (update status=published)
1537
+
1538
+ 8. Slack (notify #marketing: "Posted: {{$json.title}}")
1539
+ ```
1540
+
1541
+ ---
1542
+
1543
+ ## Timezone Considerations
1544
+
1545
+ ### Set Workflow Timezone
1546
+
1547
+ ```javascript
1548
+ // In workflow settings
1549
+ {
1550
+ timezone: "America/New_York"; // EST/EDT
1551
+ }
1552
+ ```
1553
+
1554
+ ### Common Timezones
1555
+
1556
+ ```
1557
+ America/New_York - Eastern (US)
1558
+ America/Chicago - Central (US)
1559
+ America/Denver - Mountain (US)
1560
+ America/Los_Angeles - Pacific (US)
1561
+ Europe/London - GMT/BST
1562
+ Europe/Paris - CET/CEST
1563
+ Asia/Tokyo - JST
1564
+ Australia/Sydney - AEDT
1565
+ UTC - Universal Time
1566
+ ```
1567
+
1568
+ ### Handle Daylight Saving
1569
+
1570
+ **Best practice**: Use timezone-aware scheduling
1571
+
1572
+ ```javascript
1573
+ // Bad: UTC schedule for "9 AM local"
1574
+ // Will be off by 1 hour during DST transitions
1575
+
1576
+ // Good: Set workflow timezone
1577
+ {
1578
+ timezone: "America/New_York",
1579
+ schedule: {
1580
+ mode: "daysAndHours",
1581
+ hour: 9 // Always 9 AM Eastern, regardless of DST
1582
+ }
1583
+ }
1584
+ ```
1585
+
1586
+ ---
1587
+
1588
+ ## Error Handling
1589
+
1590
+ ### Pattern 1: Error Trigger Workflow
1591
+
1592
+ **Main workflow**: Normal execution
1593
+ **Error workflow**: Alerts and recovery
1594
+
1595
+ **Main**:
1596
+
1597
+ ```
1598
+ Schedule -> Fetch -> Process -> Deliver
1599
+ ```
1600
+
1601
+ **Error**:
1602
+
1603
+ ```
1604
+ Error Trigger (for main workflow)
1605
+ -> Set (extract error details)
1606
+ -> Slack (#ops-team: "Scheduled job failed")
1607
+ -> Email (admin alert)
1608
+ -> Postgres (log error for analysis)
1609
+ ```
1610
+
1611
+ ### Pattern 2: Retry with Backoff
1612
+
1613
+ ```
1614
+ Schedule -> HTTP Request (continueOnFail: true)
1615
+ -> IF (error)
1616
+ ├─ Wait (5 minutes)
1617
+ ├─ HTTP Request (retry 1)
1618
+ └─ IF (still error)
1619
+ ├─ Wait (15 minutes)
1620
+ ├─ HTTP Request (retry 2)
1621
+ └─ IF (still error)
1622
+ └─ Alert admin
1623
+ ```
1624
+
1625
+ ### Pattern 3: Partial Failure Handling
1626
+
1627
+ ```
1628
+ Schedule -> Split In Batches
1629
+ -> Process (continueOnFail: true)
1630
+ -> Code (track successes and failures)
1631
+ -> Report:
1632
+ "Processed: 95/100"
1633
+ "Failed: 5/100"
1634
+ ```
1635
+
1636
+ ---
1637
+
1638
+ ## Performance Optimization
1639
+
1640
+ ### 1. Batch Processing
1641
+
1642
+ For large datasets:
1643
+
1644
+ ```
1645
+ Schedule -> Query (LIMIT 10000)
1646
+ -> Split In Batches (100 items)
1647
+ -> Process batch
1648
+ -> Loop
1649
+ ```
1650
+
1651
+ ### 2. Parallel Processing
1652
+
1653
+ When operations are independent:
1654
+
1655
+ ```
1656
+ Schedule
1657
+ ├─ [Branch 1: Update DB]
1658
+ ├─ [Branch 2: Send emails]
1659
+ └─ [Branch 3: Generate report]
1660
+ -> Merge (wait for all) -> Final notification
1661
+ ```
1662
+
1663
+ ### 3. Skip if Already Running
1664
+
1665
+ Prevent overlapping executions:
1666
+
1667
+ ```
1668
+ Schedule -> Redis (check lock)
1669
+ -> IF (lock exists)
1670
+ └─ End (skip this execution)
1671
+ -> ELSE
1672
+ ├─ Redis (set lock, TTL 30 min)
1673
+ ├─ [Execute workflow]
1674
+ └─ Redis (delete lock)
1675
+ ```
1676
+
1677
+ ### 4. Early Exit on No Data
1678
+
1679
+ Don't waste time if nothing to process:
1680
+
1681
+ ```
1682
+ Schedule -> Query (check if work exists)
1683
+ -> IF (no results)
1684
+ └─ End workflow (exit early)
1685
+ -> ELSE
1686
+ └─ Process data
1687
+ ```
1688
+
1689
+ ---
1690
+
1691
+ ## Monitoring & Logging
1692
+
1693
+ ### Pattern 1: Execution Log Table
1694
+
1695
+ ```sql
1696
+ CREATE TABLE workflow_executions (
1697
+ id SERIAL PRIMARY KEY,
1698
+ workflow_name VARCHAR(255),
1699
+ started_at TIMESTAMP,
1700
+ completed_at TIMESTAMP,
1701
+ status VARCHAR(50),
1702
+ records_processed INT,
1703
+ error_message TEXT
1704
+ );
1705
+ ```
1706
+
1707
+ **Log execution**:
1708
+
1709
+ ```
1710
+ Schedule
1711
+ -> Set (record start)
1712
+ -> [Workflow logic]
1713
+ -> Postgres (INSERT execution log)
1714
+ ```
1715
+
1716
+ ### Pattern 2: Metrics Collection
1717
+
1718
+ ```
1719
+ Schedule -> [Execute]
1720
+ -> Code (calculate metrics)
1721
+ - Duration
1722
+ - Records processed
1723
+ - Success rate
1724
+ -> HTTP Request (send to monitoring system)
1725
+ - Datadog, Prometheus, etc.
1726
+ ```
1727
+
1728
+ ### Pattern 3: Summary Notifications
1729
+
1730
+ Daily/weekly execution summaries:
1731
+
1732
+ ```
1733
+ Schedule (daily at 6 PM) -> Query execution logs
1734
+ -> Code (aggregate today's executions)
1735
+ -> Email (summary report)
1736
+ "Today's Workflow Executions:
1737
+ - 24/24 successful
1738
+ - 0 failures
1739
+ - Avg duration: 2.3 min"
1740
+ ```
1741
+
1742
+ ---
1743
+
1744
+ ## Testing Scheduled Workflows
1745
+
1746
+ ### 1. Use Manual Trigger for Testing
1747
+
1748
+ **Development pattern**:
1749
+
1750
+ ```
1751
+ Manual Trigger (for testing)
1752
+ -> [Same workflow logic]
1753
+ -> [Outputs]
1754
+
1755
+ // Once tested, replace with Schedule Trigger
1756
+ ```
1757
+
1758
+ ### 2. Test with Different Times
1759
+
1760
+ ```javascript
1761
+ // Code node - simulate different times
1762
+ const testTime = new Date("2024-01-15T09:00:00Z");
1763
+ return [{ json: { currentTime: testTime } }];
1764
+ ```
1765
+
1766
+ ### 3. Dry Run Mode
1767
+
1768
+ ```
1769
+ Schedule -> Set (dryRun: true)
1770
+ -> IF (dryRun)
1771
+ └─ Log what would happen (don't execute)
1772
+ -> ELSE
1773
+ └─ Execute normally
1774
+ ```
1775
+
1776
+ ### 4. Shorter Interval for Testing
1777
+
1778
+ ```javascript
1779
+ // Testing: every 1 minute
1780
+ {
1781
+ mode: "interval",
1782
+ interval: 1,
1783
+ unit: "minutes"
1784
+ }
1785
+
1786
+ // Production: every 1 hour
1787
+ {
1788
+ mode: "interval",
1789
+ interval: 1,
1790
+ unit: "hours"
1791
+ }
1792
+ ```
1793
+
1794
+ ---
1795
+
1796
+ ## Scheduled Tasks Common Gotchas
1797
+
1798
+ ### 1. Wrong: Ignoring timezone
1799
+
1800
+ ```javascript
1801
+ Schedule (9 AM) // 9 AM in which timezone?
1802
+ ```
1803
+
1804
+ ### Correct: Set workflow timezone
1805
+
1806
+ ```javascript
1807
+ // Workflow settings
1808
+ {
1809
+ timezone: "America/New_York";
1810
+ }
1811
+ ```
1812
+
1813
+ ### 2. Wrong: Overlapping executions
1814
+
1815
+ ```
1816
+ Schedule (every 5 min) -> Long-running task (10 min)
1817
+ // Two executions running simultaneously!
1818
+ ```
1819
+
1820
+ ### Correct: Add execution lock
1821
+
1822
+ ```
1823
+ Schedule -> Redis (check lock)
1824
+ -> IF (locked) -> Skip
1825
+ -> ELSE -> Execute
1826
+ ```
1827
+
1828
+ ### 3. Wrong: No error handling
1829
+
1830
+ ```
1831
+ Schedule -> API call -> Process (fails silently)
1832
+ ```
1833
+
1834
+ ### Correct: Add error workflow
1835
+
1836
+ ```
1837
+ Main: Schedule -> Execute
1838
+ Error: Error Trigger -> Alert
1839
+ ```
1840
+
1841
+ ### 4. Wrong: Processing all data at once
1842
+
1843
+ ```
1844
+ Schedule -> SELECT 1000000 records -> Process (OOM)
1845
+ ```
1846
+
1847
+ ### Correct: Batch processing
1848
+
1849
+ ```
1850
+ Schedule -> SELECT with pagination -> Split In Batches -> Process
1851
+ ```
1852
+
1853
+ ### 5. Wrong: Hardcoded dates
1854
+
1855
+ ```javascript
1856
+ query: "SELECT * FROM orders WHERE date = '2024-01-15'";
1857
+ ```
1858
+
1859
+ ### Correct: Dynamic dates
1860
+
1861
+ ```javascript
1862
+ query: "SELECT * FROM orders WHERE date = CURRENT_DATE - INTERVAL '1 day'";
1863
+ ```
1864
+
1865
+ ---
1866
+
1867
+ ## Real Scheduled Template Examples
1868
+
1869
+ From n8n template library:
1870
+
1871
+ **Template #2947** (Weather to Slack):
1872
+
1873
+ ```
1874
+ Schedule (daily 8 AM)
1875
+ -> HTTP Request (weather API)
1876
+ -> Set (format message)
1877
+ -> Slack (post to #general)
1878
+ ```
1879
+
1880
+ **Daily backup**:
1881
+
1882
+ ```
1883
+ Schedule (nightly 2 AM)
1884
+ -> Postgres (export data)
1885
+ -> Google Drive (upload)
1886
+ -> Email (confirmation)
1887
+ ```
1888
+
1889
+ **Monitoring**:
1890
+
1891
+ ```
1892
+ Schedule (every 5 min)
1893
+ -> HTTP Request (health check)
1894
+ -> IF (down) -> PagerDuty alert
1895
+ ```
1896
+
1897
+ Use `search_templates({query: "schedule"})` to find more!
1898
+
1899
+ ---
1900
+
1901
+ ## Checklist for Scheduled Workflows
1902
+
1903
+ ### Planning
1904
+
1905
+ - [ ] Define schedule frequency (interval, cron, days & hours)
1906
+ - [ ] Set workflow timezone
1907
+ - [ ] Estimate execution duration
1908
+ - [ ] Plan for failures and retries
1909
+ - [ ] Consider timezone and DST
1910
+
1911
+ ### Implementation
1912
+
1913
+ - [ ] Configure Schedule Trigger
1914
+ - [ ] Set workflow timezone in settings
1915
+ - [ ] Add early exit for no-op cases
1916
+ - [ ] Implement batch processing for large data
1917
+ - [ ] Add execution logging
1918
+
1919
+ ### Error Handling
1920
+
1921
+ - [ ] Create Error Trigger workflow
1922
+ - [ ] Implement retry logic
1923
+ - [ ] Add alert notifications
1924
+ - [ ] Log errors for analysis
1925
+ - [ ] Handle partial failures gracefully
1926
+
1927
+ ### Monitoring
1928
+
1929
+ - [ ] Log each execution (start, end, status)
1930
+ - [ ] Track metrics (duration, records, success rate)
1931
+ - [ ] Set up daily/weekly summaries
1932
+ - [ ] Alert on consecutive failures
1933
+ - [ ] Monitor resource usage
1934
+
1935
+ ### Testing
1936
+
1937
+ - [ ] Test with Manual Trigger first
1938
+ - [ ] Verify timezone behavior
1939
+ - [ ] Test error scenarios
1940
+ - [ ] Check for overlapping executions
1941
+ - [ ] Validate output quality
1942
+
1943
+ ### Deployment
1944
+
1945
+ - [ ] Document workflow purpose
1946
+ - [ ] Set up monitoring
1947
+ - [ ] Configure alerts
1948
+ - [ ] Activate workflow in n8n UI (Manual activation required - API/MCP cannot activate)
1949
+ - [ ] Test in production (short interval first)
1950
+ - [ ] Monitor first few executions
1951
+
1952
+ ---
1953
+
1954
+ ## Advanced Patterns
1955
+
1956
+ ### Dynamic Scheduling
1957
+
1958
+ **Change schedule based on conditions**:
1959
+
1960
+ ```
1961
+ Schedule (check every hour) -> Code (check if it's time to run)
1962
+ -> IF (business hours AND weekday)
1963
+ └─ Execute workflow
1964
+ -> ELSE
1965
+ └─ Skip
1966
+ ```
1967
+
1968
+ ### Dependent Schedules
1969
+
1970
+ **Chain workflows**:
1971
+
1972
+ ```
1973
+ Workflow A (daily 2 AM): Data sync
1974
+ -> On completion -> Trigger Workflow B
1975
+
1976
+ Workflow B: Generate report (depends on fresh data)
1977
+ ```
1978
+
1979
+ ### Conditional Execution
1980
+
1981
+ **Skip based on external factors**:
1982
+
1983
+ ```
1984
+ Schedule -> HTTP Request (check feature flag)
1985
+ -> IF (feature enabled)
1986
+ └─ Execute
1987
+ -> ELSE
1988
+ └─ Skip
1989
+ ```
1990
+
1991
+ ---
1992
+
1993
+ ## Scheduled Tasks Summary
1994
+
1995
+ **Key Points**:
1996
+
1997
+ 1. **Set workflow timezone** explicitly
1998
+ 2. **Batch processing** for large datasets
1999
+ 3. **Error handling** is critical (Error Trigger + retries)
2000
+ 4. **Prevent overlaps** with execution locks
2001
+ 5. **Monitor and log** all executions
2002
+
2003
+ **Pattern**: Schedule -> Fetch -> Process -> Deliver -> Log
2004
+
2005
+ **Schedule Modes**:
2006
+
2007
+ - **Interval**: Simple recurring (every X minutes/hours)
2008
+ - **Days & Hours**: Specific days and times
2009
+ - **Cron**: Advanced complex schedules
2010
+
2011
+ **Related**:
2012
+
2013
+ - [expression-syntax.md](../expression-syntax.md) - Dynamic date expressions in queries
2014
+ - [code-javascript.md](../code-javascript.md) - Code node for aggregation and metrics
2015
+ - [node-configuration.md](../node-configuration.md) - Schedule Trigger and database node setup
2016
+
2017
+ ---
2018
+
2019
+ ---
2020
+
2021
+ # HTTP API Integration Pattern
2022
+
2023
+ **Use Case**: Fetch data from REST APIs, transform it, and use it in workflows.
2024
+
2025
+ ---
2026
+
2027
+ ## Pattern Structure
2028
+
2029
+ ```
2030
+ Trigger -> HTTP Request -> [Transform] -> [Action] -> [Error Handler]
2031
+ ```
2032
+
2033
+ **Key Characteristic**: External data fetching with error handling
2034
+
2035
+ ---
2036
+
2037
+ ## Core Components
2038
+
2039
+ ### 1. Trigger
2040
+
2041
+ **Options**:
2042
+
2043
+ - **Schedule** - Periodic fetching (most common)
2044
+ - **Webhook** - Triggered by external event
2045
+ - **Manual** - On-demand execution
2046
+
2047
+ ### 2. HTTP Request Node
2048
+
2049
+ **Purpose**: Call external REST APIs
2050
+
2051
+ **Configuration**:
2052
+
2053
+ ```javascript
2054
+ {
2055
+ method: "GET", // GET, POST, PUT, DELETE, PATCH
2056
+ url: "https://api.example.com/users",
2057
+ authentication: "predefinedCredentialType",
2058
+ sendQuery: true,
2059
+ queryParameters: {
2060
+ "page": "={{$json.page}}",
2061
+ "limit": "100"
2062
+ },
2063
+ sendHeaders: true,
2064
+ headerParameters: {
2065
+ "Accept": "application/json",
2066
+ "X-API-Version": "v1"
2067
+ }
2068
+ }
2069
+ ```
2070
+
2071
+ > Cross-reference: See [node-configuration.md](../node-configuration.md) for HTTP Request node setup details.
2072
+
2073
+ ### 3. Response Processing
2074
+
2075
+ **Purpose**: Extract and transform API response data
2076
+
2077
+ **Typical flow**:
2078
+
2079
+ ```
2080
+ HTTP Request -> Code (parse) -> Set (map fields) -> Action
2081
+ ```
2082
+
2083
+ ### 4. Action
2084
+
2085
+ **Common actions**:
2086
+
2087
+ - Store in database
2088
+ - Send to another API
2089
+ - Create notifications
2090
+ - Update spreadsheet
2091
+
2092
+ ### 5. Error Handler
2093
+
2094
+ **Purpose**: Handle API failures gracefully
2095
+
2096
+ **Error Trigger Workflow**:
2097
+
2098
+ ```
2099
+ Error Trigger -> Log Error -> Notify Admin -> Retry Logic (optional)
2100
+ ```
2101
+
2102
+ ---
2103
+
2104
+ ## Common Use Cases
2105
+
2106
+ ### 1. Data Fetching & Storage
2107
+
2108
+ **Flow**: Schedule -> HTTP Request -> Transform -> Database
2109
+
2110
+ **Example** (Fetch GitHub issues):
2111
+
2112
+ ```
2113
+ 1. Schedule (every hour)
2114
+ 2. HTTP Request
2115
+ - Method: GET
2116
+ - URL: https://api.github.com/repos/owner/repo/issues
2117
+ - Auth: Bearer Token
2118
+ - Query: state=open
2119
+ 3. Code (filter by labels)
2120
+ 4. Set (map to database schema)
2121
+ 5. Postgres (upsert issues)
2122
+ ```
2123
+
2124
+ **Response Handling**:
2125
+
2126
+ ```javascript
2127
+ // Code node - filter issues
2128
+ const issues = $input.all();
2129
+ return issues
2130
+ .filter((item) => item.json.labels.some((l) => l.name === "bug"))
2131
+ .map((item) => ({
2132
+ json: {
2133
+ id: item.json.id,
2134
+ title: item.json.title,
2135
+ created_at: item.json.created_at,
2136
+ },
2137
+ }));
2138
+ ```
2139
+
2140
+ > Cross-reference: See [code-javascript.md](../code-javascript.md) for `$input.all()`, `.filter()`, and `.map()` patterns in Code nodes.
2141
+
2142
+ ### 2. API to API Integration
2143
+
2144
+ **Flow**: Trigger -> Fetch from API A -> Transform -> Send to API B
2145
+
2146
+ **Example** (Jira to Slack):
2147
+
2148
+ ```
2149
+ 1. Schedule (every 15 minutes)
2150
+ 2. HTTP Request (GET Jira tickets updated today)
2151
+ 3. IF (check if tickets exist)
2152
+ 4. Set (format for Slack)
2153
+ 5. HTTP Request (POST to Slack webhook)
2154
+ ```
2155
+
2156
+ ### 3. Data Enrichment
2157
+
2158
+ **Flow**: Trigger -> Fetch base data -> Call enrichment API -> Combine -> Store
2159
+
2160
+ **Example** (Enrich contacts with company data):
2161
+
2162
+ ```
2163
+ 1. Postgres (SELECT new contacts)
2164
+ 2. Code (extract company domains)
2165
+ 3. HTTP Request (call Clearbit API for each domain)
2166
+ 4. Set (combine contact + company data)
2167
+ 5. Postgres (UPDATE contacts with enrichment)
2168
+ ```
2169
+
2170
+ ### 4. Monitoring & Alerting
2171
+
2172
+ **Flow**: Schedule -> Check API health -> IF unhealthy -> Alert
2173
+
2174
+ **Example** (API health check):
2175
+
2176
+ ```
2177
+ 1. Schedule (every 5 minutes)
2178
+ 2. HTTP Request (GET /health endpoint)
2179
+ 3. IF (status !== 200 OR response time > 2000ms)
2180
+ 4. Slack (alert #ops-team)
2181
+ 5. PagerDuty (create incident)
2182
+ ```
2183
+
2184
+ ### 5. Batch Processing
2185
+
2186
+ **Flow**: Trigger -> Fetch large dataset -> Split in Batches -> Process -> Loop
2187
+
2188
+ **Example** (Process all users):
2189
+
2190
+ ```
2191
+ 1. Manual Trigger
2192
+ 2. HTTP Request (GET /api/users?limit=1000)
2193
+ 3. Split In Batches (100 items per batch)
2194
+ 4. HTTP Request (POST /api/process for each batch)
2195
+ 5. Wait (2 seconds between batches - rate limiting)
2196
+ 6. Loop (back to step 4 until all processed)
2197
+ ```
2198
+
2199
+ ---
2200
+
2201
+ ## Authentication Methods
2202
+
2203
+ ### 1. None (Public APIs)
2204
+
2205
+ ```javascript
2206
+ {
2207
+ authentication: "none";
2208
+ }
2209
+ ```
2210
+
2211
+ ### 2. Bearer Token (Most Common)
2212
+
2213
+ **Setup**: Create credential
2214
+
2215
+ ```javascript
2216
+ {
2217
+ authentication: "predefinedCredentialType",
2218
+ nodeCredentialType: "httpHeaderAuth",
2219
+ headerAuth: {
2220
+ name: "Authorization",
2221
+ value: "Bearer YOUR_TOKEN"
2222
+ }
2223
+ }
2224
+ ```
2225
+
2226
+ **Access in workflow**:
2227
+
2228
+ ```javascript
2229
+ {
2230
+ authentication: "predefinedCredentialType",
2231
+ nodeCredentialType: "httpHeaderAuth"
2232
+ }
2233
+ ```
2234
+
2235
+ ### 3. API Key (Header or Query)
2236
+
2237
+ **Header auth**:
2238
+
2239
+ ```javascript
2240
+ {
2241
+ sendHeaders: true,
2242
+ headerParameters: {
2243
+ "X-API-Key": "={{$credentials.apiKey}}"
2244
+ }
2245
+ }
2246
+ ```
2247
+
2248
+ **Query auth**:
2249
+
2250
+ ```javascript
2251
+ {
2252
+ sendQuery: true,
2253
+ queryParameters: {
2254
+ "api_key": "={{$credentials.apiKey}}"
2255
+ }
2256
+ }
2257
+ ```
2258
+
2259
+ ### 4. Basic Auth
2260
+
2261
+ **Setup**: Create "Basic Auth" credential
2262
+
2263
+ ```javascript
2264
+ {
2265
+ authentication: "predefinedCredentialType",
2266
+ nodeCredentialType: "httpBasicAuth"
2267
+ }
2268
+ ```
2269
+
2270
+ ### 5. OAuth2
2271
+
2272
+ **Setup**: Create OAuth2 credential with:
2273
+
2274
+ - Authorization URL
2275
+ - Token URL
2276
+ - Client ID
2277
+ - Client Secret
2278
+ - Scopes
2279
+
2280
+ ```javascript
2281
+ {
2282
+ authentication: "predefinedCredentialType",
2283
+ nodeCredentialType: "oAuth2Api"
2284
+ }
2285
+ ```
2286
+
2287
+ ---
2288
+
2289
+ ## Handling API Responses
2290
+
2291
+ ### Success Response (200-299)
2292
+
2293
+ **Default**: Data flows to next node
2294
+
2295
+ **Access response**:
2296
+
2297
+ ```javascript
2298
+ // Entire response
2299
+ {
2300
+ {
2301
+ $json;
2302
+ }
2303
+ }
2304
+
2305
+ // Specific fields
2306
+ {
2307
+ {
2308
+ $json.data.id;
2309
+ }
2310
+ }
2311
+ {
2312
+ {
2313
+ $json.results[0].name;
2314
+ }
2315
+ }
2316
+ ```
2317
+
2318
+ > Cross-reference: See [expression-syntax.md](../expression-syntax.md) for nested access and array indexing patterns.
2319
+
2320
+ ### Pagination
2321
+
2322
+ #### Pattern 1: Offset-based
2323
+
2324
+ ```
2325
+ 1. Set (initialize: page=1, has_more=true)
2326
+ 2. HTTP Request (GET /api/items?page={{$json.page}})
2327
+ 3. Code (check if more pages)
2328
+ 4. IF (has_more === true)
2329
+ └-> Set (increment page) -> Loop to step 2
2330
+ ```
2331
+
2332
+ **Code node** (check pagination):
2333
+
2334
+ ```javascript
2335
+ const items = $input.first().json;
2336
+ const currentPage = $json.page || 1;
2337
+
2338
+ return [
2339
+ {
2340
+ json: {
2341
+ items: items.results,
2342
+ page: currentPage + 1,
2343
+ has_more: items.next !== null,
2344
+ },
2345
+ },
2346
+ ];
2347
+ ```
2348
+
2349
+ #### Pattern 2: Cursor-based
2350
+
2351
+ ```
2352
+ 1. HTTP Request (GET /api/items)
2353
+ 2. Code (extract next_cursor)
2354
+ 3. IF (next_cursor exists)
2355
+ └-> Set (cursor={{$json.next_cursor}}) -> Loop to step 1
2356
+ ```
2357
+
2358
+ #### Pattern 3: Link Header
2359
+
2360
+ ```javascript
2361
+ // Code node - parse Link header
2362
+ const linkHeader = $input.first().json.headers["link"];
2363
+ const hasNext = linkHeader && linkHeader.includes('rel="next"');
2364
+
2365
+ return [
2366
+ {
2367
+ json: {
2368
+ items: $input.first().json.body,
2369
+ has_next: hasNext,
2370
+ next_url: hasNext ? parseNextUrl(linkHeader) : null,
2371
+ },
2372
+ },
2373
+ ];
2374
+ ```
2375
+
2376
+ ### Error Responses (400-599)
2377
+
2378
+ **Configure HTTP Request**:
2379
+
2380
+ ```javascript
2381
+ {
2382
+ continueOnFail: true, // Don't stop workflow on error
2383
+ ignoreResponseCode: true // Get response even on error
2384
+ }
2385
+ ```
2386
+
2387
+ **Handle errors**:
2388
+
2389
+ ```
2390
+ HTTP Request (continueOnFail: true)
2391
+ -> IF (check error)
2392
+ ├─ [Success Path]
2393
+ └─ [Error Path] -> Log -> Retry or Alert
2394
+ ```
2395
+
2396
+ **IF condition**:
2397
+
2398
+ ```javascript
2399
+ {{$json.error}} is empty
2400
+ // OR
2401
+ {{$json.statusCode}} < 400
2402
+ ```
2403
+
2404
+ ---
2405
+
2406
+ ## Rate Limiting
2407
+
2408
+ ### Pattern 1: Wait Between Requests
2409
+
2410
+ ```
2411
+ Split In Batches (1 item per batch)
2412
+ -> HTTP Request
2413
+ -> Wait (1 second)
2414
+ -> Loop
2415
+ ```
2416
+
2417
+ ### Pattern 2: Exponential Backoff
2418
+
2419
+ ```javascript
2420
+ // Code node
2421
+ const maxRetries = 3;
2422
+ let retryCount = $json.retryCount || 0;
2423
+
2424
+ if ($json.error && retryCount < maxRetries) {
2425
+ const delay = Math.pow(2, retryCount) * 1000; // 1s, 2s, 4s
2426
+
2427
+ return [
2428
+ {
2429
+ json: {
2430
+ ...$json,
2431
+ retryCount: retryCount + 1,
2432
+ waitTime: delay,
2433
+ },
2434
+ },
2435
+ ];
2436
+ }
2437
+ ```
2438
+
2439
+ ### Pattern 3: Respect Rate Limit Headers
2440
+
2441
+ ```javascript
2442
+ // Code node - check rate limit
2443
+ const headers = $input.first().json.headers;
2444
+ const remaining = parseInt(headers["x-ratelimit-remaining"] || "999");
2445
+ const resetTime = parseInt(headers["x-ratelimit-reset"] || "0");
2446
+
2447
+ if (remaining < 10) {
2448
+ const now = Math.floor(Date.now() / 1000);
2449
+ const waitSeconds = resetTime - now;
2450
+
2451
+ return [
2452
+ {
2453
+ json: {
2454
+ shouldWait: true,
2455
+ waitSeconds: Math.max(waitSeconds, 0),
2456
+ },
2457
+ },
2458
+ ];
2459
+ }
2460
+
2461
+ return [{ json: { shouldWait: false } }];
2462
+ ```
2463
+
2464
+ ---
2465
+
2466
+ ## Request Configuration
2467
+
2468
+ ### GET Request
2469
+
2470
+ ```javascript
2471
+ {
2472
+ method: "GET",
2473
+ url: "https://api.example.com/users",
2474
+ sendQuery: true,
2475
+ queryParameters: {
2476
+ "page": "1",
2477
+ "limit": "100",
2478
+ "filter": "active"
2479
+ }
2480
+ }
2481
+ ```
2482
+
2483
+ ### POST Request (JSON Body)
2484
+
2485
+ ```javascript
2486
+ {
2487
+ method: "POST",
2488
+ url: "https://api.example.com/users",
2489
+ sendBody: true,
2490
+ bodyParametersJson: JSON.stringify({
2491
+ name: "={{$json.name}}",
2492
+ email: "={{$json.email}}",
2493
+ role: "user"
2494
+ })
2495
+ }
2496
+ ```
2497
+
2498
+ ### POST Request (Form Data)
2499
+
2500
+ ```javascript
2501
+ {
2502
+ method: "POST",
2503
+ url: "https://api.example.com/upload",
2504
+ sendBody: true,
2505
+ bodyParametersUi: {
2506
+ parameter: [
2507
+ { name: "file", value: "={{$json.fileData}}" },
2508
+ { name: "filename", value: "={{$json.filename}}" }
2509
+ ]
2510
+ },
2511
+ sendHeaders: true,
2512
+ headerParameters: {
2513
+ "Content-Type": "multipart/form-data"
2514
+ }
2515
+ }
2516
+ ```
2517
+
2518
+ ### PUT/PATCH Request (Update)
2519
+
2520
+ ```javascript
2521
+ {
2522
+ method: "PATCH",
2523
+ url: "https://api.example.com/users/={{$json.userId}}",
2524
+ sendBody: true,
2525
+ bodyParametersJson: JSON.stringify({
2526
+ status: "active",
2527
+ last_updated: "={{$now}}"
2528
+ })
2529
+ }
2530
+ ```
2531
+
2532
+ ### DELETE Request
2533
+
2534
+ ```javascript
2535
+ {
2536
+ method: "DELETE",
2537
+ url: "https://api.example.com/users/={{$json.userId}}"
2538
+ }
2539
+ ```
2540
+
2541
+ ---
2542
+
2543
+ ## Error Handling Patterns
2544
+
2545
+ ### Pattern 1: Retry on Failure
2546
+
2547
+ ```
2548
+ HTTP Request (continueOnFail: true)
2549
+ -> IF (error occurred)
2550
+ └-> Wait (5 seconds)
2551
+ └-> HTTP Request (retry)
2552
+ ```
2553
+
2554
+ ### Pattern 2: Fallback API
2555
+
2556
+ ```
2557
+ HTTP Request (Primary API, continueOnFail: true)
2558
+ -> IF (failed)
2559
+ └-> HTTP Request (Fallback API)
2560
+ ```
2561
+
2562
+ ### Pattern 3: Error Trigger Workflow
2563
+
2564
+ **Main Workflow**:
2565
+
2566
+ ```
2567
+ HTTP Request -> Process Data
2568
+ ```
2569
+
2570
+ **Error Workflow**:
2571
+
2572
+ ```
2573
+ Error Trigger
2574
+ -> Set (extract error details)
2575
+ -> Slack (alert team)
2576
+ -> Database (log error for analysis)
2577
+ ```
2578
+
2579
+ ### Pattern 4: Circuit Breaker
2580
+
2581
+ ```javascript
2582
+ // Code node - circuit breaker logic
2583
+ const failures = $json.recentFailures || 0;
2584
+ const threshold = 5;
2585
+
2586
+ if (failures >= threshold) {
2587
+ throw new Error("Circuit breaker open - too many failures");
2588
+ }
2589
+
2590
+ return [{ json: { canProceed: true } }];
2591
+ ```
2592
+
2593
+ > Cross-reference: See [code-javascript.md](../code-javascript.md) for error handling and `throw` patterns in Code nodes.
2594
+
2595
+ ---
2596
+
2597
+ ## Response Transformation
2598
+
2599
+ ### Extract Nested Data
2600
+
2601
+ ```javascript
2602
+ // Code node
2603
+ const response = $input.first().json;
2604
+
2605
+ return response.data.items.map((item) => ({
2606
+ json: {
2607
+ id: item.id,
2608
+ name: item.attributes.name,
2609
+ email: item.attributes.contact.email,
2610
+ },
2611
+ }));
2612
+ ```
2613
+
2614
+ ### Flatten Arrays
2615
+
2616
+ ```javascript
2617
+ // Code node - flatten nested array
2618
+ const items = $input.all();
2619
+ const flattened = items.flatMap((item) =>
2620
+ item.json.results.map((result) => ({
2621
+ json: {
2622
+ parent_id: item.json.id,
2623
+ ...result,
2624
+ },
2625
+ })),
2626
+ );
2627
+
2628
+ return flattened;
2629
+ ```
2630
+
2631
+ ### Combine Multiple API Responses
2632
+
2633
+ ```
2634
+ HTTP Request 1 (users)
2635
+ -> Set (store users)
2636
+ -> HTTP Request 2 (orders for each user)
2637
+ -> Merge (combine users + orders)
2638
+ ```
2639
+
2640
+ ---
2641
+
2642
+ ## Testing & Debugging
2643
+
2644
+ ### 1. Test with Manual Trigger
2645
+
2646
+ Replace Schedule with Manual Trigger for testing
2647
+
2648
+ ### 2. Use Postman/Insomnia First
2649
+
2650
+ - Test API outside n8n
2651
+ - Understand response structure
2652
+ - Verify authentication
2653
+
2654
+ ### 3. Log Responses
2655
+
2656
+ ```javascript
2657
+ // Code node - log for debugging
2658
+ console.log("API Response:", JSON.stringify($input.first().json, null, 2));
2659
+ return $input.all();
2660
+ ```
2661
+
2662
+ ### 4. Check Execution Data
2663
+
2664
+ - View node output in n8n UI
2665
+ - Check headers, body, status code
2666
+ - Verify data structure
2667
+
2668
+ ### 5. Use Binary Data Properly
2669
+
2670
+ For file downloads:
2671
+
2672
+ ```javascript
2673
+ {
2674
+ method: "GET",
2675
+ url: "https://api.example.com/download/file.pdf",
2676
+ responseFormat: "file", // Important for binary data
2677
+ outputPropertyName: "data"
2678
+ }
2679
+ ```
2680
+
2681
+ ---
2682
+
2683
+ ## Performance Optimization
2684
+
2685
+ ### 1. Parallel Requests
2686
+
2687
+ Use **Split In Batches** with multiple items:
2688
+
2689
+ ```
2690
+ Set (create array of IDs)
2691
+ -> Split In Batches (10 items per batch)
2692
+ -> HTTP Request (processes all 10 in parallel)
2693
+ -> Loop
2694
+ ```
2695
+
2696
+ ### 2. Caching
2697
+
2698
+ ```
2699
+ IF (check cache exists)
2700
+ ├─ [Cache Hit] -> Use cached data
2701
+ └─ [Cache Miss] -> HTTP Request -> Store in cache
2702
+ ```
2703
+
2704
+ ### 3. Conditional Fetching
2705
+
2706
+ Only fetch if data changed:
2707
+
2708
+ ```
2709
+ HTTP Request (GET with If-Modified-Since header)
2710
+ -> IF (status === 304)
2711
+ └─ Use existing data
2712
+ -> IF (status === 200)
2713
+ └─ Process new data
2714
+ ```
2715
+
2716
+ ### 4. Batch API Calls
2717
+
2718
+ If API supports batch operations:
2719
+
2720
+ ```javascript
2721
+ {
2722
+ method: "POST",
2723
+ url: "https://api.example.com/batch",
2724
+ bodyParametersJson: JSON.stringify({
2725
+ requests: $json.items.map(item => ({
2726
+ method: "GET",
2727
+ url: `/users/${item.id}`
2728
+ }))
2729
+ })
2730
+ }
2731
+ ```
2732
+
2733
+ ---
2734
+
2735
+ ## HTTP API Common Gotchas
2736
+
2737
+ ### 1. Wrong: Hardcoded URLs
2738
+
2739
+ ```javascript
2740
+ url: "https://api.example.com/prod/users";
2741
+ ```
2742
+
2743
+ ### Correct: Use environment variables
2744
+
2745
+ ```javascript
2746
+ url: "={{$env.API_BASE_URL}}/users";
2747
+ ```
2748
+
2749
+ ### 2. Wrong: Credentials in parameters
2750
+
2751
+ ```javascript
2752
+ headerParameters: {
2753
+ "Authorization": "Bearer sk-abc123xyz" // Exposed!
2754
+ }
2755
+ ```
2756
+
2757
+ ### Correct: Use credentials system
2758
+
2759
+ ```javascript
2760
+ authentication: "predefinedCredentialType",
2761
+ nodeCredentialType: "httpHeaderAuth"
2762
+ ```
2763
+
2764
+ ### 3. Wrong: No error handling
2765
+
2766
+ ```javascript
2767
+ HTTP Request -> Process (fails if API down)
2768
+ ```
2769
+
2770
+ ### Correct: Handle errors
2771
+
2772
+ ```javascript
2773
+ HTTP Request (continueOnFail: true) -> IF (error) -> Handle
2774
+ ```
2775
+
2776
+ ### 4. Wrong: Blocking on large responses
2777
+
2778
+ Processing 10,000 items synchronously
2779
+
2780
+ ### Correct: Use batching
2781
+
2782
+ ```
2783
+ Split In Batches (100 items) -> Process -> Loop
2784
+ ```
2785
+
2786
+ ---
2787
+
2788
+ ## Real HTTP API Template Examples
2789
+
2790
+ From n8n template library (892 API integration templates):
2791
+
2792
+ **GitHub to Notion**:
2793
+
2794
+ ```
2795
+ Schedule -> HTTP Request (GitHub API) -> Transform -> HTTP Request (Notion API)
2796
+ ```
2797
+
2798
+ **Weather to Slack**:
2799
+
2800
+ ```
2801
+ Schedule -> HTTP Request (Weather API) -> Set (format) -> Slack
2802
+ ```
2803
+
2804
+ **CRM Sync**:
2805
+
2806
+ ```
2807
+ Schedule -> HTTP Request (CRM A) -> Transform -> HTTP Request (CRM B)
2808
+ ```
2809
+
2810
+ Use `search_templates({query: "http api"})` to find more!
2811
+
2812
+ ---
2813
+
2814
+ ## Checklist for API Integration
2815
+
2816
+ ### Planning
2817
+
2818
+ - [ ] Test API with Postman/curl first
2819
+ - [ ] Understand response structure
2820
+ - [ ] Check rate limits
2821
+ - [ ] Review authentication method
2822
+ - [ ] Plan error handling
2823
+
2824
+ ### Implementation
2825
+
2826
+ - [ ] Use credentials (never hardcode)
2827
+ - [ ] Configure proper HTTP method
2828
+ - [ ] Set correct headers (Content-Type, Accept)
2829
+ - [ ] Handle pagination if needed
2830
+ - [ ] Add query parameters properly
2831
+
2832
+ ### Error Handling
2833
+
2834
+ - [ ] Set continueOnFail: true if needed
2835
+ - [ ] Check response status codes
2836
+ - [ ] Implement retry logic
2837
+ - [ ] Add Error Trigger workflow
2838
+ - [ ] Alert on failures
2839
+
2840
+ ### Performance
2841
+
2842
+ - [ ] Use batching for large datasets
2843
+ - [ ] Add rate limiting if needed
2844
+ - [ ] Consider caching
2845
+ - [ ] Test with production load
2846
+
2847
+ ### Security
2848
+
2849
+ - [ ] Use HTTPS only
2850
+ - [ ] Store secrets in credentials
2851
+ - [ ] Validate API responses
2852
+ - [ ] Use environment variables
2853
+
2854
+ ---
2855
+
2856
+ ## HTTP API Summary
2857
+
2858
+ **Key Points**:
2859
+
2860
+ 1. **Authentication** via credentials system (never hardcode)
2861
+ 2. **Error handling** is critical (continueOnFail + IF checks)
2862
+ 3. **Pagination** for large datasets
2863
+ 4. **Rate limiting** to respect API limits
2864
+ 5. **Transform responses** to match your needs
2865
+
2866
+ **Pattern**: Trigger -> HTTP Request -> Transform -> Action -> Error Handler
2867
+
2868
+ **Related**:
2869
+
2870
+ - [expression-syntax.md](../expression-syntax.md) - Dynamic URL and parameter expressions
2871
+ - [node-configuration.md](../node-configuration.md) - HTTP Request node configuration
2872
+ - [code-javascript.md](../code-javascript.md) - Response parsing and transformation logic
2873
+
2874
+ ---
2875
+
2876
+ ---
2877
+
2878
+ # Database Operations Pattern
2879
+
2880
+ **Use Case**: Read, write, sync, and manage database data in workflows.
2881
+
2882
+ ---
2883
+
2884
+ ## Pattern Structure
2885
+
2886
+ ```
2887
+ Trigger -> [Query/Read] -> [Transform] -> [Write/Update] -> [Verify/Log]
2888
+ ```
2889
+
2890
+ **Key Characteristic**: Data persistence and synchronization
2891
+
2892
+ ---
2893
+
2894
+ ## Core Components
2895
+
2896
+ ### 1. Trigger
2897
+
2898
+ **Options**:
2899
+
2900
+ - **Schedule** - Periodic sync/maintenance (most common)
2901
+ - **Webhook** - Event-driven writes
2902
+ - **Manual** - One-time operations
2903
+
2904
+ ### 2. Database Read Nodes
2905
+
2906
+ **Supported databases**:
2907
+
2908
+ - Postgres
2909
+ - MySQL
2910
+ - MongoDB
2911
+ - Microsoft SQL
2912
+ - SQLite
2913
+ - Redis
2914
+ - And more via community nodes
2915
+
2916
+ ### 3. Transform
2917
+
2918
+ **Purpose**: Map between different database schemas or formats
2919
+
2920
+ **Typical nodes**:
2921
+
2922
+ - **Set** - Field mapping
2923
+ - **Code** - Complex transformations
2924
+ - **Merge** - Combine data from multiple sources
2925
+
2926
+ ### 4. Database Write Nodes
2927
+
2928
+ **Operations**:
2929
+
2930
+ - INSERT - Create new records
2931
+ - UPDATE - Modify existing records
2932
+ - UPSERT - Insert or update
2933
+ - DELETE - Remove records
2934
+
2935
+ ### 5. Verification
2936
+
2937
+ **Purpose**: Confirm operations succeeded
2938
+
2939
+ **Methods**:
2940
+
2941
+ - Query to verify records
2942
+ - Count rows affected
2943
+ - Log results
2944
+
2945
+ ---
2946
+
2947
+ ## Common Use Cases
2948
+
2949
+ ### 1. Data Synchronization
2950
+
2951
+ **Flow**: Schedule -> Read Source DB -> Transform -> Write Target DB -> Log
2952
+
2953
+ **Example** (Postgres to MySQL sync):
2954
+
2955
+ ```
2956
+ 1. Schedule (every 15 minutes)
2957
+ 2. Postgres (SELECT * FROM users WHERE updated_at > {{$json.last_sync}})
2958
+ 3. IF (check if records exist)
2959
+ 4. Set (map Postgres schema to MySQL schema)
2960
+ 5. MySQL (INSERT or UPDATE users)
2961
+ 6. Postgres (UPDATE sync_log SET last_sync = NOW())
2962
+ 7. Slack (notify: "Synced X users")
2963
+ ```
2964
+
2965
+ **Incremental sync query**:
2966
+
2967
+ ```sql
2968
+ SELECT *
2969
+ FROM users
2970
+ WHERE updated_at > $1
2971
+ ORDER BY updated_at ASC
2972
+ LIMIT 1000
2973
+ ```
2974
+
2975
+ **Parameters**:
2976
+
2977
+ ```javascript
2978
+ {
2979
+ "parameters": [
2980
+ "={{$node['Get Last Sync'].json.last_sync}}"
2981
+ ]
2982
+ }
2983
+ ```
2984
+
2985
+ > Cross-reference: See [expression-syntax.md](../expression-syntax.md) for `$node[...]` reference syntax.
2986
+
2987
+ ### 2. ETL (Extract, Transform, Load)
2988
+
2989
+ **Flow**: Extract from multiple sources -> Transform -> Load into warehouse
2990
+
2991
+ **Example** (Consolidate data):
2992
+
2993
+ ```
2994
+ 1. Schedule (daily at 2 AM)
2995
+ 2. [Parallel branches]
2996
+ ├─ Postgres (SELECT orders)
2997
+ ├─ MySQL (SELECT customers)
2998
+ └─ MongoDB (SELECT products)
2999
+ 3. Merge (combine all data)
3000
+ 4. Code (transform to warehouse schema)
3001
+ 5. Postgres (warehouse - INSERT into fact_sales)
3002
+ 6. Email (send summary report)
3003
+ ```
3004
+
3005
+ ### 3. Data Validation & Cleanup
3006
+
3007
+ **Flow**: Schedule -> Query -> Validate -> Update/Delete invalid records
3008
+
3009
+ **Example** (Clean orphaned records):
3010
+
3011
+ ```
3012
+ 1. Schedule (weekly)
3013
+ 2. Postgres (SELECT users WHERE email IS NULL OR email = '')
3014
+ 3. IF (invalid records exist)
3015
+ 4. Postgres (UPDATE users SET status='inactive' WHERE email IS NULL)
3016
+ 5. Postgres (DELETE FROM users WHERE created_at < NOW() - INTERVAL '1 year' AND status='inactive')
3017
+ 6. Slack (alert: "Cleaned X invalid records")
3018
+ ```
3019
+
3020
+ ### 4. Backup & Archive
3021
+
3022
+ **Flow**: Schedule -> Query -> Export -> Store
3023
+
3024
+ **Example** (Archive old records):
3025
+
3026
+ ```
3027
+ 1. Schedule (monthly)
3028
+ 2. Postgres (SELECT * FROM orders WHERE created_at < NOW() - INTERVAL '2 years')
3029
+ 3. Code (convert to JSON)
3030
+ 4. Write File (save to archive.json)
3031
+ 5. Google Drive (upload archive)
3032
+ 6. Postgres (DELETE FROM orders WHERE created_at < NOW() - INTERVAL '2 years')
3033
+ ```
3034
+
3035
+ ### 5. Real-time Data Updates
3036
+
3037
+ **Flow**: Webhook -> Parse -> Update Database
3038
+
3039
+ **Example** (Update user status):
3040
+
3041
+ ```
3042
+ 1. Webhook (receive status update)
3043
+ 2. Postgres (UPDATE users SET status = {{$json.body.status}} WHERE id = {{$json.body.user_id}})
3044
+ 3. IF (rows affected > 0)
3045
+ 4. Redis (SET user:{{$json.body.user_id}}:status {{$json.body.status}})
3046
+ 5. Webhook Response ({"success": true})
3047
+ ```
3048
+
3049
+ ---
3050
+
3051
+ ## Database Node Configuration
3052
+
3053
+ ### Postgres
3054
+
3055
+ #### SELECT Query
3056
+
3057
+ ```javascript
3058
+ {
3059
+ operation: "executeQuery",
3060
+ query: "SELECT id, name, email FROM users WHERE created_at > $1 LIMIT $2",
3061
+ parameters: [
3062
+ "={{$json.since_date}}",
3063
+ "100"
3064
+ ]
3065
+ }
3066
+ ```
3067
+
3068
+ #### INSERT
3069
+
3070
+ ```javascript
3071
+ {
3072
+ operation: "insert",
3073
+ table: "users",
3074
+ columns: "id, name, email, created_at",
3075
+ values: [
3076
+ {
3077
+ id: "={{$json.id}}",
3078
+ name: "={{$json.name}}",
3079
+ email: "={{$json.email}}",
3080
+ created_at: "={{$now}}"
3081
+ }
3082
+ ]
3083
+ }
3084
+ ```
3085
+
3086
+ #### UPDATE
3087
+
3088
+ ```javascript
3089
+ {
3090
+ operation: "update",
3091
+ table: "users",
3092
+ updateKey: "id",
3093
+ columns: "name, email, updated_at",
3094
+ values: {
3095
+ id: "={{$json.id}}",
3096
+ name: "={{$json.name}}",
3097
+ email: "={{$json.email}}",
3098
+ updated_at: "={{$now}}"
3099
+ }
3100
+ }
3101
+ ```
3102
+
3103
+ #### UPSERT (INSERT ... ON CONFLICT)
3104
+
3105
+ ```javascript
3106
+ {
3107
+ operation: "executeQuery",
3108
+ query: `
3109
+ INSERT INTO users (id, name, email)
3110
+ VALUES ($1, $2, $3)
3111
+ ON CONFLICT (id)
3112
+ DO UPDATE SET name = $2, email = $3, updated_at = NOW()
3113
+ `,
3114
+ parameters: [
3115
+ "={{$json.id}}",
3116
+ "={{$json.name}}",
3117
+ "={{$json.email}}"
3118
+ ]
3119
+ }
3120
+ ```
3121
+
3122
+ > Cross-reference: See [node-configuration.md](../node-configuration.md) for Postgres, MySQL, and MongoDB node setup.
3123
+
3124
+ ### MySQL
3125
+
3126
+ #### SELECT with JOIN
3127
+
3128
+ ```javascript
3129
+ {
3130
+ operation: "executeQuery",
3131
+ query: `
3132
+ SELECT u.id, u.name, o.order_id, o.total
3133
+ FROM users u
3134
+ LEFT JOIN orders o ON u.id = o.user_id
3135
+ WHERE u.created_at > ?
3136
+ `,
3137
+ parameters: [
3138
+ "={{$json.since_date}}"
3139
+ ]
3140
+ }
3141
+ ```
3142
+
3143
+ #### Bulk INSERT
3144
+
3145
+ ```javascript
3146
+ {
3147
+ operation: "insert",
3148
+ table: "orders",
3149
+ columns: "user_id, total, status",
3150
+ values: $json.orders // Array of objects
3151
+ }
3152
+ ```
3153
+
3154
+ ### MongoDB
3155
+
3156
+ #### Find Documents
3157
+
3158
+ ```javascript
3159
+ {
3160
+ operation: "find",
3161
+ collection: "users",
3162
+ query: JSON.stringify({
3163
+ created_at: { $gt: new Date($json.since_date) },
3164
+ status: "active"
3165
+ }),
3166
+ limit: 100
3167
+ }
3168
+ ```
3169
+
3170
+ #### Insert Document
3171
+
3172
+ ```javascript
3173
+ {
3174
+ operation: "insert",
3175
+ collection: "users",
3176
+ document: JSON.stringify({
3177
+ name: $json.name,
3178
+ email: $json.email,
3179
+ created_at: new Date()
3180
+ })
3181
+ }
3182
+ ```
3183
+
3184
+ #### Update Document
3185
+
3186
+ ```javascript
3187
+ {
3188
+ operation: "update",
3189
+ collection: "users",
3190
+ query: JSON.stringify({ _id: $json.user_id }),
3191
+ update: JSON.stringify({
3192
+ $set: {
3193
+ status: $json.status,
3194
+ updated_at: new Date()
3195
+ }
3196
+ })
3197
+ }
3198
+ ```
3199
+
3200
+ ---
3201
+
3202
+ ## Batch Processing
3203
+
3204
+ ### Pattern 1: Split In Batches
3205
+
3206
+ **Use when**: Processing large datasets to avoid memory issues
3207
+
3208
+ ```
3209
+ Postgres (SELECT 10000 records)
3210
+ -> Split In Batches (100 items per batch)
3211
+ -> Transform
3212
+ -> MySQL (write batch)
3213
+ -> Loop (until all processed)
3214
+ ```
3215
+
3216
+ ### Pattern 2: Paginated Queries
3217
+
3218
+ **Use when**: Database has millions of records
3219
+
3220
+ ```
3221
+ Set (initialize: offset=0, limit=1000)
3222
+ -> Loop Start
3223
+ -> Postgres (SELECT * FROM large_table LIMIT {{$json.limit}} OFFSET {{$json.offset}})
3224
+ -> IF (records returned)
3225
+ ├─ Process records
3226
+ ├─ Set (increment offset by 1000)
3227
+ └─ Loop back
3228
+ └─ [No records] -> End
3229
+ ```
3230
+
3231
+ **Query**:
3232
+
3233
+ ```sql
3234
+ SELECT * FROM large_table
3235
+ ORDER BY id
3236
+ LIMIT $1 OFFSET $2
3237
+ ```
3238
+
3239
+ ### Pattern 3: Cursor-Based Pagination
3240
+
3241
+ **Better performance for large datasets**:
3242
+
3243
+ ```
3244
+ Set (initialize: last_id=0)
3245
+ -> Loop Start
3246
+ -> Postgres (SELECT * FROM table WHERE id > {{$json.last_id}} ORDER BY id LIMIT 1000)
3247
+ -> IF (records returned)
3248
+ ├─ Process records
3249
+ ├─ Code (get max id from batch)
3250
+ └─ Loop back
3251
+ └─ [No records] -> End
3252
+ ```
3253
+
3254
+ **Query**:
3255
+
3256
+ ```sql
3257
+ SELECT * FROM table
3258
+ WHERE id > $1
3259
+ ORDER BY id ASC
3260
+ LIMIT 1000
3261
+ ```
3262
+
3263
+ ---
3264
+
3265
+ ## Transaction Handling
3266
+
3267
+ ### Pattern 1: BEGIN/COMMIT/ROLLBACK
3268
+
3269
+ **For databases that support transactions**:
3270
+
3271
+ ```javascript
3272
+ // Node 1: Begin Transaction
3273
+ {
3274
+ operation: "executeQuery",
3275
+ query: "BEGIN"
3276
+ }
3277
+
3278
+ // Node 2-N: Your operations
3279
+ {
3280
+ operation: "executeQuery",
3281
+ query: "INSERT INTO ...",
3282
+ continueOnFail: true
3283
+ }
3284
+
3285
+ // Node N+1: Commit or Rollback
3286
+ {
3287
+ operation: "executeQuery",
3288
+ query: "={{$node['Operation'].json.error ? 'ROLLBACK' : 'COMMIT'}}"
3289
+ }
3290
+ ```
3291
+
3292
+ ### Pattern 2: Atomic Operations
3293
+
3294
+ **Use database features for atomicity**:
3295
+
3296
+ ```sql
3297
+ -- Upsert example (atomic)
3298
+ INSERT INTO inventory (product_id, quantity)
3299
+ VALUES ($1, $2)
3300
+ ON CONFLICT (product_id)
3301
+ DO UPDATE SET quantity = inventory.quantity + $2
3302
+ ```
3303
+
3304
+ ### Pattern 3: Error Rollback
3305
+
3306
+ **Manual rollback on error**:
3307
+
3308
+ ```
3309
+ Try Operations:
3310
+ Postgres (INSERT orders)
3311
+ MySQL (INSERT order_items)
3312
+
3313
+ Error Trigger:
3314
+ Postgres (DELETE FROM orders WHERE id = {{$json.order_id}})
3315
+ MySQL (DELETE FROM order_items WHERE order_id = {{$json.order_id}})
3316
+ ```
3317
+
3318
+ ---
3319
+
3320
+ ## Data Transformation
3321
+
3322
+ ### Schema Mapping
3323
+
3324
+ ```javascript
3325
+ // Code node - map schemas
3326
+ const sourceData = $input.all();
3327
+
3328
+ return sourceData.map((item) => ({
3329
+ json: {
3330
+ // Source -> Target mapping
3331
+ user_id: item.json.id,
3332
+ full_name: `${item.json.first_name} ${item.json.last_name}`,
3333
+ email_address: item.json.email,
3334
+ registration_date: new Date(item.json.created_at).toISOString(),
3335
+ // Computed fields
3336
+ is_premium: item.json.plan_type === "pro",
3337
+ // Default values
3338
+ status: item.json.status || "active",
3339
+ },
3340
+ }));
3341
+ ```
3342
+
3343
+ ### Data Type Conversions
3344
+
3345
+ ```javascript
3346
+ // Code node - convert data types
3347
+ return $input.all().map((item) => ({
3348
+ json: {
3349
+ // String to number
3350
+ user_id: parseInt(item.json.user_id),
3351
+ // String to date
3352
+ created_at: new Date(item.json.created_at),
3353
+ // Number to boolean
3354
+ is_active: item.json.active === 1,
3355
+ // JSON string to object
3356
+ metadata: JSON.parse(item.json.metadata || "{}"),
3357
+ // Null handling
3358
+ email: item.json.email || null,
3359
+ },
3360
+ }));
3361
+ ```
3362
+
3363
+ ### Aggregation
3364
+
3365
+ ```javascript
3366
+ // Code node - aggregate data
3367
+ const items = $input.all();
3368
+
3369
+ const summary = items.reduce((acc, item) => {
3370
+ const date = item.json.created_at.split("T")[0];
3371
+ if (!acc[date]) {
3372
+ acc[date] = { count: 0, total: 0 };
3373
+ }
3374
+ acc[date].count++;
3375
+ acc[date].total += item.json.amount;
3376
+ return acc;
3377
+ }, {});
3378
+
3379
+ return Object.entries(summary).map(([date, data]) => ({
3380
+ json: {
3381
+ date,
3382
+ count: data.count,
3383
+ total: data.total,
3384
+ average: data.total / data.count,
3385
+ },
3386
+ }));
3387
+ ```
3388
+
3389
+ > Cross-reference: See [code-javascript.md](../code-javascript.md) for `$input.all()`, `.reduce()`, and data transformation patterns.
3390
+
3391
+ ---
3392
+
3393
+ ## Performance Optimization
3394
+
3395
+ ### 1. Use Indexes
3396
+
3397
+ Ensure database has proper indexes:
3398
+
3399
+ ```sql
3400
+ -- Add index for sync queries
3401
+ CREATE INDEX idx_users_updated_at ON users(updated_at);
3402
+
3403
+ -- Add index for lookups
3404
+ CREATE INDEX idx_orders_user_id ON orders(user_id);
3405
+ ```
3406
+
3407
+ ### 2. Limit Result Sets
3408
+
3409
+ Always use LIMIT:
3410
+
3411
+ ```sql
3412
+ -- Good
3413
+ SELECT * FROM large_table
3414
+ WHERE created_at > $1
3415
+ LIMIT 1000
3416
+
3417
+ -- Bad (unbounded)
3418
+ SELECT * FROM large_table
3419
+ WHERE created_at > $1
3420
+ ```
3421
+
3422
+ ### 3. Use Prepared Statements
3423
+
3424
+ Parameterized queries are faster:
3425
+
3426
+ ```javascript
3427
+ // Good - prepared statement
3428
+ {
3429
+ query: "SELECT * FROM users WHERE id = $1",
3430
+ parameters: ["={{$json.id}}"]
3431
+ }
3432
+
3433
+ // Bad - string concatenation
3434
+ {
3435
+ query: "SELECT * FROM users WHERE id = '={{$json.id}}'"
3436
+ }
3437
+ ```
3438
+
3439
+ ### 4. Batch Writes
3440
+
3441
+ Write multiple records at once:
3442
+
3443
+ ```javascript
3444
+ // Good - batch insert
3445
+ {
3446
+ operation: "insert",
3447
+ table: "orders",
3448
+ values: $json.items // Array of 100 items
3449
+ }
3450
+
3451
+ // Bad - individual inserts in loop
3452
+ // 100 separate INSERT statements
3453
+ ```
3454
+
3455
+ ### 5. Connection Pooling
3456
+
3457
+ Configure in credentials:
3458
+
3459
+ ```javascript
3460
+ {
3461
+ host: "db.example.com",
3462
+ database: "mydb",
3463
+ user: "user",
3464
+ password: "pass",
3465
+ // Connection pool settings
3466
+ min: 2,
3467
+ max: 10,
3468
+ idleTimeoutMillis: 30000
3469
+ }
3470
+ ```
3471
+
3472
+ ---
3473
+
3474
+ ## Database Error Handling
3475
+
3476
+ ### Pattern 1: Check Rows Affected
3477
+
3478
+ ```
3479
+ Database Operation (UPDATE users...)
3480
+ -> IF ({{$json.rowsAffected === 0}})
3481
+ └─ Alert: "No rows updated - record not found"
3482
+ ```
3483
+
3484
+ ### Pattern 2: Constraint Violations
3485
+
3486
+ ```javascript
3487
+ // Database operation with continueOnFail: true
3488
+ {
3489
+ operation: "insert",
3490
+ continueOnFail: true
3491
+ }
3492
+
3493
+ // Next node: Check for errors
3494
+ IF ({{$json.error !== undefined}})
3495
+ -> IF ({{$json.error.includes('duplicate key')}})
3496
+ └─ Log: "Record already exists - skipping"
3497
+ -> ELSE
3498
+ └─ Alert: "Database error: {{$json.error}}"
3499
+ ```
3500
+
3501
+ ### Pattern 3: Rollback on Error
3502
+
3503
+ ```
3504
+ Try Operations:
3505
+ -> Database Write 1
3506
+ -> Database Write 2
3507
+ -> Database Write 3
3508
+
3509
+ Error Trigger:
3510
+ -> Rollback Operations
3511
+ -> Alert Admin
3512
+ ```
3513
+
3514
+ ---
3515
+
3516
+ ## Security Best Practices
3517
+
3518
+ ### 1. Use Parameterized Queries (Prevent SQL Injection)
3519
+
3520
+ ```javascript
3521
+ // SAFE - parameterized
3522
+ {
3523
+ query: "SELECT * FROM users WHERE email = $1",
3524
+ parameters: ["={{$json.email}}"]
3525
+ }
3526
+
3527
+ // DANGEROUS - SQL injection risk
3528
+ {
3529
+ query: "SELECT * FROM users WHERE email = '={{$json.email}}'"
3530
+ }
3531
+ ```
3532
+
3533
+ ### 2. Least Privilege Access
3534
+
3535
+ **Create dedicated workflow user**:
3536
+
3537
+ ```sql
3538
+ -- Good - limited permissions
3539
+ CREATE USER n8n_workflow WITH PASSWORD 'secure_password';
3540
+ GRANT SELECT, INSERT, UPDATE ON orders TO n8n_workflow;
3541
+ GRANT SELECT ON users TO n8n_workflow;
3542
+
3543
+ -- Bad - too much access
3544
+ GRANT ALL PRIVILEGES TO n8n_workflow;
3545
+ ```
3546
+
3547
+ ### 3. Validate Input Data
3548
+
3549
+ ```javascript
3550
+ // Code node - validate before write
3551
+ const email = $json.email;
3552
+ const name = $json.name;
3553
+
3554
+ // Validation
3555
+ if (!email || !email.includes("@")) {
3556
+ throw new Error("Invalid email address");
3557
+ }
3558
+
3559
+ if (!name || name.length < 2) {
3560
+ throw new Error("Invalid name");
3561
+ }
3562
+
3563
+ // Sanitization
3564
+ return [
3565
+ {
3566
+ json: {
3567
+ email: email.toLowerCase().trim(),
3568
+ name: name.trim(),
3569
+ },
3570
+ },
3571
+ ];
3572
+ ```
3573
+
3574
+ ### 4. Encrypt Sensitive Data
3575
+
3576
+ ```javascript
3577
+ // Code node - encrypt before storage
3578
+ const crypto = require("crypto");
3579
+
3580
+ const algorithm = "aes-256-cbc";
3581
+ const key = Buffer.from($credentials.encryptionKey, "hex");
3582
+ const iv = crypto.randomBytes(16);
3583
+
3584
+ const cipher = crypto.createCipheriv(algorithm, key, iv);
3585
+ let encrypted = cipher.update($json.sensitive_data, "utf8", "hex");
3586
+ encrypted += cipher.final("hex");
3587
+
3588
+ return [
3589
+ {
3590
+ json: {
3591
+ encrypted_data: encrypted,
3592
+ iv: iv.toString("hex"),
3593
+ },
3594
+ },
3595
+ ];
3596
+ ```
3597
+
3598
+ ---
3599
+
3600
+ ## Database Common Gotchas
3601
+
3602
+ ### 1. Wrong: Unbounded queries
3603
+
3604
+ ```sql
3605
+ SELECT * FROM large_table -- Could return millions
3606
+ ```
3607
+
3608
+ ### Correct: Use LIMIT
3609
+
3610
+ ```sql
3611
+ SELECT * FROM large_table
3612
+ ORDER BY created_at DESC
3613
+ LIMIT 1000
3614
+ ```
3615
+
3616
+ ### 2. Wrong: String concatenation in queries
3617
+
3618
+ ```javascript
3619
+ query: "SELECT * FROM users WHERE id = '{{$json.id}}'";
3620
+ ```
3621
+
3622
+ ### Correct: Parameterized queries
3623
+
3624
+ ```javascript
3625
+ query: "SELECT * FROM users WHERE id = $1",
3626
+ parameters: ["={{$json.id}}"]
3627
+ ```
3628
+
3629
+ ### 3. Wrong: No transaction for multi-step operations
3630
+
3631
+ ```
3632
+ INSERT into orders
3633
+ INSERT into order_items // Fails -> orphaned order record
3634
+ ```
3635
+
3636
+ ### Correct: Use transaction
3637
+
3638
+ ```
3639
+ BEGIN
3640
+ INSERT into orders
3641
+ INSERT into order_items
3642
+ COMMIT (or ROLLBACK on error)
3643
+ ```
3644
+
3645
+ ### 4. Wrong: Processing all items at once
3646
+
3647
+ ```
3648
+ SELECT 1000000 records -> Process all -> OOM error
3649
+ ```
3650
+
3651
+ ### Correct: Batch processing
3652
+
3653
+ ```
3654
+ SELECT records -> Split In Batches (1000) -> Process -> Loop
3655
+ ```
3656
+
3657
+ ---
3658
+
3659
+ ## Real Database Template Examples
3660
+
3661
+ From n8n template library (456 database templates):
3662
+
3663
+ **Data Sync**:
3664
+
3665
+ ```
3666
+ Schedule -> Postgres (SELECT new records) -> Transform -> MySQL (INSERT)
3667
+ ```
3668
+
3669
+ **ETL Pipeline**:
3670
+
3671
+ ```
3672
+ Schedule -> [Multiple DB reads] -> Merge -> Transform -> Warehouse (INSERT)
3673
+ ```
3674
+
3675
+ **Backup**:
3676
+
3677
+ ```
3678
+ Schedule -> Postgres (SELECT all) -> JSON -> Google Drive (upload)
3679
+ ```
3680
+
3681
+ Use `search_templates({query: "database"})` to find more!
3682
+
3683
+ ---
3684
+
3685
+ ## Checklist for Database Workflows
3686
+
3687
+ ### Planning
3688
+
3689
+ - [ ] Identify source and target databases
3690
+ - [ ] Understand schema differences
3691
+ - [ ] Plan transformation logic
3692
+ - [ ] Consider batch size for large datasets
3693
+ - [ ] Design error handling strategy
3694
+
3695
+ ### Implementation
3696
+
3697
+ - [ ] Use parameterized queries (never concatenate)
3698
+ - [ ] Add LIMIT to all SELECT queries
3699
+ - [ ] Use appropriate operation (INSERT/UPDATE/UPSERT)
3700
+ - [ ] Configure credentials properly
3701
+ - [ ] Test with small dataset first
3702
+
3703
+ ### Performance
3704
+
3705
+ - [ ] Add database indexes for queries
3706
+ - [ ] Use batch operations
3707
+ - [ ] Implement pagination for large datasets
3708
+ - [ ] Configure connection pooling
3709
+ - [ ] Monitor query execution times
3710
+
3711
+ ### Security
3712
+
3713
+ - [ ] Use parameterized queries (SQL injection prevention)
3714
+ - [ ] Least privilege database user
3715
+ - [ ] Validate and sanitize input
3716
+ - [ ] Encrypt sensitive data
3717
+ - [ ] Never log sensitive data
3718
+
3719
+ ### Reliability
3720
+
3721
+ - [ ] Add transaction handling if needed
3722
+ - [ ] Check rows affected
3723
+ - [ ] Handle constraint violations
3724
+ - [ ] Implement retry logic
3725
+ - [ ] Add Error Trigger workflow
3726
+
3727
+ ---
3728
+
3729
+ ## Database Summary
3730
+
3731
+ **Key Points**:
3732
+
3733
+ 1. **Always use parameterized queries** (prevent SQL injection)
3734
+ 2. **Batch processing** for large datasets
3735
+ 3. **Transaction handling** for multi-step operations
3736
+ 4. **Limit result sets** to avoid memory issues
3737
+ 5. **Validate input data** before writes
3738
+
3739
+ **Pattern**: Trigger -> Query -> Transform -> Write -> Verify
3740
+
3741
+ **Related**:
3742
+
3743
+ - [expression-syntax.md](../expression-syntax.md) - Dynamic query parameters
3744
+ - [code-javascript.md](../code-javascript.md) - Schema mapping and data transformation logic
3745
+ - [node-configuration.md](../node-configuration.md) - Database node configuration
3746
+
3747
+ ---
3748
+
3749
+ ---
3750
+
3751
+ # AI Agent Workflow Pattern
3752
+
3753
+ **Use Case**: Build AI agents with tool access, memory, and reasoning capabilities.
3754
+
3755
+ ---
3756
+
3757
+ ## Pattern Structure
3758
+
3759
+ ```
3760
+ Trigger -> AI Agent (Model + Tools + Memory) -> [Process Response] -> Output
3761
+ ```
3762
+
3763
+ **Key Characteristic**: AI-powered decision making with tool use
3764
+
3765
+ ---
3766
+
3767
+ ## Core AI Connection Types
3768
+
3769
+ n8n supports **8 AI connection types** for building agent workflows:
3770
+
3771
+ 1. **ai_languageModel** - The LLM (OpenAI, Anthropic, etc.)
3772
+ 2. **ai_tool** - Functions the agent can call
3773
+ 3. **ai_memory** - Conversation context
3774
+ 4. **ai_outputParser** - Parse structured outputs
3775
+ 5. **ai_embedding** - Vector embeddings
3776
+ 6. **ai_vectorStore** - Vector database
3777
+ 7. **ai_document** - Document loaders
3778
+ 8. **ai_textSplitter** - Text chunking
3779
+
3780
+ ---
3781
+
3782
+ ## Core Components
3783
+
3784
+ ### 1. Trigger
3785
+
3786
+ **Options**:
3787
+
3788
+ - **Webhook** - Chat interfaces, API calls (most common)
3789
+ - **Manual** - Testing and development
3790
+ - **Schedule** - Periodic AI tasks
3791
+
3792
+ ### 2. AI Agent Node
3793
+
3794
+ **Purpose**: Orchestrate LLM with tools and memory
3795
+
3796
+ **Configuration**:
3797
+
3798
+ ```javascript
3799
+ {
3800
+ agent: "conversationalAgent", // or "openAIFunctionsAgent"
3801
+ promptType: "define",
3802
+ text: "You are a helpful assistant that can search docs, query databases, and send emails."
3803
+ }
3804
+ ```
3805
+
3806
+ **Connections**:
3807
+
3808
+ - **ai_languageModel input** - Connected to LLM node
3809
+ - **ai_tool inputs** - Connected to tool nodes
3810
+ - **ai_memory input** - Connected to memory node (optional)
3811
+
3812
+ > Cross-reference: See [node-configuration.md](../node-configuration.md) for AI Agent node setup and connection types.
3813
+
3814
+ ### 3. Language Model
3815
+
3816
+ **Available providers**:
3817
+
3818
+ - OpenAI (GPT-4, GPT-3.5)
3819
+ - Anthropic (Claude)
3820
+ - Google (Gemini)
3821
+ - Local models (Ollama, LM Studio)
3822
+
3823
+ **Example** (OpenAI Chat Model):
3824
+
3825
+ ```javascript
3826
+ {
3827
+ model: "gpt-4",
3828
+ temperature: 0.7,
3829
+ maxTokens: 1000
3830
+ }
3831
+ ```
3832
+
3833
+ ### 4. Tools (ANY Node Can Be a Tool!)
3834
+
3835
+ **Critical insight**: Connect ANY n8n node to agent via `ai_tool` port
3836
+
3837
+ **Common tool types**:
3838
+
3839
+ - HTTP Request - Call APIs
3840
+ - Database nodes - Query data
3841
+ - Code - Custom functions
3842
+ - Search nodes - Web/document search
3843
+ - Pre-built tool nodes (Calculator, Wikipedia, etc.)
3844
+
3845
+ ### 5. Memory (Optional but Recommended)
3846
+
3847
+ **Purpose**: Maintain conversation context
3848
+
3849
+ **Types**:
3850
+
3851
+ - **Buffer Memory** - Store recent messages
3852
+ - **Window Buffer Memory** - Store last N messages
3853
+ - **Summary Memory** - Summarize conversation
3854
+
3855
+ ### 6. Output Processing
3856
+
3857
+ **Purpose**: Format AI response for delivery
3858
+
3859
+ **Common patterns**:
3860
+
3861
+ - Return directly (chat response)
3862
+ - Store in database (conversation history)
3863
+ - Send to communication channel (Slack, email)
3864
+
3865
+ ---
3866
+
3867
+ ## Common Use Cases
3868
+
3869
+ ### 1. Conversational Chatbot
3870
+
3871
+ **Flow**: Webhook (chat message) -> AI Agent -> Webhook Response
3872
+
3873
+ **Example** (Customer support bot):
3874
+
3875
+ ```
3876
+ 1. Webhook (path: "chat", POST)
3877
+ - Receives: {user_id, message, session_id}
3878
+
3879
+ 2. Window Buffer Memory (load context by session_id)
3880
+
3881
+ 3. AI Agent
3882
+ ├─ OpenAI Chat Model (gpt-4)
3883
+ ├─ HTTP Request Tool (search knowledge base)
3884
+ ├─ Database Tool (query customer orders)
3885
+ └─ Window Buffer Memory (conversation context)
3886
+
3887
+ 4. Code (format response)
3888
+
3889
+ 5. Webhook Response (send reply)
3890
+ ```
3891
+
3892
+ **AI Agent prompt**:
3893
+
3894
+ ```
3895
+ You are a customer support assistant.
3896
+ You can:
3897
+ 1. Search the knowledge base for answers
3898
+ 2. Look up customer orders
3899
+ 3. Provide shipping information
3900
+
3901
+ Be helpful and professional.
3902
+ ```
3903
+
3904
+ ### 2. Document Q&A
3905
+
3906
+ **Flow**: Upload docs -> Embed -> Store -> Query with AI
3907
+
3908
+ **Example** (Internal documentation assistant):
3909
+
3910
+ ```
3911
+ Setup Phase (run once):
3912
+ 1. Read Files (load documentation)
3913
+ 2. Text Splitter (chunk into paragraphs)
3914
+ 3. Embeddings (OpenAI Embeddings)
3915
+ 4. Vector Store (Pinecone/Qdrant) (store vectors)
3916
+
3917
+ Query Phase (recurring):
3918
+ 1. Webhook (receive question)
3919
+ 2. AI Agent
3920
+ ├─ OpenAI Chat Model (gpt-4)
3921
+ ├─ Vector Store Tool (search similar docs)
3922
+ └─ Buffer Memory (context)
3923
+ 3. Webhook Response (answer with citations)
3924
+ ```
3925
+
3926
+ ### 3. Data Analysis Assistant
3927
+
3928
+ **Flow**: Request -> AI Agent (with data tools) -> Analysis -> Visualization
3929
+
3930
+ **Example** (SQL analyst agent):
3931
+
3932
+ ```
3933
+ 1. Webhook (data question: "What were sales last month?")
3934
+
3935
+ 2. AI Agent
3936
+ ├─ OpenAI Chat Model (gpt-4)
3937
+ ├─ Postgres Tool (execute queries)
3938
+ └─ Code Tool (data analysis)
3939
+
3940
+ 3. Code (generate visualization data)
3941
+
3942
+ 4. Webhook Response (answer + chart data)
3943
+ ```
3944
+
3945
+ **Postgres Tool Configuration**:
3946
+
3947
+ ```javascript
3948
+ {
3949
+ name: "query_database",
3950
+ description: "Execute SQL queries to analyze sales data. Use SELECT queries only.",
3951
+ // Node executes AI-generated SQL
3952
+ }
3953
+ ```
3954
+
3955
+ ### 4. Workflow Automation Agent
3956
+
3957
+ **Flow**: Command -> AI Agent -> Execute actions -> Report
3958
+
3959
+ **Example** (DevOps assistant):
3960
+
3961
+ ```
3962
+ 1. Slack (slash command: /deploy production)
3963
+
3964
+ 2. AI Agent
3965
+ ├─ OpenAI Chat Model (gpt-4)
3966
+ ├─ HTTP Request Tool (GitHub API)
3967
+ ├─ HTTP Request Tool (Deploy API)
3968
+ └─ Postgres Tool (deployment logs)
3969
+
3970
+ 3. Agent actions:
3971
+ - Check if tests passed
3972
+ - Create deployment
3973
+ - Log deployment
3974
+ - Notify team
3975
+
3976
+ 4. Slack (deployment status)
3977
+ ```
3978
+
3979
+ ### 5. Email Processing Agent
3980
+
3981
+ **Flow**: Email received -> AI Agent -> Categorize -> Route -> Respond
3982
+
3983
+ **Example** (Support ticket router):
3984
+
3985
+ ```
3986
+ 1. Email Trigger (new support email)
3987
+
3988
+ 2. AI Agent
3989
+ ├─ OpenAI Chat Model (gpt-4)
3990
+ ├─ Vector Store Tool (search similar tickets)
3991
+ └─ HTTP Request Tool (create Jira ticket)
3992
+
3993
+ 3. Agent actions:
3994
+ - Categorize urgency (low/medium/high)
3995
+ - Find similar past tickets
3996
+ - Create ticket in appropriate project
3997
+ - Draft response
3998
+
3999
+ 4. Email (send auto-response)
4000
+ 5. Slack (notify assigned team)
4001
+ ```
4002
+
4003
+ ---
4004
+
4005
+ ## Tool Configuration
4006
+
4007
+ ### Making ANY Node an AI Tool
4008
+
4009
+ **Critical concept**: Any n8n node can become an AI tool!
4010
+
4011
+ **Requirements**:
4012
+
4013
+ 1. Connect node to AI Agent via `ai_tool` port (NOT main port)
4014
+ 2. Configure tool name and description
4015
+ 3. Define input schema (optional)
4016
+
4017
+ **Example** (HTTP Request as tool):
4018
+
4019
+ ```javascript
4020
+ {
4021
+ // Tool metadata (for AI)
4022
+ name: "search_github_issues",
4023
+ description: "Search GitHub issues by keyword. Returns issue titles and URLs.",
4024
+
4025
+ // HTTP Request configuration
4026
+ method: "GET",
4027
+ url: "https://api.github.com/search/issues",
4028
+ sendQuery: true,
4029
+ queryParameters: {
4030
+ "q": "={{$json.query}} repo:{{$json.repo}}",
4031
+ "per_page": "5"
4032
+ }
4033
+ }
4034
+ ```
4035
+
4036
+ **How it works**:
4037
+
4038
+ 1. AI Agent sees tool: `search_github_issues(query, repo)`
4039
+ 2. AI decides to use it: `search_github_issues("bug", "n8n-io/n8n")`
4040
+ 3. n8n executes HTTP Request with parameters
4041
+ 4. Result returned to AI Agent
4042
+ 5. AI Agent processes result and responds
4043
+
4044
+ ### Pre-built Tool Nodes
4045
+
4046
+ **Available in @n8n/n8n-nodes-langchain**:
4047
+
4048
+ - **Calculator Tool** - Math operations
4049
+ - **Wikipedia Tool** - Wikipedia search
4050
+ - **Serper Tool** - Google search
4051
+ - **Wolfram Alpha Tool** - Computational knowledge
4052
+ - **Custom Tool** - Define with Code node
4053
+
4054
+ **Example** (Calculator Tool):
4055
+
4056
+ ```
4057
+ AI Agent
4058
+ ├─ OpenAI Chat Model
4059
+ └─ Calculator Tool (ai_tool connection)
4060
+
4061
+ User: "What's 15% of 2,847?"
4062
+ AI: *uses calculator tool* -> "426.05"
4063
+ ```
4064
+
4065
+ ### Database as Tool
4066
+
4067
+ **Pattern**: Postgres/MySQL node connected as ai_tool
4068
+
4069
+ **Configuration**:
4070
+
4071
+ ```javascript
4072
+ {
4073
+ // Tool metadata
4074
+ name: "query_customers",
4075
+ description: "Query customer database. Use SELECT queries to find customer information by email, name, or ID.",
4076
+
4077
+ // Postgres config
4078
+ operation: "executeQuery",
4079
+ query: "={{$json.sql}}", // AI provides SQL
4080
+ // Security: Use read-only database user!
4081
+ }
4082
+ ```
4083
+
4084
+ **Safety**: Create read-only DB user for AI tools!
4085
+
4086
+ ```sql
4087
+ CREATE USER ai_readonly WITH PASSWORD 'secure_password';
4088
+ GRANT SELECT ON customers, orders TO ai_readonly;
4089
+ -- NO INSERT, UPDATE, DELETE access
4090
+ ```
4091
+
4092
+ ### Code Node as Tool
4093
+
4094
+ **Pattern**: Custom Python/JavaScript function
4095
+
4096
+ **Example** (Data processor):
4097
+
4098
+ ```javascript
4099
+ // Tool metadata
4100
+ {
4101
+ name: "process_csv",
4102
+ description: "Process CSV data and return statistics. Input: csv_string"
4103
+ }
4104
+
4105
+ // Code node
4106
+ const csv = $input.first().json.csv_string;
4107
+ const lines = csv.split('\n');
4108
+ const data = lines.slice(1).map(line => line.split(','));
4109
+
4110
+ return [{
4111
+ json: {
4112
+ row_count: data.length,
4113
+ columns: lines[0].split(','),
4114
+ summary: {
4115
+ // Calculate statistics
4116
+ }
4117
+ }
4118
+ }];
4119
+ ```
4120
+
4121
+ > Cross-reference: See [code-javascript.md](../code-javascript.md) for Code node patterns used as AI tools.
4122
+
4123
+ ---
4124
+
4125
+ ## Memory Configuration
4126
+
4127
+ ### Buffer Memory
4128
+
4129
+ **Stores all messages** (until cleared)
4130
+
4131
+ ```javascript
4132
+ {
4133
+ memoryType: "bufferMemory",
4134
+ sessionKey: "={{$json.body.user_id}}" // Per-user memory
4135
+ }
4136
+ ```
4137
+
4138
+ ### Window Buffer Memory
4139
+
4140
+ **Stores last N messages** (recommended)
4141
+
4142
+ ```javascript
4143
+ {
4144
+ memoryType: "windowBufferMemory",
4145
+ sessionKey: "={{$json.body.session_id}}",
4146
+ contextWindowLength: 10 // Last 10 messages
4147
+ }
4148
+ ```
4149
+
4150
+ ### Summary Memory
4151
+
4152
+ **Summarizes old messages** (for long conversations)
4153
+
4154
+ ```javascript
4155
+ {
4156
+ memoryType: "summaryMemory",
4157
+ sessionKey: "={{$json.body.session_id}}",
4158
+ maxTokenLimit: 2000
4159
+ }
4160
+ ```
4161
+
4162
+ **How it works**:
4163
+
4164
+ 1. Conversation grows beyond limit
4165
+ 2. AI summarizes old messages
4166
+ 3. Summary stored, old messages discarded
4167
+ 4. Saves tokens while maintaining context
4168
+
4169
+ ---
4170
+
4171
+ ## Agent Types
4172
+
4173
+ ### 1. Conversational Agent
4174
+
4175
+ **Best for**: General chat, customer support
4176
+
4177
+ **Features**:
4178
+
4179
+ - Natural conversation flow
4180
+ - Memory integration
4181
+ - Tool use with reasoning
4182
+
4183
+ **When to use**: Most common use case
4184
+
4185
+ ### 2. OpenAI Functions Agent
4186
+
4187
+ **Best for**: Tool-heavy workflows, structured outputs
4188
+
4189
+ **Features**:
4190
+
4191
+ - Optimized for function calling
4192
+ - Better tool selection
4193
+ - Structured responses
4194
+
4195
+ **When to use**: Multiple tools, need reliable tool calling
4196
+
4197
+ ### 3. ReAct Agent
4198
+
4199
+ **Best for**: Step-by-step reasoning
4200
+
4201
+ **Features**:
4202
+
4203
+ - Think -> Act -> Observe loop
4204
+ - Visible reasoning process
4205
+ - Good for debugging
4206
+
4207
+ **When to use**: Complex multi-step tasks
4208
+
4209
+ ---
4210
+
4211
+ ## Prompt Engineering for Agents
4212
+
4213
+ ### System Prompt Structure
4214
+
4215
+ ```
4216
+ You are a [ROLE].
4217
+
4218
+ You can:
4219
+ - [CAPABILITY 1]
4220
+ - [CAPABILITY 2]
4221
+ - [CAPABILITY 3]
4222
+
4223
+ Guidelines:
4224
+ - [GUIDELINE 1]
4225
+ - [GUIDELINE 2]
4226
+
4227
+ Format:
4228
+ - [OUTPUT FORMAT]
4229
+ ```
4230
+
4231
+ ### Example (Customer Support)
4232
+
4233
+ ```
4234
+ You are a customer support assistant for Acme Corp.
4235
+
4236
+ You can:
4237
+ - Search the knowledge base for answers
4238
+ - Look up customer orders and shipping status
4239
+ - Create support tickets for complex issues
4240
+
4241
+ Guidelines:
4242
+ - Be friendly and professional
4243
+ - If you don't know something, say so and offer to create a ticket
4244
+ - Always verify customer identity before sharing order details
4245
+
4246
+ Format:
4247
+ - Keep responses concise
4248
+ - Use bullet points for multiple items
4249
+ - Include relevant links when available
4250
+ ```
4251
+
4252
+ ### Example (Data Analyst)
4253
+
4254
+ ```
4255
+ You are a data analyst assistant with access to the company database.
4256
+
4257
+ You can:
4258
+ - Query sales, customer, and product data
4259
+ - Perform data analysis and calculations
4260
+ - Generate summary statistics
4261
+
4262
+ Guidelines:
4263
+ - Write efficient SQL queries (always use LIMIT)
4264
+ - Explain your analysis methodology
4265
+ - Highlight important trends or anomalies
4266
+ - Use read-only queries (SELECT only)
4267
+
4268
+ Format:
4269
+ - Provide numerical answers with context
4270
+ - Include query used (for transparency)
4271
+ - Suggest follow-up analyses when relevant
4272
+ ```
4273
+
4274
+ ---
4275
+
4276
+ ## Error Handling
4277
+
4278
+ ### Pattern 1: Tool Execution Errors
4279
+
4280
+ ```
4281
+ AI Agent (continueOnFail on tool nodes)
4282
+ -> IF (tool error occurred)
4283
+ └─ Code (log error)
4284
+ └─ Webhook Response (user-friendly error)
4285
+ ```
4286
+
4287
+ ### Pattern 2: LLM API Errors
4288
+
4289
+ ```
4290
+ Main Workflow:
4291
+ AI Agent -> Process Response
4292
+
4293
+ Error Workflow:
4294
+ Error Trigger
4295
+ -> IF (rate limit error)
4296
+ └─ Wait -> Retry
4297
+ -> ELSE
4298
+ └─ Notify Admin
4299
+ ```
4300
+
4301
+ ### Pattern 3: Invalid Tool Outputs
4302
+
4303
+ ```javascript
4304
+ // Code node - validate tool output
4305
+ const result = $input.first().json;
4306
+
4307
+ if (!result || !result.data) {
4308
+ throw new Error("Tool returned invalid data");
4309
+ }
4310
+
4311
+ return [{ json: result }];
4312
+ ```
4313
+
4314
+ ---
4315
+
4316
+ ## Performance Optimization
4317
+
4318
+ ### 1. Choose Right Model
4319
+
4320
+ ```
4321
+ Fast & cheap: GPT-3.5-turbo, Claude 3 Haiku
4322
+ Balanced: GPT-4, Claude 3 Sonnet
4323
+ Powerful: GPT-4-turbo, Claude 3 Opus
4324
+ ```
4325
+
4326
+ ### 2. Limit Context Window
4327
+
4328
+ ```javascript
4329
+ {
4330
+ memoryType: "windowBufferMemory",
4331
+ contextWindowLength: 5 // Only last 5 messages
4332
+ }
4333
+ ```
4334
+
4335
+ ### 3. Optimize Tool Descriptions
4336
+
4337
+ ```javascript
4338
+ // Bad: Vague
4339
+ description: "Search for things";
4340
+
4341
+ // Good: Clear and concise
4342
+ description: "Search GitHub issues by keyword and repository. Returns top 5 matching issues with titles and URLs.";
4343
+ ```
4344
+
4345
+ ### 4. Cache Embeddings
4346
+
4347
+ For document Q&A, embed documents once:
4348
+
4349
+ ```
4350
+ Setup (run once):
4351
+ Documents -> Embed -> Store in Vector DB
4352
+
4353
+ Query (fast):
4354
+ Question -> Search Vector DB -> AI Agent
4355
+ ```
4356
+
4357
+ ### 5. Async Tools for Slow Operations
4358
+
4359
+ ```
4360
+ AI Agent -> [Queue slow tool request]
4361
+ -> Return immediate response
4362
+ -> [Background: Execute tool + notify when done]
4363
+ ```
4364
+
4365
+ ---
4366
+
4367
+ ## Security Considerations
4368
+
4369
+ ### 1. Read-Only Database Tools
4370
+
4371
+ ```sql
4372
+ -- Create limited user for AI tools
4373
+ CREATE USER ai_agent_ro WITH PASSWORD 'secure';
4374
+ GRANT SELECT ON public.* TO ai_agent_ro;
4375
+ -- NO write access!
4376
+ ```
4377
+
4378
+ ### 2. Validate Tool Inputs
4379
+
4380
+ ```javascript
4381
+ // Code node - validate before execution
4382
+ const query = $json.query;
4383
+
4384
+ if (
4385
+ query.toLowerCase().includes("drop ") ||
4386
+ query.toLowerCase().includes("delete ") ||
4387
+ query.toLowerCase().includes("update ")
4388
+ ) {
4389
+ throw new Error("Invalid query - write operations not allowed");
4390
+ }
4391
+ ```
4392
+
4393
+ ### 3. Rate Limiting
4394
+
4395
+ ```
4396
+ Webhook -> IF (check user rate limit)
4397
+ ├─ [Within limit] -> AI Agent
4398
+ └─ [Exceeded] -> Error (429 Too Many Requests)
4399
+ ```
4400
+
4401
+ ### 4. Sanitize User Input
4402
+
4403
+ ```javascript
4404
+ // Code node
4405
+ const userInput = $json.body.message.trim().substring(0, 1000); // Max 1000 chars
4406
+
4407
+ return [{ json: { sanitized: userInput } }];
4408
+ ```
4409
+
4410
+ ### 5. Monitor Tool Usage
4411
+
4412
+ ```
4413
+ AI Agent -> Log Tool Calls
4414
+ -> IF (suspicious pattern)
4415
+ └─ Alert Admin + Pause Agent
4416
+ ```
4417
+
4418
+ ---
4419
+
4420
+ ## Testing AI Agents
4421
+
4422
+ ### 1. Start with Manual Trigger
4423
+
4424
+ Replace webhook with manual trigger:
4425
+
4426
+ ```
4427
+ Manual Trigger
4428
+ -> Set (mock user input)
4429
+ -> AI Agent
4430
+ -> Code (log output)
4431
+ ```
4432
+
4433
+ ### 2. Test Tools Independently
4434
+
4435
+ Before connecting to agent:
4436
+
4437
+ ```
4438
+ Manual Trigger -> Tool Node -> Verify output format
4439
+ ```
4440
+
4441
+ ### 3. Test with Standard Questions
4442
+
4443
+ Create test suite:
4444
+
4445
+ ```
4446
+ 1. "Hello" - Test basic response
4447
+ 2. "Search for bug reports" - Test tool calling
4448
+ 3. "What did I ask before?" - Test memory
4449
+ 4. Invalid input - Test error handling
4450
+ ```
4451
+
4452
+ ### 4. Monitor Token Usage
4453
+
4454
+ ```javascript
4455
+ // Code node - log token usage
4456
+ console.log("Input tokens:", $node["AI Agent"].json.usage.input_tokens);
4457
+ console.log("Output tokens:", $node["AI Agent"].json.usage.output_tokens);
4458
+ ```
4459
+
4460
+ ### 5. Test Edge Cases
4461
+
4462
+ - Empty input
4463
+ - Very long input
4464
+ - Tool returns no results
4465
+ - Tool returns error
4466
+ - Multiple tool calls in sequence
4467
+
4468
+ ---
4469
+
4470
+ ## AI Agent Common Gotchas
4471
+
4472
+ ### 1. Wrong: Connecting tools to main port
4473
+
4474
+ ```
4475
+ HTTP Request -> AI Agent // Won't work as tool!
4476
+ ```
4477
+
4478
+ ### Correct: Use ai_tool connection type
4479
+
4480
+ ```
4481
+ HTTP Request --[ai_tool]--> AI Agent
4482
+ ```
4483
+
4484
+ ### 2. Wrong: Vague tool descriptions
4485
+
4486
+ ```
4487
+ description: "Get data" // AI won't know when to use this
4488
+ ```
4489
+
4490
+ ### Correct: Specific descriptions
4491
+
4492
+ ```
4493
+ description: "Query customer orders by email address. Returns order ID, status, and shipping info."
4494
+ ```
4495
+
4496
+ ### 3. Wrong: No memory for conversations
4497
+
4498
+ ```
4499
+ Every message is standalone - no context!
4500
+ ```
4501
+
4502
+ ### Correct: Add memory
4503
+
4504
+ ```
4505
+ Window Buffer Memory --[ai_memory]--> AI Agent
4506
+ ```
4507
+
4508
+ ### 4. Wrong: Giving AI write access
4509
+
4510
+ ```
4511
+ Postgres (full access) as tool // AI could DELETE data!
4512
+ ```
4513
+
4514
+ ### Correct: Read-only access
4515
+
4516
+ ```
4517
+ Postgres (read-only user) as tool // Safe
4518
+ ```
4519
+
4520
+ ### 5. Wrong: Unbounded tool responses
4521
+
4522
+ ```
4523
+ Tool returns 10MB of data -> exceeds token limit
4524
+ ```
4525
+
4526
+ ### Correct: Limit tool output
4527
+
4528
+ ```javascript
4529
+ {
4530
+ query: "SELECT * FROM table LIMIT 10"; // Only 10 rows
4531
+ }
4532
+ ```
4533
+
4534
+ ---
4535
+
4536
+ ## Real AI Agent Template Examples
4537
+
4538
+ From n8n template library (234 AI templates):
4539
+
4540
+ **Simple Chatbot**:
4541
+
4542
+ ```
4543
+ Webhook -> AI Agent (GPT-4 + Memory) -> Webhook Response
4544
+ ```
4545
+
4546
+ **Document Q&A**:
4547
+
4548
+ ```
4549
+ Setup: Files -> Embed -> Vector Store
4550
+ Query: Webhook -> AI Agent (GPT-4 + Vector Store Tool) -> Response
4551
+ ```
4552
+
4553
+ **SQL Analyst**:
4554
+
4555
+ ```
4556
+ Webhook -> AI Agent (GPT-4 + Postgres Tool) -> Format -> Response
4557
+ ```
4558
+
4559
+ Use `search_templates({query: "ai agent"})` to find more!
4560
+
4561
+ ---
4562
+
4563
+ ## Checklist for AI Agent Workflows
4564
+
4565
+ ### Planning
4566
+
4567
+ - [ ] Define agent purpose and capabilities
4568
+ - [ ] List required tools (APIs, databases, etc.)
4569
+ - [ ] Design conversation flow
4570
+ - [ ] Plan memory strategy (per-user, per-session)
4571
+ - [ ] Consider token costs
4572
+
4573
+ ### Implementation
4574
+
4575
+ - [ ] Choose appropriate LLM model
4576
+ - [ ] Write clear system prompt
4577
+ - [ ] Connect tools via ai_tool ports (NOT main)
4578
+ - [ ] Add tool descriptions
4579
+ - [ ] Configure memory (Window Buffer recommended)
4580
+ - [ ] Test each tool independently
4581
+
4582
+ ### Security
4583
+
4584
+ - [ ] Use read-only database access for tools
4585
+ - [ ] Validate tool inputs
4586
+ - [ ] Sanitize user inputs
4587
+ - [ ] Add rate limiting
4588
+ - [ ] Monitor for abuse
4589
+
4590
+ ### Testing
4591
+
4592
+ - [ ] Test with diverse inputs
4593
+ - [ ] Verify tool calling works
4594
+ - [ ] Check memory persistence
4595
+ - [ ] Test error scenarios
4596
+ - [ ] Monitor token usage and costs
4597
+
4598
+ ### Deployment
4599
+
4600
+ - [ ] Add error handling
4601
+ - [ ] Set up logging
4602
+ - [ ] Monitor performance
4603
+ - [ ] Set cost alerts
4604
+ - [ ] Document agent capabilities
4605
+
4606
+ ---
4607
+
4608
+ ## AI Agent Summary
4609
+
4610
+ **Key Points**:
4611
+
4612
+ 1. **8 AI connection types** - Use ai_tool for tools, ai_memory for context
4613
+ 2. **ANY node can be a tool** - Connect to ai_tool port
4614
+ 3. **Memory is essential** for conversations (Window Buffer recommended)
4615
+ 4. **Tool descriptions matter** - AI uses them to decide when to call tools
4616
+ 5. **Security first** - Read-only database access, validate inputs
4617
+
4618
+ **Pattern**: Trigger -> AI Agent (Model + Tools + Memory) -> Output
4619
+
4620
+ **Related**:
4621
+
4622
+ - [expression-syntax.md](../expression-syntax.md) - Session key and dynamic parameter expressions
4623
+ - [code-javascript.md](../code-javascript.md) - Custom tool logic and input validation
4624
+ - [node-configuration.md](../node-configuration.md) - AI Agent, LLM, and tool node configuration