{
  "openapi": "3.0.3",
  "info": {
    "title": "SmartyLabels API",
    "description": "REST API for managing QR code URLs with SmartyLabels. Create trackable QR codes that can be updated without reprinting.",
    "version": "1.0.0",
    "contact": {
      "name": "SmartyLabels Support",
      "url": "https://smartylabels.com",
      "email": "hello@smartylabels.com"
    }
  },
  "servers": [
    {
      "url": "https://smartylabels.com/api/v1",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/urls": {
      "get": {
        "summary": "List all URLs",
        "description": "Get a paginated list of all URLs for the authenticated user",
        "tags": ["URLs"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of URLs to return",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "description": "Number of URLs to skip",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "string",
              "enum": ["active", "inactive", "pending"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of URLs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UrlListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a new URL",
        "description": "Create a new trackable URL with optional destination",
        "tags": ["URLs"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUrlRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "URL created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UrlResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/urls/{id}": {
      "get": {
        "summary": "Get URL details",
        "description": "Get detailed information about a specific URL",
        "tags": ["URLs"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "URL ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "URL details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UrlResponse"
                }
              }
            }
          },
          "404": {
            "description": "URL not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Update a URL",
        "description": "Update the destination, title, or status of a URL",
        "tags": ["URLs"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "URL ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateUrlRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "URL updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessResponse"
                }
              }
            }
          },
          "404": {
            "description": "URL not found"
          }
        }
      },
      "delete": {
        "summary": "Delete a URL",
        "description": "Permanently delete a URL",
        "tags": ["URLs"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "URL ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "URL deleted successfully"
          },
          "404": {
            "description": "URL not found"
          }
        }
      }
    },
    "/urls/{id}/stats": {
      "get": {
        "summary": "Get URL statistics",
        "description": "Get click statistics and analytics for a URL",
        "tags": ["URLs"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "URL ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "URL statistics",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatsResponse"
                }
              }
            }
          },
          "404": {
            "description": "URL not found"
          }
        }
      }
    },
    "/batches": {
      "get": {
        "summary": "List all batches",
        "description": "Get a list of all URL batches",
        "tags": ["Batches"],
        "responses": {
          "200": {
            "description": "List of batches",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchListResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a batch of URLs",
        "description": "Create multiple URLs at once for bulk QR code generation",
        "tags": ["Batches"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateBatchRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Batch created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchResponse"
                }
              }
            }
          }
        }
      }
    },
    "/batches/{batchId}": {
      "get": {
        "summary": "Get batch details",
        "description": "Get batch information including all URLs in the batch",
        "tags": ["Batches"],
        "parameters": [
          {
            "name": "batchId",
            "in": "path",
            "required": true,
            "description": "Batch ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Batch details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchResponse"
                }
              }
            }
          },
          "404": {
            "description": "Batch not found"
          }
        }
      }
    },
    "/account": {
      "get": {
        "summary": "Get account info",
        "description": "Get information about the authenticated user's account",
        "tags": ["Account"],
        "responses": {
          "200": {
            "description": "Account information",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountResponse"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/subscribe": {
      "post": {
        "summary": "Subscribe to webhook events",
        "description": "Subscribe to receive webhook notifications for events like QR code scans",
        "tags": ["Webhooks"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookSubscribeRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook subscription created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookResponse"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "summary": "List webhook subscriptions",
        "description": "Get all active webhook subscriptions",
        "tags": ["Webhooks"],
        "responses": {
          "200": {
            "description": "List of webhooks",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/{id}": {
      "delete": {
        "summary": "Unsubscribe from webhook",
        "description": "Remove a webhook subscription",
        "tags": ["Webhooks"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Webhook ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook unsubscribed"
          }
        }
      }
    },
    "/webhooks/{id}/test": {
      "post": {
        "summary": "Test webhook",
        "description": "Send a test payload to verify webhook is working",
        "tags": ["Webhooks"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Webhook ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Test sent successfully"
          }
        }
      }
    },
    "/webhooks/sample/{event}": {
      "get": {
        "summary": "Get sample webhook data",
        "description": "Get sample data for a webhook event type (useful for Zapier)",
        "tags": ["Webhooks"],
        "parameters": [
          {
            "name": "event",
            "in": "path",
            "required": true,
            "description": "Event type",
            "schema": {
              "type": "string",
              "enum": ["url.scanned", "url.created", "url.updated", "url.deleted"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sample event data"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key authentication. Get your key from the dashboard."
      }
    },
    "schemas": {
      "CreateUrlRequest": {
        "type": "object",
        "required": ["title"],
        "properties": {
          "title": {
            "type": "string",
            "description": "Title for the URL",
            "example": "Product Landing Page"
          },
          "destination": {
            "type": "string",
            "format": "uri",
            "description": "Destination URL to redirect to",
            "example": "https://example.com/product"
          },
          "description": {
            "type": "string",
            "description": "Optional description"
          }
        }
      },
      "UpdateUrlRequest": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "destination": {
            "type": "string",
            "format": "uri"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["active", "inactive"]
          }
        }
      },
      "CreateBatchRequest": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": {
            "type": "string",
            "description": "Name for the batch",
            "example": "Marketing Campaign Q1"
          },
          "count": {
            "type": "integer",
            "description": "Number of URLs to create",
            "default": 10,
            "minimum": 1,
            "maximum": 1000
          },
          "titlePrefix": {
            "type": "string",
            "description": "Prefix for URL titles",
            "default": "URL-"
          },
          "description": {
            "type": "string"
          }
        }
      },
      "UrlResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "url": {
            "$ref": "#/components/schemas/Url"
          }
        }
      },
      "UrlListResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "urls": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Url"
            }
          },
          "pagination": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer"
              },
              "limit": {
                "type": "integer"
              },
              "offset": {
                "type": "integer"
              },
              "hasMore": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "Url": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "urlCode": {
            "type": "string",
            "example": "Xy7kM"
          },
          "title": {
            "type": "string"
          },
          "shortUrl": {
            "type": "string",
            "format": "uri",
            "example": "https://smartylabels.com/Xy7kM"
          },
          "qrCodeUrl": {
            "type": "string",
            "format": "uri"
          },
          "destination": {
            "type": "string",
            "format": "uri"
          },
          "status": {
            "type": "string",
            "enum": ["active", "inactive", "pending"]
          },
          "clicks": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "StatsResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "stats": {
            "type": "object",
            "properties": {
              "totalClicks": {
                "type": "integer"
              },
              "last24Hours": {
                "type": "integer"
              },
              "last7Days": {
                "type": "integer"
              },
              "last30Days": {
                "type": "integer"
              },
              "deviceBreakdown": {
                "type": "object",
                "properties": {
                  "mobile": {
                    "type": "integer"
                  },
                  "desktop": {
                    "type": "integer"
                  },
                  "other": {
                    "type": "integer"
                  }
                }
              },
              "topReferrers": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "host": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "BatchResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "batch": {
            "$ref": "#/components/schemas/Batch"
          }
        }
      },
      "BatchListResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "batches": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Batch"
            }
          }
        }
      },
      "Batch": {
        "type": "object",
        "properties": {
          "batchId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "urlCount": {
            "type": "integer"
          },
          "urls": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Url"
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AccountResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "account": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "email": {
                "type": "string"
              },
              "urlCount": {
                "type": "integer"
              },
              "batchCount": {
                "type": "integer"
              },
              "memberSince": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "SuccessResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "string"
          }
        }
      },
      "WebhookSubscribeRequest": {
        "type": "object",
        "required": ["url", "event"],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "URL to send webhook notifications to",
            "example": "https://hooks.zapier.com/hooks/catch/123456/abcdef/"
          },
          "event": {
            "type": "string",
            "enum": ["url.scanned", "url.created", "url.updated", "url.deleted"],
            "description": "Event type to subscribe to"
          }
        }
      },
      "WebhookResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "webhook": {
            "$ref": "#/components/schemas/Webhook"
          }
        }
      },
      "WebhookListResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "webhooks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Webhook"
            }
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "event": {
            "type": "string",
            "enum": ["url.scanned", "url.created", "url.updated", "url.deleted"]
          },
          "active": {
            "type": "boolean"
          },
          "triggerCount": {
            "type": "integer"
          },
          "lastTriggered": {
            "type": "string",
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
