{
  "name": "B2B Marketing Orchestrator - Main",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "marketing-api",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"body\"][\"action\"]}}",
              "operation": "equals",
              "value2": "onboard_user"
            }
          ]
        }
      },
      "id": "switch-router",
      "name": "Route Request",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:5678/webhook/user-onboarding",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "user_data",
              "value": "={{$json[\"body\"]}}"
            }
          ]
        },
        "options": {
          "timeout": 30000
        }
      },
      "id": "call-onboarding",
      "name": "Call User Onboarding",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        650,
        200
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:5678/webhook/content-generation",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "content_request",
              "value": "={{$json[\"body\"]}}"
            }
          ]
        },
        "options": {
          "timeout": 60000
        }
      },
      "id": "call-content-gen",
      "name": "Call Content Generation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:5678/webhook/analytics",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "analytics_request",
              "value": "={{$json[\"body\"]}}"
            }
          ]
        },
        "options": {
          "timeout": 20000
        }
      },
      "id": "call-analytics",
      "name": "Call Analytics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        650,
        400
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO user_activity (user_id, action, timestamp, data) VALUES ($1, $2, NOW(), $3)",
        "additionalFields": {
          "queryParams": "={{$json[\"body\"][\"user_id\"]}},={{$json[\"body\"][\"action\"]}},={{JSON.stringify($json[\"body\"])}}"
        }
      },
      "id": "log-activity",
      "name": "Log Activity to PostgreSQL",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2,
      "position": [
        850,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{JSON.stringify({\"status\": \"success\", \"data\": $json})}}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "respond-success",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{JSON.stringify({\"status\": \"error\", \"message\": $json[\"error\"][\"message\"]})}}",
        "options": {
          "responseCode": 500
        }
      },
      "id": "respond-error",
      "name": "Error Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1050,
        500
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Route Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Request": {
      "main": [
        [
          {
            "node": "Call User Onboarding",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Call Content Generation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Call Analytics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call User Onboarding": {
      "main": [
        [
          {
            "node": "Log Activity to PostgreSQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Content Generation": {
      "main": [
        [
          {
            "node": "Log Activity to PostgreSQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Analytics": {
      "main": [
        [
          {
            "node": "Log Activity to PostgreSQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Activity to PostgreSQL": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1",
  "id": "1",
  "tags": []
}