{
  "openapi": "3.1.0",
  "info": {
    "title": "Rufio Stats score API",
    "version": "1.0.0",
    "description": "Unofficial, statkeeper-entered volleyball scores. Server to server only: keys must stay on your backend and responses carry no CORS headers. Terms and full guidance: https://rufiostats.com/developers/"
  },
  "servers": [{ "url": "https://rufiostats.com/api/developer/v1" }],
  "security": [{ "apiKey": [] }],
  "paths": {
    "/live": {
      "get": {
        "summary": "Games updated in the last 6 hours",
        "description": "Cursor paged, 500 items a page by default and at most. Follow nextCursor to the end, then start again from the first page. A walk every 15 seconds over 3,000 games is six pages, 24 calls a minute. Items never include tournament.venue.",
        "parameters": [{ "$ref": "#/components/parameters/cursor" }, { "$ref": "#/components/parameters/limit500" }],
        "responses": { "200": { "$ref": "#/components/responses/GamePage" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/teams": {
      "get": {
        "summary": "Directory of teams that share scores",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string", "maxLength": 100 } },
          { "name": "state", "in": "query", "schema": { "type": "string", "maxLength": 64 } },
          { "$ref": "#/components/parameters/cursor" },
          { "$ref": "#/components/parameters/limit" }
        ],
        "responses": { "200": { "$ref": "#/components/responses/TeamPage" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/teams/{teamId}/games": {
      "get": {
        "summary": "Schedule and scores for one team",
        "parameters": [
          { "$ref": "#/components/parameters/teamId" },
          { "name": "from", "in": "query", "required": true, "schema": { "type": "string", "format": "date" } },
          { "name": "to", "in": "query", "required": true, "description": "Inclusive range of at most 31 calendar days, including from and to.", "schema": { "type": "string", "format": "date" } },
          { "$ref": "#/components/parameters/cursor" },
          { "$ref": "#/components/parameters/limit" }
        ],
        "responses": { "200": { "$ref": "#/components/responses/GamePage" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/games/{gameId}": {
      "get": {
        "summary": "One game",
        "parameters": [{ "$ref": "#/components/parameters/gameId" }],
        "responses": { "200": { "$ref": "#/components/responses/GameOne" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/removed": {
      "get": {
        "summary": "Team ids you have been served that are no longer shared",
        "description": "Team ids only, ascending. Continue until nextCursor is null; a page can be empty partway through. Best effort: it can miss some teams.",
        "parameters": [{ "$ref": "#/components/parameters/cursor" }, { "$ref": "#/components/parameters/limit" }],
        "responses": { "200": { "$ref": "#/components/responses/RemovedPage" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/sandbox/live": {
      "get": {
        "summary": "Test mode: games in play",
        "description": "Fictional fixtures on a repeating 15-minute cycle. Reads no real data. Lists only live and stale games.",
        "parameters": [{ "$ref": "#/components/parameters/cursor" }, { "$ref": "#/components/parameters/limit500" }],
        "responses": { "200": { "$ref": "#/components/responses/GamePage" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/sandbox/teams": {
      "get": {
        "summary": "Test mode: team directory",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string", "maxLength": 100 } },
          { "name": "state", "in": "query", "schema": { "type": "string", "maxLength": 64 } },
          { "$ref": "#/components/parameters/cursor" }, { "$ref": "#/components/parameters/limit" }
        ],
        "responses": { "200": { "$ref": "#/components/responses/TeamPage" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/sandbox/teams/{teamId}/games": {
      "get": {
        "summary": "Test mode: one team's games",
        "parameters": [
          { "$ref": "#/components/parameters/teamId" },
          { "name": "from", "in": "query", "required": true, "schema": { "type": "string", "format": "date" } },
          { "name": "to", "in": "query", "required": true, "schema": { "type": "string", "format": "date" } },
          { "$ref": "#/components/parameters/cursor" },
          { "$ref": "#/components/parameters/limit" }
        ],
        "responses": { "200": { "$ref": "#/components/responses/GamePage" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/sandbox/games/{gameId}": {
      "get": {
        "summary": "Test mode: one game",
        "parameters": [{ "$ref": "#/components/parameters/gameId" }],
        "responses": { "200": { "$ref": "#/components/responses/GameOne" }, "304": { "$ref": "#/components/responses/NotModified" }, "default": { "$ref": "#/components/responses/Error" } }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": { "type": "http", "scheme": "bearer", "description": "Keys look like rsp_<prefix>_<secret>. Get one at https://rufiostats.com/developers/." }
    },
    "parameters": {
      "cursor": { "name": "cursor", "in": "query", "description": "Opaque. Pass back exactly as received, with the same other parameters.", "schema": { "type": "string" } },
      "limit": { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 } },
      "limit500": { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 500, "default": 500 } },
      "teamId": { "name": "teamId", "in": "path", "required": true, "schema": { "type": "string", "maxLength": 128 } },
      "gameId": { "name": "gameId", "in": "path", "required": true, "schema": { "type": "string", "maxLength": 128 } }
    },
    "responses": {
      "NotModified": { "description": "The ETag sent in If-None-Match still matches." },
      "Error": { "description": "An error.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "GameOne": { "description": "One game.", "content": { "application/json": { "schema": { "type": "object", "required": ["success", "data"], "properties": { "success": { "const": true }, "data": { "$ref": "#/components/schemas/Game" } } } } } },
      "GamePage": { "description": "A page of games.", "content": { "application/json": { "schema": { "type": "object", "required": ["success", "data"], "properties": { "success": { "const": true }, "data": { "type": "object", "required": ["items", "nextCursor"], "properties": { "items": { "type": "array", "items": { "$ref": "#/components/schemas/Game" } }, "nextCursor": { "type": ["string", "null"] } } } } } } } },
      "TeamPage": { "description": "A page of teams.", "content": { "application/json": { "schema": { "type": "object", "required": ["success", "data"], "properties": { "success": { "const": true }, "data": { "type": "object", "required": ["items", "nextCursor"], "properties": { "items": { "type": "array", "items": { "$ref": "#/components/schemas/Team" } }, "nextCursor": { "type": ["string", "null"] } } } } } } } },
      "RemovedPage": { "description": "A page of removed team ids.", "content": { "application/json": { "schema": { "type": "object", "required": ["success", "data"], "properties": { "success": { "const": true }, "data": { "type": "object", "required": ["items", "nextCursor"], "properties": { "items": { "type": "array", "items": { "type": "string" } }, "nextCursor": { "type": ["string", "null"] } } } } } } } }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["success", "error"],
        "properties": {
          "success": { "const": false },
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": { "enum": ["VALIDATION_ERROR", "INVALID_CURSOR", "CURSOR_EXPIRED", "UNAUTHORIZED", "FORBIDDEN", "NOT_FOUND", "METHOD_NOT_ALLOWED", "AUTH_RATE_LIMITED", "RATE_LIMITED", "GLOBAL_CAPACITY", "DAILY_QUOTA_EXCEEDED", "SERVICE_UNAVAILABLE"] },
              "message": { "type": "string" }
            }
          }
        }
      },
      "Team": {
        "type": "object",
        "required": ["id", "name", "club", "state", "city", "region", "league", "level", "url"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "club": { "type": ["string", "null"], "description": "The club or program the team belongs to in Rufio Stats, when set. Unverified." },
          "state": { "type": ["string", "null"] },
          "city": { "type": ["string", "null"] },
          "region": { "type": ["string", "null"] },
          "league": { "type": ["string", "null"] },
          "level": { "type": ["string", "null"] },
          "url": { "type": "string", "format": "uri" }
        }
      },
      "Set": {
        "type": "object",
        "required": ["number", "team", "opponent", "completed"],
        "properties": { "number": { "type": "integer" }, "team": { "type": "integer" }, "opponent": { "type": "integer" }, "completed": { "type": "boolean" } }
      },
      "Tournament": {
        "type": ["object", "null"],
        "properties": {
          "name": { "type": ["string", "null"] },
          "startDate": { "type": ["string", "null"] },
          "endDate": { "type": ["string", "null"] },
          "venue": { "type": ["string", "null"], "description": "Absent on /live items." },
          "links": { "type": "array", "items": { "type": "string", "format": "uri" } },
          "externalRefs": {
            "type": "array",
            "items": { "type": "object", "required": ["system", "eventKey"], "properties": { "system": { "const": "aes" }, "eventKey": { "type": "string", "description": "Opaque, statkeeper-supplied and unverified." } } }
          }
        }
      },
      "Game": {
        "type": "object",
        "required": ["gameId", "teamId", "teamName", "club", "opponent", "date", "time", "startedAt", "startedAtSource", "status", "bestOf", "setsWon", "sets", "tournament", "round", "lastUpdatedAt", "official", "source", "url"],
        "properties": {
          "gameId": { "type": "string" },
          "teamId": { "type": "string" },
          "teamName": { "type": "string" },
          "club": { "type": ["string", "null"] },
          "opponent": { "type": "string" },
          "date": { "type": "string", "description": "Statkeeper-entered local date. Never converted to UTC." },
          "time": { "type": "string", "description": "Statkeeper-entered local time, blank when unset." },
          "startedAt": { "type": ["string", "null"], "format": "date-time" },
          "startedAtSource": { "enum": ["statkeeper_override", "recording_clock", "unknown"] },
          "status": { "enum": ["scheduled", "live", "stale", "incomplete", "final"] },
          "bestOf": { "type": "integer" },
          "setsWon": { "type": "object", "required": ["team", "opponent"], "properties": { "team": { "type": "integer" }, "opponent": { "type": "integer" } } },
          "sets": { "type": "array", "items": { "$ref": "#/components/schemas/Set" } },
          "tournament": { "$ref": "#/components/schemas/Tournament" },
          "round": { "type": ["string", "null"] },
          "lastUpdatedAt": { "type": "string", "format": "date-time" },
          "official": { "const": false },
          "source": { "const": "statkeeper" },
          "url": { "type": "string", "format": "uri" }
        }
      }
    }
  }
}
