{
  "name": "Get Order Status",
  "nodes": [
    {
      "parameters": {
        "path": "get_order_status",
        "httpMethod": "POST",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// n8n webhook may put POST body in $json.body or at root level\nconst data = $json.body || $json;\n\n// Get integration from _integrations object (keyed by integration type)\nconst integrations = data._integrations || {};\nconst integration = integrations.order_api;\nconst orderNumber = data.orderNumber;\n\nif (!orderNumber) {\n  return {\n    _error: true,\n    success: false,\n    message: 'Order number is required. Please provide the order number to check.'\n  };\n}\n\nif (!integration || !integration.apiUrl) {\n  return {\n    _error: true,\n    success: false,\n    message: 'No API integration configured for this client. Please set up an order_api integration in the admin panel.',\n    debug: { hasIntegrations: !!data._integrations, keys: Object.keys(integrations) }\n  };\n}\n\n// Replace placeholders in URL with actual values\nlet apiUrl = integration.apiUrl;\napiUrl = apiUrl.replace('{orderNumber}', orderNumber);\napiUrl = apiUrl.replace('{orderId}', orderNumber);\n\n// Prepare API call config\nreturn {\n  orderNumber: orderNumber,\n  _apiConfig: {\n    url: apiUrl,\n    key: integration.apiKey,\n    method: integration.method || 'GET',\n    authMethod: integration.authMethod || 'bearer'\n  }\n};"
      },
      "id": "prepare-request",
      "name": "Prepare API Request",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json._error }}",
              "value2": true
            }
          ]
        }
      },
      "id": "if-error",
      "name": "Has Error?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "method": "={{ $json._apiConfig.method }}",
        "url": "={{ $json._apiConfig.url }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json._apiConfig.key }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "timeout": 10000
        }
      },
      "id": "http-api-call",
      "name": "Call Client API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        900,
        400
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}"
      },
      "id": "respond-error",
      "name": "Return Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        900,
        200
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}"
      },
      "id": "respond-success",
      "name": "Return Result",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1100,
        400
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Prepare API Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare API Request": {
      "main": [
        [
          {
            "node": "Has Error?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Error?": {
      "main": [
        [
          {
            "node": "Return Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Call Client API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Client API": {
      "main": [
        [
          {
            "node": "Return Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "versionId": "4",
  "id": "get_order_status"
}