{
  "name": "Multi-Service API Orchestration",
  "version": "1.0.0",
  "description": "Coordinate multiple APIs with parallel calls, data transformation, and AI enrichment - demonstrates parallel execution, schema validation, and data aggregation",
  "input_schema": {
    "type": "object",
    "properties": {
      "customer_id": {
        "type": "string",
        "description": "Customer ID to fetch data for"
      },
      "include_history": {
        "type": "boolean",
        "default": true
      },
      "enrichment_level": {
        "type": "string",
        "enum": ["basic", "full"],
        "default": "basic"
      }
    },
    "required": ["customer_id"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "customer": { "type": "object" },
      "insights": { "type": "object" }
    }
  },
  "stages": [
    {
      "id": "validate-input",
      "name": "Validate Input",
      "component_type": "schema_validate",
      "config": {
        "data": "{{input}}",
        "schema": {
          "type": "object",
          "required": ["customer_id"],
          "properties": {
            "customer_id": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      },
      "depends_on": [],
      "position": { "x": 100, "y": 100 }
    },
    {
      "id": "fetch-salesforce",
      "name": "Fetch Salesforce Data",
      "component_type": "http_request",
      "config": {
        "url": "{{secrets.SALESFORCE_URL}}/services/data/v58.0/sobjects/Account/{{input.customer_id}}",
        "method": "GET",
        "headers": {
          "Authorization": "Bearer {{secrets.SALESFORCE_TOKEN}}"
        },
        "timeout": 10
      },
      "depends_on": ["validate-input"],
      "position": { "x": 100, "y": 200 }
    },
    {
      "id": "fetch-stripe",
      "name": "Fetch Stripe Data",
      "component_type": "http_request",
      "config": {
        "url": "https://api.stripe.com/v1/customers/{{input.customer_id}}",
        "method": "GET",
        "headers": {
          "Authorization": "Bearer {{secrets.STRIPE_SECRET_KEY}}"
        },
        "params": {
          "expand[]": "subscriptions"
        },
        "timeout": 10
      },
      "depends_on": ["validate-input"],
      "position": { "x": 100, "y": 300 }
    },
    {
      "id": "fetch-intercom",
      "name": "Fetch Intercom Data",
      "component_type": "http_request",
      "config": {
        "url": "https://api.intercom.io/contacts/{{input.customer_id}}",
        "method": "GET",
        "headers": {
          "Authorization": "Bearer {{secrets.INTERCOM_TOKEN}}",
          "Intercom-Version": "2.10"
        },
        "timeout": 10
      },
      "depends_on": ["validate-input"],
      "position": { "x": 100, "y": 400 }
    },
    {
      "id": "fetch-internal",
      "name": "Fetch Internal Usage",
      "component_type": "http_request",
      "config": {
        "url": "{{secrets.INTERNAL_API}}/customers/{{input.customer_id}}/usage",
        "method": "GET",
        "headers": {
          "Authorization": "Bearer {{secrets.INTERNAL_TOKEN}}"
        },
        "timeout": 5
      },
      "depends_on": ["validate-input"],
      "position": { "x": 100, "y": 500 }
    },
    {
      "id": "transform-salesforce",
      "name": "Transform Salesforce",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.fetch-salesforce.body}}",
        "jmespath_expression": "{ source: 'salesforce', company_name: Name, industry: Industry, employee_count: NumberOfEmployees, annual_revenue: AnnualRevenue, deal_stage: StageName, owner: Owner.Name }"
      },
      "depends_on": ["fetch-salesforce"],
      "position": { "x": 350, "y": 200 }
    },
    {
      "id": "transform-stripe",
      "name": "Transform Stripe",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.fetch-stripe.body}}",
        "jmespath_expression": "{ source: 'stripe', email: email, currency: currency, balance: balance, subscriptions: subscriptions.data[*].{ id: id, status: status, plan: plan.nickname, amount: plan.amount } }"
      },
      "depends_on": ["fetch-stripe"],
      "position": { "x": 350, "y": 300 }
    },
    {
      "id": "transform-intercom",
      "name": "Transform Intercom",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.fetch-intercom.body}}",
        "jmespath_expression": "{ source: 'intercom', last_seen: last_seen_at, total_conversations: statistics.total_conversations, open_tickets: statistics.open_tickets }"
      },
      "depends_on": ["fetch-intercom"],
      "position": { "x": 350, "y": 400 }
    },
    {
      "id": "transform-internal",
      "name": "Transform Internal",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.fetch-internal.body}}",
        "jmespath_expression": "{ source: 'internal', monthly_active_days: usage.active_days_30d, feature_usage: usage.features, api_calls_30d: usage.api_calls, health_score: computed.health_score }"
      },
      "depends_on": ["fetch-internal"],
      "position": { "x": 350, "y": 500 }
    },
    {
      "id": "merge-responses",
      "name": "Merge All Data",
      "component_type": "json_transform",
      "config": {
        "data": {
          "salesforce": "{{upstream.transform-salesforce.result}}",
          "stripe": "{{upstream.transform-stripe.result}}",
          "intercom": "{{upstream.transform-intercom.result}}",
          "internal": "{{upstream.transform-internal.result}}"
        },
        "jmespath_expression": "{ customer_id: '{{input.customer_id}}', profile: { company: salesforce.company_name, industry: salesforce.industry, size: salesforce.employee_count, email: stripe.email }, financial: { subscription_status: stripe.subscriptions[0].status, mrr: stripe.subscriptions[0].amount, currency: stripe.currency }, engagement: { last_seen: intercom.last_seen, support_tickets: intercom.open_tickets, health_score: internal.health_score, active_days: internal.monthly_active_days }, sales: { deal_stage: salesforce.deal_stage, owner: salesforce.owner }, sources_fetched: ['salesforce', 'stripe', 'intercom', 'internal'] }"
      },
      "depends_on": ["transform-salesforce", "transform-stripe", "transform-intercom", "transform-internal"],
      "position": { "x": 600, "y": 350 }
    },
    {
      "id": "enrich-data",
      "name": "AI Enrich Customer Data",
      "component_type": "generator",
      "config": {
        "model": "gpt-4",
        "temperature": 0.3,
        "system_prompt": "You are a customer success analyst. Given customer data, provide: 1) Risk level (low/medium/high) with reasoning, 2) Top 3 engagement opportunities, 3) Churn indicators if any. Be concise and actionable. Format as JSON.",
        "prompt": "Analyze this customer:\n\n{{upstream.merge-responses.result}}"
      },
      "depends_on": ["merge-responses"],
      "position": { "x": 600, "y": 500 }
    },
    {
      "id": "final-validation",
      "name": "Validate Output",
      "component_type": "schema_validate",
      "config": {
        "data": {
          "customer": "{{upstream.merge-responses.result}}",
          "insights": "{{upstream.enrich-data.result}}"
        },
        "schema": {
          "type": "object",
          "required": ["customer", "insights"],
          "properties": {
            "customer": {
              "type": "object",
              "required": ["customer_id", "profile", "financial", "engagement"]
            },
            "insights": {
              "type": "object"
            }
          }
        }
      },
      "depends_on": ["merge-responses", "enrich-data"],
      "position": { "x": 850, "y": 450 }
    },
    {
      "id": "log-completion",
      "name": "Log Completion",
      "component_type": "logger",
      "config": {
        "message": "Customer 360 built for {{input.customer_id}}",
        "level": "info",
        "data": {
          "customer_id": "{{input.customer_id}}",
          "health_score": "{{upstream.merge-responses.result.engagement.health_score}}",
          "sources": "{{upstream.merge-responses.result.sources_fetched}}"
        }
      },
      "depends_on": ["final-validation"],
      "position": { "x": 850, "y": 550 }
    }
  ],
  "output_stage_id": "final-validation"
}
