{
  "openapi": "3.1.0",
  "info": {
    "title": "Endorso Affiliate Link API",
    "version": "1.0.0",
    "description": "Convert any product URL into a tracked affiliate link. Supports Amazon, AliExpress, and 120+ affiliate networks. AI agents can register as partners and monetize product recommendations.",
    "contact": {
      "email": "support@endorso.com"
    }
  },
  "servers": [
    {
      "url": "https://api.endorso.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/v1/partners/register": {
      "post": {
        "operationId": "registerPartner",
        "summary": "Register as a partner to get an API key",
        "description": "Creates a new partner account for an AI agent, bot, or app. No auth required — returns an API key instantly. Rate limited to 3 registrations per IP per hour.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "description": "Partner name (e.g., \"My Shopping Bot\")"
                  },
                  "website": {
                    "type": "string",
                    "description": "Partner website URL"
                  },
                  "description": {
                    "type": "string",
                    "description": "What the partner does"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Partner created with active API key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "partner": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "api_key": {
                          "type": "string",
                          "description": "Use this as Bearer token for authenticated endpoints"
                        },
                        "tag": {
                          "type": "string",
                          "description": "Partner tag for sub-affiliate tracking"
                        },
                        "revenue_share": {
                          "type": "number",
                          "description": "Partner revenue share (0.70 = 70%)"
                        }
                      }
                    },
                    "usage": {
                      "type": "object",
                      "description": "Quick-start examples for using the API",
                      "properties": {
                        "match_links": {
                          "type": "string"
                        },
                        "search": {
                          "type": "string"
                        },
                        "networks": {
                          "type": "string"
                        },
                        "docs": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/v1/links/match": {
      "post": {
        "operationId": "matchLink",
        "summary": "Convert a product URL to a tracked affiliate link",
        "description": "Takes any product URL and returns a tracked affiliate link with commission info. Supports Amazon, AliExpress, and programs from 120+ networks.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Product URL (e.g., https://amazon.com/dp/B0DLRL1G87)"
                  },
                  "geo": {
                    "type": "string",
                    "description": "User country code (e.g., US, GB)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Link matched",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "matched": {
                      "type": "boolean"
                    },
                    "program": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "network": {
                          "type": "string"
                        },
                        "commission_rate": {
                          "type": "string"
                        }
                      }
                    },
                    "link": {
                      "type": "object",
                      "properties": {
                        "tracking_id": {
                          "type": "string"
                        },
                        "affiliate_url": {
                          "type": "string"
                        },
                        "endorso_url": {
                          "type": "string",
                          "description": "Share this URL — it tracks clicks and redirects to the affiliate link"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/products/search": {
      "get": {
        "operationId": "searchProducts",
        "summary": "Search products across all feeds",
        "description": "Full-text search across product feeds from multiple affiliate networks.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Search query"
          },
          {
            "name": "brand",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "min_price",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "max_price",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Products found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "products": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "total_count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/networks": {
      "get": {
        "operationId": "listNetworks",
        "summary": "List supported affiliate networks",
        "description": "Returns all 120+ affiliate networks with their status and API availability.",
        "responses": {
          "200": {
            "description": "Networks list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "networks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "slug": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string"
                          },
                          "api_available": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from /api/v1/partners/register (format: na_xxx)"
      }
    }
  }
}