{
  "openapi": "3.1.0",
  "info": {
    "title": "bikeapi.eu",
    "version": "1",
    "summary": "One frame-number check across Europe's bicycle registries.",
    "description": "bikeapi.eu is a neutral hub between bicycle registries in Europe. A partner sends a frame number; the hub asks every connected registry at once and answers with what was found and a link to the registry that holds the record.\n\n**No owner data** is requested, stored or returned. Answers carry the registry, country, status, brand, model, colour and a link — enough to tell whether it is the bike in front of you, and where to turn next.\n\n**Access** is for partners only: registries, police and public bodies (free), insurers, leasing companies and second-hand marketplaces. Sign up at https://bikeapi.eu/join: a business gets a trial of 20 checks as soon as its email address is confirmed; registries, police and public bodies are confirmed by us first. API keys are issued in the partner account; send one in the `Authorization` header as `Bearer <key>`.\n\n**Match levels.** Numbers are compared ignoring case, spaces and punctuation, and treating look-alike characters as equal (O/0, I/L/1, S/5, Z/2, B/8). `exact` — same characters; `similar` — same once look-alikes are equated; `partial` — the number asked for is part of a longer recorded number (e.g. worn-off ending); `close` — one or two typos away. Partial and close matches are shown only for bikes reported stolen.\n\n**Brand, model and colour** are optional. They never hide a match — stolen bikes are repainted, brands are misspelt — but rank matches that fit the description first and flag agreement in `brand_match`, `model_match`, `color_match`.\n\n**Restricted sources.** Some registries share details only with the police or other registries. If such a source holds the number, other partners get a `restricted_hits` entry: a match exists, contact that registry.\n\n**Certificates.** Add `certificate=true` to a check and its result is kept as a certificate: a page showing what was checked, when, against which sources and with what result. Anyone holding the link can verify it — attach it to a claim file or a purchase record. Certificates are kept for five years.\n\n**Watching.** Add `watch_months` to a check and the number is checked again every day; the notification addresses set in your account get an e-mail whenever a record of it appears, changes status or disappears in any registry.",
    "contact": { "name": "bikeapi.eu", "url": "https://bikeapi.eu" }
  },
  "servers": [{ "url": "https://api.bikeapi.eu" }],
  "security": [{ "apiKey": [] }],
  "tags": [{ "name": "API" }],
  "paths": {
    "/v1/search": {
      "get": {
        "tags": ["API"],
        "operationId": "search",
        "summary": "Check a frame number",
        "description": "The one call for every check. Asks every connected source in parallel (up to about 3 seconds); the answer lists each source and what happened there. A source that does not answer in time is listed with `state: unavailable` and a link for checking it by hand.\n\nParameters decide what else happens: `certificate=true` keeps the result as a certificate and returns its link; `watch_months` keeps watching the number.",
        "parameters": [
          { "name": "serial", "in": "query", "required": true, "description": "Frame number as written on the bike. At least 4 letters or digits and at most 100 characters; placeholders such as \"unknown\" are rejected.", "schema": { "type": "string", "maxLength": 100 }, "example": "WTU087G0122P" },
          { "$ref": "#/components/parameters/brand" },
          { "$ref": "#/components/parameters/model" },
          { "$ref": "#/components/parameters/color" },
          { "$ref": "#/components/parameters/certificate" },
          { "$ref": "#/components/parameters/watch_months" },
          { "$ref": "#/components/parameters/reference" }
        ],
        "responses": {
          "200": { "description": "Search result", "content": { "application/json": { "schema": { "allOf": [
            { "$ref": "#/components/schemas/SearchResult" },
            { "type": "object", "properties": {
              "certificate": { "$ref": "#/components/schemas/CertificateRef" },
              "watch": { "$ref": "#/components/schemas/WatchRef" }
            } }
          ] } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/TooManyRequests" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/watches": {
      "get": {
        "tags": ["API"],
        "operationId": "listWatches",
        "summary": "List watched numbers",
        "description": "Numbers your organisation is watching, most recently changed first. A watch ends by itself at `expires_at`.",
        "responses": {
          "200": { "description": "Watched numbers", "content": { "application/json": { "schema": { "type": "object", "properties": { "watches": { "type": "array", "items": { "$ref": "#/components/schemas/Watch" } } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/watches/{id}": {
      "delete": {
        "tags": ["API"],
        "operationId": "stopWatch",
        "summary": "Stop watching a number",
        "description": "Stops the watch and deletes the number it kept.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "integer" } }
        ],
        "responses": {
          "204": { "description": "Stopped" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "description": "No such watch for your organisation", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/records": {
      "put": {
        "tags": ["API"],
        "operationId": "putRecords",
        "summary": "Send your registry's records (registries)",
        "description": "For registries whose data bikeapi.eu holds. The body is your **complete** export and replaces everything sent before: records missing from it are removed from the search. CSV (a first row naming the columns; comma or semicolon) or JSON (an array of objects, or `{\"records\": [...]}`), up to 100 MB.\n\nFields: `serial` and `status` (`stolen` or `registered`) are required; `id` (your record number — keeps records stable between exports), `brand`, `model`, `color`, `year`, `country`, `url` are optional. Any other field — owner names, addresses, phone numbers — is ignored and never stored.\n\nAn export that would remove more than half of 100 or more records is refused in case it was cut off; add `allow_shrink=1` if that is intended. An empty JSON list (`[]` or `{\"records\": []}`) is accepted only with `allow_shrink=1`, and then removes all your records. Watched numbers whose records changed are checked again at once.",
        "parameters": [
          { "name": "allow_shrink", "in": "query", "required": false, "description": "Confirm an export that removes more than half of your records, or all of them.", "schema": { "type": "string", "enum": ["1"] } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "text/csv": { "schema": { "type": "string" }, "example": "id;serial;brand;model;color;year;status;country;url\nA-1023;WTU087G0122P;Trek;Marlin 5;black;2021;stolen;SI;https://registry.example/bikes/1023\n" },
            "application/json": { "schema": { "type": "array", "items": { "type": "object" } } }
          }
        },
        "responses": {
          "200": { "description": "Imported", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ImportReport" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "description": "`no_source`: your organisation has no registry data source at bikeapi.eu yet.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "413": { "description": "`too_large`: more than 100 MB.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "422": { "description": "Refused; nothing changed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ImportReport" } } } }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": { "type": "http", "scheme": "bearer", "description": "Your API key, e.g. `bk_live_...`. `X-API-Key: <key>` is accepted too." }
    },
    "parameters": {
      "brand": { "name": "brand", "in": "query", "required": false, "description": "Manufacturer, as known. Strongly recommended: frame numbers repeat across manufacturers.", "schema": { "type": "string", "maxLength": 64 }, "example": "Trek" },
      "model": { "name": "model", "in": "query", "required": false, "description": "Model name, as known.", "schema": { "type": "string", "maxLength": 64 }, "example": "Remedy 7" },
      "color": { "name": "color", "in": "query", "required": false, "description": "Colour in any common European language (black, schwarz, zwart, noir, nero, czarny, črna…).", "schema": { "type": "string", "maxLength": 64 }, "example": "blue" },
      "certificate": { "name": "certificate", "in": "query", "required": false, "description": "Keep this check's result as a certificate and return its link in `certificate.url`. The page shows what was checked, when, against which sources and with what result, as it was at that moment; it can be printed to PDF from the browser. A certificate is kept for five years after issue (`certificate.expires_at`), then deleted together with the frame number it records. Off unless given.", "schema": { "type": "boolean", "default": false }, "example": true },
      "watch_months": { "name": "watch_months", "in": "query", "required": false, "description": "Keep watching this number for 1 to 24 months: it is checked again every day, and your notification addresses get an e-mail whenever a record of it appears, changes status or disappears in any registry. Watching a number again renews it. Off unless given.", "schema": { "type": "integer", "minimum": 0, "maximum": 24 }, "example": 12 },
      "reference": { "name": "reference", "in": "query", "required": false, "description": "Your own reference shown on the certificate and kept with a watch (repeated in its e-mails), e.g. a claim number. Do not put personal data here.", "schema": { "type": "string", "maxLength": 64 }, "example": "CLAIM-2026-117" }
    },
    "schemas": {
      "Hints": {
        "type": "object",
        "properties": {
          "brand": { "type": "string", "maxLength": 64 },
          "model": { "type": "string", "maxLength": 64 },
          "color": { "type": "string", "maxLength": 64 }
        }
      },
      "Query": {
        "allOf": [
          { "type": "object", "required": ["serial"], "properties": { "serial": { "type": "string", "description": "As sent." } } },
          { "$ref": "#/components/schemas/Hints" }
        ]
      },
      "SearchResult": {
        "type": "object",
        "required": ["query", "result", "matches", "restricted_hits", "sources", "checked_at"],
        "properties": {
          "query": { "$ref": "#/components/schemas/Query" },
          "result": {
            "type": "string",
            "enum": ["stolen", "registered", "restricted_match", "possible_match", "not_found"],
            "description": "`stolen` — an exact or similar match is reported stolen; `registered` — exact or similar matches, none stolen; `restricted_match` — only a restricted source holds the number (see `restricted_hits`); `possible_match` — only partial or close matches; `not_found` — nothing in the sources checked."
          },
          "matches": { "type": "array", "items": { "$ref": "#/components/schemas/Match" }, "description": "Best first: match level, then agreement with brand, model and colour, then stolen before registered." },
          "restricted_hits": { "type": "array", "items": { "$ref": "#/components/schemas/RestrictedHit" } },
          "sources": { "type": "array", "items": { "$ref": "#/components/schemas/SourceState" }, "description": "What happened at each source during this check." },
          "checked_at": { "type": "string", "format": "date-time" }
        }
      },
      "Match": {
        "type": "object",
        "required": ["source", "source_name", "status", "match", "serial"],
        "properties": {
          "source": { "type": "string", "example": "bikeindex" },
          "source_name": { "type": "string", "example": "Bike Index" },
          "country": { "type": "string", "description": "ISO 3166-1 alpha-2: where the bike was reported stolen, or the registry's country.", "example": "GB" },
          "status": { "type": "string", "enum": ["stolen", "registered"] },
          "brand": { "type": "string", "example": "Trek" },
          "brand_match": { "type": "boolean", "description": "Present when you sent a brand and the record has one." },
          "model": { "type": "string", "example": "Remedy 7" },
          "model_match": { "type": "boolean" },
          "color": { "type": "string", "example": "Blue, Black" },
          "color_match": { "type": "boolean", "description": "Same basic colour. A mismatch alone proves little: stolen bikes get repainted." },
          "year": { "type": "integer", "example": 2021 },
          "match": { "type": "string", "enum": ["exact", "similar", "partial", "close"] },
          "serial": { "type": "string", "description": "The number as the registry recorded it.", "example": "WTU 087 G0122P" },
          "url": { "type": "string", "format": "uri", "description": "The record's page at the registry, when it has one." }
        }
      },
      "RestrictedHit": {
        "type": "object",
        "required": ["source", "source_name"],
        "properties": {
          "source": { "type": "string" },
          "source_name": { "type": "string" },
          "country": { "type": "string" },
          "contact_url": { "type": "string", "format": "uri" }
        }
      },
      "SourceState": {
        "type": "object",
        "required": ["source", "source_name", "state"],
        "properties": {
          "source": { "type": "string" },
          "source_name": { "type": "string" },
          "country": { "type": "string" },
          "state": { "type": "string", "enum": ["ok", "unavailable", "link_only"], "description": "`ok` — checked; `unavailable` — did not answer in time; `link_only` — not checked automatically, use `check_url`." },
          "check_url": { "type": "string", "format": "uri", "description": "For sources not checked in this search: where to check by hand." },
          "link_kind": { "type": "string", "enum": ["result", "form"], "description": "`result` — the link opens the registry's answer for this number; `form` — the registry's check page, type the number there." }
        }
      },
      "CertificateRef": {
        "type": "object",
        "description": "Present when `certificate=true` was given.",
        "required": ["code", "url", "issued_at", "expires_at"],
        "properties": {
          "code": { "type": "string", "example": "3o5ja7gtfc2hidv2" },
          "url": { "type": "string", "format": "uri", "example": "https://bikeapi.eu/c/3o5ja7gtfc2hidv2" },
          "issued_at": { "type": "string", "format": "date-time" },
          "expires_at": { "type": "string", "format": "date-time", "description": "Five years after issue. From then the link answers 404 and the certificate is deleted." }
        }
      },
      "WatchRef": {
        "type": "object",
        "description": "Present when `watch_months` was given and watching started.",
        "properties": {
          "id": { "type": "integer", "example": 41 },
          "expires_at": { "type": "string", "format": "date-time" }
        }
      },
      "Watch": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "serial": { "type": "string", "description": "As you sent it." },
          "brand": { "type": "string" },
          "model": { "type": "string" },
          "color": { "type": "string" },
          "reference": { "type": "string" },
          "result": { "type": "string", "enum": ["stolen", "registered", "restricted_match", "possible_match", "not_found"], "description": "Overall result as of the last change." },
          "created_at": { "type": "string", "format": "date-time" },
          "expires_at": { "type": "string", "format": "date-time" },
          "checked_at": { "type": "string", "format": "date-time" },
          "changed_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "ImportReport": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "enum": ["ok", "refused", "failed"] },
          "received": { "type": "integer", "description": "Rows in the export." },
          "added": { "type": "integer" },
          "updated": { "type": "integer" },
          "removed": { "type": "integer", "description": "Records sent before that are missing from this export." },
          "rejected": { "type": "integer", "description": "Rows skipped, e.g. a placeholder instead of a frame number." },
          "problems": { "type": "array", "items": { "type": "string" }, "description": "What was wrong with skipped rows (the first 50).", "example": ["line 12: \"unknown\" is a placeholder, not a frame number"] },
          "message": { "type": "string" }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error", "message"],
        "properties": {
          "error": { "type": "string", "description": "Stable code to branch on.", "example": "serial_too_short" },
          "message": { "type": "string", "description": "Human-readable explanation." }
        }
      }
    },
    "responses": {
      "BadRequest": { "description": "Invalid input: `missing_serial`, `serial_too_short`, `serial_too_long`, `serial_placeholder`, `invalid_serial`, `reference_too_long`, `bad_certificate`, `bad_watch_months`.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Unauthorized": { "description": "`missing_key` or `invalid_key` (unknown or revoked).", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Forbidden": { "description": "`partner_suspended`; `key_kind` (a widget key used server-side); `trial_limit_reached`: a trial account has used all its checks — write to info@bikeapi.eu to go on.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "TooManyRequests": { "description": "`rate_limited`: the key's per-minute limit, or the per-address limit (20 requests per second, bursts of 50), is used up. Wait `Retry-After` seconds.", "headers": { "Retry-After": { "schema": { "type": "integer" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Unavailable": { "description": "`unavailable`: try again shortly. With `certificate=true` this also means the certificate could not be saved; none was issued.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  }
}
