{
  "openapi": "3.0.3",
  "info": {
    "title": "Ordavia Zapier API",
    "description": "Comprehensive API documentation for integrating Ordavia with Zapier. This API provides real-time webhooks and polling endpoints for order management and inventory tracking.",
    "version": "1.0.1",
    "contact": {
      "name": "Ordavia Support",
      "email": "contact@ordavia.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://www.ordavia.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://www.ordavia.com",
      "description": "Production server"
    },
    {
      "url": "https://kizzy-unsolidified-mayola.ngrok-free.dev",
      "description": "Development server (ngrok)"
    }
  ],
  "tags": [
    {
      "name": "Authentication",
      "description": "API key authentication endpoints"
    },
    {
      "name": "Triggers - Orders",
      "description": "Order-related trigger endpoints"
    },
    {
      "name": "Triggers - Products",
      "description": "Product and inventory trigger endpoints"
    },
    {
      "name": "Webhooks",
      "description": "Webhook subscription management"
    }
  ],
  "paths": {
    "/api/zapier/auth/test": {
      "get": {
        "tags": ["Authentication"],
        "summary": "Test API Key Authentication",
        "description": "Validates the provided API key and returns user information. Used by Zapier to verify credentials.",
        "operationId": "testAuth",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Authentication successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "userId": {
                      "type": "string",
                      "format": "uuid",
                      "example": "550e8400-e29b-41d4-a716-446655440000"
                    },
                    "userName": {
                      "type": "string",
                      "example": "John Doe"
                    },
                    "userEmail": {
                      "type": "string",
                      "format": "email",
                      "example": "john@ordavia.com"
                    },
                    "message": {
                      "type": "string",
                      "example": "Authentication successful"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/zapier/triggers/orders/new": {
      "get": {
        "tags": ["Triggers - Orders"],
        "summary": "Get New Orders",
        "description": "Returns a list of recently created orders. Used for polling new order events.",
        "operationId": "getNewOrders",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of orders to return",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of new orders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Order"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/zapier/triggers/orders/status-changed": {
      "get": {
        "tags": ["Triggers - Orders"],
        "summary": "Get Orders with Status Changes",
        "description": "Returns orders that have had their status updated recently.",
        "operationId": "getStatusChangedOrders",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of orders to return",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of orders with status changes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/OrderStatusChanged"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/zapier/triggers/products/low-stock": {
      "get": {
        "tags": ["Triggers - Products"],
        "summary": "Get Low Stock Products",
        "description": "Returns products that have stock levels at or below their minimum stock threshold.",
        "operationId": "getLowStockProducts",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of products to return",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of low stock products",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/LowStockProduct"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/zapier/webhooks/subscribe": {
      "post": {
        "tags": ["Webhooks"],
        "summary": "Subscribe to Webhook Events",
        "description": "Register a webhook URL to receive real-time notifications for specific events.",
        "operationId": "subscribeWebhook",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["hookUrl", "event"],
                "properties": {
                  "hookUrl": {
                    "type": "string",
                    "format": "uri",
                    "description": "The URL where webhook payloads will be sent",
                    "example": "https://hooks.zapier.com/hooks/catch/123456/abcdef/"
                  },
                  "event": {
                    "type": "string",
                    "enum": ["order.created", "order.status_changed", "product.low_stock"],
                    "description": "The event type to subscribe to"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook subscription created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "webhook": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "event": {
                          "type": "string"
                        },
                        "url": {
                          "type": "string",
                          "format": "uri"
                        },
                        "status": {
                          "type": "string",
                          "enum": ["active"]
                        },
                        "createdAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequestError"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          }
        }
      }
    },
    "/api/zapier/webhooks/unsubscribe": {
      "delete": {
        "tags": ["Webhooks"],
        "summary": "Unsubscribe from Webhook Events",
        "description": "Remove a webhook subscription by its ID.",
        "operationId": "unsubscribeWebhook",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["webhookId"],
                "properties": {
                  "webhookId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "The ID of the webhook subscription to remove"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook subscription removed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "Webhook unsubscribed successfully"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "API key authentication. Get your API key from Settings → Integrations → Zapier in your Ordavia dashboard."
      }
    },
    "schemas": {
      "Order": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique order identifier"
          },
          "orderNumber": {
            "type": "string",
            "description": "Human-readable order number",
            "example": "ORD-00123"
          },
          "totalAmount": {
            "type": "string",
            "description": "Formatted total amount with currency",
            "example": "$115.00"
          },
          "status": {
            "type": "string",
            "enum": ["pending", "confirmed", "shipped", "delivered", "cancelled"],
            "description": "Current order status"
          },
          "paymentMethod": {
            "type": "string",
            "description": "Payment method used"
          },
          "notes": {
            "type": "string",
            "nullable": true,
            "description": "Additional order notes"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp of order creation"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp of last update"
          },
          "customer": {
            "$ref": "#/components/schemas/Customer"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderItem"
            }
          }
        }
      },
      "OrderStatusChanged": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Order"
          },
          {
            "type": "object",
            "properties": {
              "previousStatus": {
                "type": "string",
                "description": "Previous order status before the change"
              }
            }
          }
        ]
      },
      "Customer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "example": "John Doe"
          },
          "email": {
            "type": "string",
            "format": "email",
            "example": "john@example.com"
          },
          "phone": {
            "type": "string",
            "nullable": true,
            "example": "+1234567890"
          }
        }
      },
      "OrderItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "productId": {
            "type": "string",
            "format": "uuid"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1
          },
          "unitPrice": {
            "type": "string",
            "description": "Formatted unit price",
            "example": "$50.00"
          },
          "totalPrice": {
            "type": "string",
            "description": "Formatted total price",
            "example": "$100.00"
          }
        }
      },
      "LowStockProduct": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "example": "Premium Wireless Mouse"
          },
          "sku": {
            "type": "string",
            "example": "MOUSE-001"
          },
          "currentStock": {
            "type": "integer",
            "description": "Current inventory level"
          },
          "minimumStock": {
            "type": "integer",
            "description": "Minimum stock threshold"
          },
          "stockPercentage": {
            "type": "integer",
            "description": "Current stock as percentage of minimum",
            "example": 50
          },
          "needsReorder": {
            "type": "boolean",
            "description": "Whether product needs to be reordered"
          },
          "isCritical": {
            "type": "boolean",
            "description": "Whether product is completely out of stock"
          },
          "price": {
            "type": "string",
            "description": "Formatted product price",
            "example": "$29.99"
          },
          "categoryId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message"
          },
          "code": {
            "type": "string",
            "description": "Error code"
          }
        }
      }
    },
    "responses": {
      "UnauthorizedError": {
        "description": "Invalid or missing API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Invalid API key"
            }
          }
        }
      },
      "BadRequestError": {
        "description": "Invalid request parameters",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Invalid request body"
            }
          }
        }
      },
      "NotFoundError": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Webhook not found"
            }
          }
        }
      },
      "ServerError": {
        "description": "Internal server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Internal server error"
            }
          }
        }
      }
    }
  }
}
