{
 "openapi": "3.1.0",
 "info": {
  "title": "BlankQR",
  "version": "1.0.0",
  "summary": "Blank QR codes to print and place in advance, set up later with a key or by the first scan. One call makes a Dynamic code, with no account or API key. Each code holds a short blankqr.com address, and its key sets and changes what a scan does after printing. A scan of a free code shows a sponsor page first.",
  "description": "A code can open a link, start an email, a call or a text message, or show Wi-Fi details, a contact card, a note, a place on a map or an event.\n\n- A blank code works from the moment it is made and does nothing yet, so it can be printed and placed in advance. Whoever scans it first can set it up, and gets a key to it. The key from making the code can change it back and remove that second key. Set it up before it is left in public, unless that is the intent. On the paid plan, or for a code with Lifetime, the key from making a code can put a password on it while it is blank: send \"password\" with the key to /api/links/CODE. A first scan then has to send the same \"password\". The key still sets the code up without it. A lost password cannot be recovered.\n- On the paid plan, or for a code with Lifetime, the key from making a code can also put a scan password on it, blank or set up: send \"scan_password\" with the key to /api/links/CODE (\"\" removes it). A scan then shows a password page before anything else, and the answers anyone can read for the code hold \"scan_password\": true with \"url\" and \"action\" null. A lost scan password cannot be recovered; the key replaces or removes it.\n- On the paid plan, or for a code with Lifetime, the key from making a code can also switch on two checks, each on its own: \"camera_check\": true (a scan opens the code after the scanner shows the printed code to their camera) and \"location_check\": {\"lat\": 40.6892, \"lon\": -74.0445} (a scan opens the code when the phone is near that spot). Send either with the key to /api/links/CODE; false takes it off. The page a scan opens does both in the scanner's browser, and the phone's place is not sent to BlankQR. The answers anyone can read for the code then hold \"camera_check\" or \"location_check\": true with \"url\" and \"action\" null. A check is asked for once the code is set up, and the pass it gives works for a few minutes. The checks stop a link that was passed on. They are no proof that a person is at the code.\n- On the paid plan, or for a code with Lifetime, a code can have up to ten destinations, each with a percent chance: send \"chances\" with the key from making the code to /api/links/CODE, a list of up to 9 others, each {\"url\" or \"action\", \"percent\": 1 to 99}, adding up to 99 at most. The code's own destination gets the rest. Each scan goes to one of them, picked by chance; [] takes them off. The answers anyone can read then hold \"chance\": true with \"url\" and \"action\" null. Without the paid plan the code goes to its own destination alone.\n- On the paid plan, or for a code with Lifetime, a code can have a webhook: send \"webhook\" with an https address (port 443 or 8443) and the key from making the code to /api/links/CODE, \"\" takes it off. Each counted scan then sends a POST to that address with the JSON {\"code\", \"time\", \"scans\"}: the code, the time in UTC and the scan count. Nothing about the scanner is sent. It is sent once, the answer is not read and a redirect is not followed. \"webhook_test\": true sends one now with \"test\": true and tells what came back in \"webhook_delivered\" and \"webhook_status\". To know a call is ours, put a secret of your own in the address.\n- On the paid plan, or for a code with Lifetime, a code can run your own code: a page of HTML, JavaScript, styles and pictures, 1 MB in total for the code. We only keep the files; the code runs in the scanner's browser. Send the files to /api/links/CODE/files as {\"token\", \"files\": [{\"name\": \"index.html\", \"text\": \"...\"}, {\"name\": \"img/logo.png\", \"base64\": \"...\"}]}; {\"name\", \"remove\": true} removes one. Then set the code to {\"action\": {\"kind\": \"page\"}} with /api/links/CODE. The page starts at index.html and reaches its other files by relative names. It runs in a sandbox with an origin of its own: scripts, forms and calls to other sites work; cookies and storage do not, and it cannot reach this site. Camera, microphone, location and downloads are off inside the page. The key's answers list the files in \"files\".\n- Making, printing and changing a Dynamic code is free. No account or API key is needed, and there is no CAPTCHA.\n- A scan of a free code shows a sponsor page first, with a Skip ad button. The page never forwards by itself. A free code suits print that people scan. It does not redirect a program silently.\n- A free Dynamic code expires when it has not been scanned or changed for 12 months, blank or set up. After that day the code is deleted: every call answers as for a code that was never made (404), and its address may be given out again. No reminder is sent. The answers that make, read or list codes give that day as \"expires\" (YYYY-MM-DD). Every scan or change moves it on. A code in a paid plan or with Lifetime does not expire, and its \"expires\" is null.\n- The paid plan costs $5 a month or $48 a year. Sales tax may be added. It belongs to an account and applies to the codes in it. Its codes show no sponsor page, a link opens at once, and they do not expire. Scans are counted per day. Lifetime costs $5 once for one code. That code then shows no sponsor page and does not expire. Nothing renews. A person pays, signed in, at https://blankqr.com/codes.\n- When a paid plan ends, its codes are free codes again. The sponsor page returns, and a code expires when it has not been scanned or changed for 12 months. Scans per day counted so far stay stored, are hidden, and show again if the plan returns. A plan can be cancelled at any time and runs to the end of the time paid for. A payment is refunded in full when asked for within 14 days, through https://blankqr.com/contact.\n- A Static code holds its content inside the picture. It does not expire, works without this site and cannot be changed or left blank. A scan goes straight to its content. Static codes are made in a browser at https://blankqr.com/free-qr-code-generator. The API makes Dynamic codes.\n- Use a Static code when the content will never change. A free Dynamic code is a poor fit for a link that must open with no page in between, and for a code that will be neither scanned nor changed for 12 months.\n- Links must be public http or https website names: no IP addresses, no user name or password in the link, nothing on public threat lists. Phone numbers need a country code.\n- Limits per network address: 20 new codes per hour and 60 per day; 30 calls with a key per hour, wrong keys included, the first set-up of a blank code not counted, and a read with the key held to its own 120 per 10 minutes; 120 look-ups and pictures per 10 minutes. All users together: 5000 new codes per day. A refused call answers 429 with Retry-After in seconds.\n- The key (token) of a code is shown once, in the answer that makes the code. Only a fingerprint of it is stored. If it is lost, nobody can change the code, the service included.\n- Stored per code: what it does (with any text it shows), the day it was made, a count of scans, the day of the last scan, a fingerprint of each key and of each password, and an email address for each key that gave one. For a paid code in an account, also its scans per day. Nothing about who scanned it.\n- No availability guarantee. If the site stops, every Dynamic code stops with it.\n- Codes that break the rules are disabled, and anyone can report one at https://blankqr.com/report.\n- Web pages on other sites cannot call the API from a browser (cross-site requests are refused). Call it from a program."
 },
 "servers": [
  {
   "url": "https://blankqr.com"
  }
 ],
 "paths": {
  "/api/links": {
   "post": {
    "summary": "Make a Dynamic code (no key needed)",
    "operationId": "makeCode",
    "description": "Send {\"blank\": true} for a code that works and does nothing yet, or \"action\" (or \"url\") for one that is set up at once. The answer holds the key; it is not shown again. With an account key the code joins that account.",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "pattern": "^[A-Za-z0-9_.:-]{8,64}$"
      },
      "description": "A new random value for every code. A repeated call with the same value and the same body from the same network address within a day returns the first answer and makes no second code; the same value with another body is refused. A restart of the service forgets it."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "blank": {
          "type": "boolean",
          "description": "true: a blank code."
         },
         "action": {
          "$ref": "#/components/schemas/Action"
         },
         "url": {
          "type": "string",
          "description": "The same as action, in written form: an http or https address (or mailto:, tel:, sms:)."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "The new code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Link"
        }
       }
      }
     },
     "400": {
      "description": "The body is not a JSON object, or the Idempotency-Key is not usable.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "The account key is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "The body is too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "415": {
      "description": "Send the body as JSON.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "What the code should do was refused; the error says why.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "A limit is reached. Retry-After says when to try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "security": [
     {},
     {
      "accountKey": []
     }
    ]
   }
  },
  "/api/links/{code}": {
   "get": {
    "summary": "Read a code",
    "operationId": "readCode",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "What anyone may know about the code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Facts"
        }
       }
      }
     },
     "401": {
      "description": "The account key is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No such code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "That is not a 7-character code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many look-ups.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Set up, change or switch a code with its key",
    "operationId": "changeCode",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     }
    ],
    "description": "Send the key as \"token\" with one of: \"action\" (or \"url\") to set or change what a scan does; \"active\" to switch the code off or on; \"look\": true to read it with the key; \"drop_scan_key\": true to remove the key a first scanner holds; \"email\" (and \"updates\") to keep this key's own email address with the code, \"\" to remove it; \"password\" to put a set-up password on a blank code, \"\" to remove it; \"scan_password\" to put a scan password on any code, \"\" to remove it; \"camera_check\" true or false, and \"location_check\" with a spot or false, for the two checks a scan can be asked to pass; \"chances\" for more destinations picked by chance, [] to take them off. With an account key, \"token\" may be empty for a code of that account, and only \"action\" (or \"url\"), \"active\" and \"look\" are served. A locked code is refused.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "token"
        ],
        "properties": {
         "token": {
          "type": "string"
         },
         "action": {
          "$ref": "#/components/schemas/Action"
         },
         "url": {
          "type": "string"
         },
         "active": {
          "type": "boolean"
         },
         "look": {
          "type": "boolean"
         },
         "drop_scan_key": {
          "type": "boolean"
         },
         "email": {
          "type": "string",
          "description": "This key's own address; \"\" removes it."
         },
         "updates": {
          "type": "boolean",
          "description": "true: the address asks for announcements about the service."
         },
         "password": {
          "type": "string",
          "description": "8 to 64 characters. Only the key from making the code, only while the code is blank."
         },
         "scan_password": {
          "type": "string",
          "description": "8 to 64 characters. Only the key from making the code. Asked for at every scan before the code shows what it does."
         },
         "camera_check": {
          "type": "boolean",
          "description": "Only the key from making the code. true: a scan opens the code after the scanner shows the printed code to their camera."
         },
         "webhook": {
          "type": "string",
          "description": "Only the key from making the code. An https address that gets a POST with {\"code\", \"time\", \"scans\"} on each counted scan; \"\" takes it off."
         },
         "webhook_test": {
          "type": "boolean",
          "description": "Only the key from making the code. true: one call to the webhook now, marked \"test\": true; the answer holds \"webhook_delivered\" and \"webhook_status\"."
         },
         "chances": {
          "type": "array",
          "maxItems": 9,
          "description": "Only the key from making the code. The other destinations of the code, each with a percent chance (1 to 99, together 99 at most); the code's own destination gets the rest. [] takes them off.",
          "items": {
           "type": "object",
           "required": [
            "percent"
           ],
           "properties": {
            "url": {
             "type": "string"
            },
            "action": {
             "$ref": "#/components/schemas/Action"
            },
            "percent": {
             "type": "integer",
             "minimum": 1,
             "maximum": 99
            }
           }
          }
         },
         "location_check": {
          "description": "Only the key from making the code. { \"lat\", \"lon\" }: a scan opens the code when the phone is near that spot. false takes it off.",
          "oneOf": [
           {
            "type": "object",
            "required": [
             "lat",
             "lon"
            ],
            "properties": {
             "lat": {
              "type": "number",
              "minimum": -90,
              "maximum": 90
             },
             "lon": {
              "type": "number",
              "minimum": -180,
              "maximum": 180
             }
            }
           },
           {
            "type": "boolean",
            "enum": [
             false
            ]
           }
          ]
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The code after the call.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/KeyFacts"
        }
       }
      }
     },
     "401": {
      "description": "The account key is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The key is not valid for this code, the code is locked to an account, an account key sent an email address, or only the key from making the code may do this.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "A set-up password was sent for a code that is set up already.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The code was disabled for breaking the rules.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "The body is too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "415": {
      "description": "Send the body as JSON.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "What the code should do was refused.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "More than 30 calls with a key in an hour from this address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "security": [
     {},
     {
      "accountKey": []
     }
    ]
   }
  },
  "/api/scan/{code}": {
   "post": {
    "summary": "Set up a blank code without a key (first scan)",
    "operationId": "firstScan",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     }
    ],
    "description": "What the page behind a blank code does when a person fills it in. It works once per code and answers with a key for whoever did it. Setting a code up is not counted. Refused attempts are held to 10 per hour per address.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "action": {
          "$ref": "#/components/schemas/Action"
         },
         "url": {
          "type": "string"
         },
         "password": {
          "type": "string",
          "description": "Needed when the code has a set-up password."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The code is set up; the answer holds a key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Link"
        }
       }
      }
     },
     "401": {
      "description": "The account key is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The code has a set-up password and it was missing or wrong, or the code is locked to an account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No such code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The code is already set up.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The code is switched off, or was disabled for breaking the rules.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "The body is too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "415": {
      "description": "Send the body as JSON.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "Refused; the error says why.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many attempts.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/open/{code}": {
   "post": {
    "summary": "Enter the scan password of a code",
    "operationId": "openCode",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     }
    ],
    "description": "What the password page of a code does. The answer holds \"to\": the address of the code with a pass that opens it for an hour. A code that asks for no password answers with its plain address.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "password"
        ],
        "properties": {
         "password": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Where to go on.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "to": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "The account key is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The password was missing or wrong.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No such code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "The body is too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "415": {
      "description": "Send the body as JSON.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many attempts.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/{code}.svg": {
   "get": {
    "summary": "The picture of a code as SVG",
    "description": "The picture holds the code's short address and nothing else, so it is the same whatever the code does.",
    "operationId": "pictureSVG",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 64,
       "maximum": 2048,
       "default": 512,
       "description": "Largest width in pixels (PNG only; an SVG has no pixel size). Each module is a whole number of pixels, so the picture can come out a little smaller."
      }
     },
     {
      "name": "margin",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0,
       "maximum": 16,
       "default": 4,
       "description": "Quiet border in modules. Scanners expect 4."
      }
     },
     {
      "name": "level",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "L",
        "M",
        "Q",
        "H"
       ],
       "default": "M",
       "description": "Error correction. Higher survives more damage and makes a denser picture."
      }
     },
     {
      "name": "dark",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "description": "Colour of the dark modules as six hex digits. It has to be much darker than light: a pair a phone cannot tell apart is refused.",
       "pattern": "^#?[0-9a-fA-F]{6}$",
       "default": "000000"
      }
     },
     {
      "name": "light",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "description": "Colour of the background as six hex digits.",
       "pattern": "^#?[0-9a-fA-F]{6}$",
       "default": "ffffff"
      }
     },
     {
      "name": "shape",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "square",
        "dots"
       ],
       "default": "square",
       "description": "Square modules, or round dots with rounded corner marks."
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The picture.",
      "content": {
       "image/svg+xml": {}
      }
     },
     "400": {
      "description": "An option is out of range.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No such code."
     },
     "429": {
      "description": "Too many requests."
     }
    }
   }
  },
  "/{code}.png": {
   "get": {
    "summary": "The picture of a code as PNG",
    "description": "The picture holds the code's short address and nothing else, so it is the same whatever the code does.",
    "operationId": "picturePNG",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 64,
       "maximum": 2048,
       "default": 512,
       "description": "Largest width in pixels (PNG only; an SVG has no pixel size). Each module is a whole number of pixels, so the picture can come out a little smaller."
      }
     },
     {
      "name": "margin",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0,
       "maximum": 16,
       "default": 4,
       "description": "Quiet border in modules. Scanners expect 4."
      }
     },
     {
      "name": "level",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "L",
        "M",
        "Q",
        "H"
       ],
       "default": "M",
       "description": "Error correction. Higher survives more damage and makes a denser picture."
      }
     },
     {
      "name": "dark",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "description": "Colour of the dark modules as six hex digits. It has to be much darker than light: a pair a phone cannot tell apart is refused.",
       "pattern": "^#?[0-9a-fA-F]{6}$",
       "default": "000000"
      }
     },
     {
      "name": "light",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "description": "Colour of the background as six hex digits.",
       "pattern": "^#?[0-9a-fA-F]{6}$",
       "default": "ffffff"
      }
     },
     {
      "name": "shape",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "square",
        "dots"
       ],
       "default": "square",
       "description": "Square modules, or round dots with rounded corner marks."
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The picture.",
      "content": {
       "image/png": {}
      }
     },
     "400": {
      "description": "An option is out of range.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No such code."
     },
     "429": {
      "description": "Too many requests."
     }
    }
   }
  },
  "/{code}.vcf": {
   "get": {
    "summary": "The contact card a code holds, as a vCard file",
    "operationId": "contactFile",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The card.",
      "content": {
       "text/vcard": {}
      }
     },
     "302": {
      "description": "The file is given from the page of the code, which carries a pass for it. Without a valid pass (a code with a sponsor page, or with a scan password): on to the address of the code."
     },
     "404": {
      "description": "The code holds no contact card."
     },
     "429": {
      "description": "Too many look-ups."
     }
    }
   }
  },
  "/{code}.ics": {
   "get": {
    "summary": "The event a code holds, as a calendar file",
    "operationId": "eventFile",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The event.",
      "content": {
       "text/calendar": {}
      }
     },
     "302": {
      "description": "The file is given from the page of the code, which carries a pass for it. Without a valid pass (a code with a sponsor page, or with a scan password): on to the address of the code."
     },
     "404": {
      "description": "The code holds no event."
     },
     "429": {
      "description": "Too many look-ups."
     }
    }
   }
  },
  "/api/report": {
   "post": {
    "summary": "Report a code that leads somewhere harmful",
    "operationId": "reportCode",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "code"
        ],
        "properties": {
         "code": {
          "type": "string",
          "description": "The short address or its 7 characters."
         },
         "kind": {
          "type": "string",
          "enum": [
           "phishing",
           "malware",
           "illegal",
           "copyright",
           "other"
          ]
         },
         "details": {
          "type": "string",
          "description": "At most 300 characters."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Recorded."
     },
     "401": {
      "description": "The account key is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No such code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "The body is too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "415": {
      "description": "Send the body as JSON.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "The code is not a short address or 7 characters.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "More than 5 reports in an hour from this address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The report queue is full.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/links/{code}/files": {
   "post": {
    "summary": "Send or remove the files of a code's own page",
    "operationId": "setFiles",
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[2-9a-zA-Z]{7}$"
      }
     }
    ],
    "description": "With the key from making the code, or an account key. The files are added, replaced or removed in one step, 1 MB in total for the code; the body of one call can be 1.5 MB. Adding needs the paid plan, removing does not. The page starts at index.html.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "token",
         "files"
        ],
        "properties": {
         "token": {
          "type": "string",
          "description": "The key of the code, from the answer that made it. With an account key, \"\" for a code of that account."
         },
         "files": {
          "type": "array",
          "minItems": 1,
          "maxItems": 60,
          "description": "Files to add or replace, or to remove. A name is letters, digits, dots, dashes and underscores with up to three folders, like \"index.html\" or \"img/logo.png\".",
          "items": {
           "type": "object",
           "required": [
            "name"
           ],
           "properties": {
            "name": {
             "type": "string"
            },
            "text": {
             "type": "string",
             "description": "The file as text."
            },
            "base64": {
             "type": "string",
             "description": "The file as base64, for pictures and other files that are not text."
            },
            "remove": {
             "type": "boolean",
             "description": "true: the file is removed."
            }
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The code after the call.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/KeyFacts"
        }
       }
      }
     },
     "401": {
      "description": "The account key is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The key is not valid for this code, or the plan does not include a page with your own code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The code opens its page and the call would remove index.html.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "A name or a kind of file that is not taken, or more than the code can hold.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many attempts.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/account/codes": {
   "get": {
    "summary": "List the codes of an account",
    "operationId": "listAccountCodes",
    "security": [
     {
      "accountKey": []
     }
    ],
    "responses": {
     "200": {
      "description": "The codes of the account the key belongs to.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "codes": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "code": {
              "type": "string"
             },
             "short": {
              "type": "string",
              "description": "The address inside the picture.",
              "format": "uri"
             },
             "does": {
              "type": "string",
              "description": "What the code does, in words."
             },
             "state": {
              "type": "string",
              "enum": [
               "blank",
               "active",
               "off",
               "disabled"
              ]
             },
             "expires": {
              "type": [
               "string",
               "null"
              ],
              "format": "date",
              "description": "The day the code expires if it is not scanned or changed before then: 12 months after it was last scanned or changed, or after the day it was made while neither has happened. null for a code that does not expire."
             },
             "locked": {
              "type": "boolean"
             },
             "opens": {
              "type": "integer"
             },
             "days": {
              "type": "array",
              "description": "Pairs of day (days since 1970-01-01, UTC) and scans on that day. Empty where the account keeps no scans per day.",
              "items": {
               "type": "array",
               "items": {
                "type": "integer"
               }
              }
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No account key, or one that is not valid.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Action": {
    "type": "object",
    "required": [
     "kind"
    ],
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "link",
       "email",
       "call",
       "message",
       "wifi",
       "contact",
       "note",
       "place",
       "event",
       "page"
      ],
      "description": "What a scan does. Each kind uses the fields named in its description below; leave the others out. page: the code runs your own page, no fields; its files are sent first to /api/links/CODE/files."
     },
     "url": {
      "type": "string",
      "description": "link: the public http or https address to open. No IP addresses, no user name or password in it."
     },
     "to": {
      "type": "string",
      "description": "email: the address the email goes to."
     },
     "subject": {
      "type": "string",
      "description": "email: subject line, optional, at most 200 characters."
     },
     "message": {
      "type": "string",
      "description": "email: prefilled words, optional, at most 600 characters. message (text message): prefilled words, optional, at most 300."
     },
     "number": {
      "type": "string",
      "description": "call and message: the phone number in international form, like +15550100199. Short numbers are refused."
     },
     "name": {
      "type": "string",
      "description": "wifi: the network name, at most 32 characters. place: a name for the place, optional, at most 100."
     },
     "password": {
      "type": "string",
      "description": "wifi: the network password, at most 64 characters. Leave out when security is none. Everyone who scans the code can read it."
     },
     "security": {
      "type": "string",
      "enum": [
       "WPA",
       "WEP",
       "none"
      ],
      "description": "wifi: WPA covers WPA, WPA2 and WPA3. Default WPA."
     },
     "hidden": {
      "type": "boolean",
      "description": "wifi: true when the network does not announce its name."
     },
     "first_name": {
      "type": "string",
      "description": "contact: at most 60 characters. A contact needs a first name, a last name or an organisation."
     },
     "last_name": {
      "type": "string",
      "description": "contact: at most 60 characters."
     },
     "organisation": {
      "type": "string",
      "description": "contact: at most 100 characters."
     },
     "title": {
      "type": "string",
      "description": "contact: job title, optional, at most 100 characters. event: the title of the event, at most 120."
     },
     "phone": {
      "type": "string",
      "description": "contact: phone number in international form, optional."
     },
     "email": {
      "type": "string",
      "description": "contact: email address, optional."
     },
     "website": {
      "type": "string",
      "description": "contact: public http or https address, optional, at most 300 characters."
     },
     "address": {
      "type": "string",
      "description": "contact: postal address on one line, optional, at most 200 characters."
     },
     "note": {
      "type": "string",
      "description": "contact: a note, optional, at most 300 characters."
     },
     "text": {
      "type": "string",
      "description": "note: the words a scan shows, at most 1000 characters."
     },
     "latitude": {
      "type": "number",
      "minimum": -90,
      "maximum": 90,
      "description": "place: degrees north, like 40.6892."
     },
     "longitude": {
      "type": "number",
      "minimum": -180,
      "maximum": 180,
      "description": "place: degrees east, like -74.0445."
     },
     "start": {
      "type": "string",
      "description": "event: the day, or the day and time, it starts: 2026-12-24 or 2026-12-24T18:00. Times carry no time zone; they mean the clock at the place of the event."
     },
     "end": {
      "type": "string",
      "description": "event: when it ends, in the same form as start, optional. With a start time, give an end time or none."
     },
     "location": {
      "type": "string",
      "description": "event: where it is, optional, at most 200 characters."
     },
     "details": {
      "type": "string",
      "description": "event: more words, optional, at most 500 characters."
     }
    },
    "description": "What a scan of the code does. A code can open a link, start an email, a call or a text message, or show Wi-Fi details, a contact card, a note, a place on a map or an event. Wi-Fi details, contact cards, notes, places and events are short text kept with the code (at most 2000 bytes) and shown by the page a scan opens; a link is only stored, the page it leads to is not.",
    "examples": [
     {
      "kind": "link",
      "url": "https://example.com/menu"
     },
     {
      "kind": "wifi",
      "name": "Cafe Guest",
      "password": "espresso-2026",
      "security": "WPA"
     },
     {
      "kind": "contact",
      "first_name": "Dana",
      "last_name": "Reyes",
      "phone": "+15550100199",
      "email": "dana@example.com"
     },
     {
      "kind": "event",
      "title": "Winter market",
      "start": "2026-12-24T18:00",
      "end": "2026-12-24T20:30",
      "location": "Town square"
     }
    ]
   },
   "Link": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string",
      "description": "The 7 characters at the end of the short address."
     },
     "short": {
      "type": "string",
      "description": "The address inside the picture.",
      "format": "uri"
     },
     "token": {
      "type": "string",
      "description": "The key of this code. Shown only here. Whoever has it can change the code or switch it off."
     },
     "edit": {
      "type": "string",
      "description": "A page where a person can use the key. The key is in the part after #, which browsers do not send to servers.",
      "format": "uri"
     },
     "stats": {
      "type": "string",
      "description": "The public counter page.",
      "format": "uri"
     },
     "svg": {
      "type": "string",
      "description": "The picture as SVG.",
      "format": "uri"
     },
     "png": {
      "type": "string",
      "description": "The picture as PNG.",
      "format": "uri"
     },
     "state": {
      "type": "string",
      "enum": [
       "blank",
       "active"
      ]
     },
     "expires": {
      "type": [
       "string",
       "null"
      ],
      "format": "date",
      "description": "The day the code expires if it is not scanned or changed before then: 12 months after it was last scanned or changed, or after the day it was made while neither has happened. null for a code that does not expire."
     },
     "url": {
      "type": "string",
      "description": "What the code does, in its stored written form. Absent on a blank code."
     },
     "action": {
      "$ref": "#/components/schemas/Action"
     }
    },
    "required": [
     "code",
     "short",
     "token",
     "edit",
     "stats",
     "svg",
     "png",
     "state"
    ]
   },
   "Facts": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string"
     },
     "short": {
      "type": "string",
      "format": "uri"
     },
     "url": {
      "type": [
       "string",
       "null"
      ],
      "description": "What the code does, in its stored written form. null when blank, off or disabled."
     },
     "action": {
      "oneOf": [
       {
        "$ref": "#/components/schemas/Action"
       },
       {
        "type": "null"
       }
      ]
     },
     "state": {
      "type": "string",
      "enum": [
       "blank",
       "active",
       "off",
       "disabled"
      ],
      "description": "blank: does nothing yet. off: switched off with a key. disabled: removed from use for breaking the rules."
     },
     "expires": {
      "type": [
       "string",
       "null"
      ],
      "format": "date",
      "description": "The day the code expires if it is not scanned or changed before then: 12 months after it was last scanned or changed, or after the day it was made while neither has happened. null for a code that does not expire."
     },
     "scan_password": {
      "type": "boolean",
      "description": "true: a scan asks for a password first, and \"url\" and \"action\" are null here."
     },
     "camera_check": {
      "type": "boolean",
      "description": "true: a scan asks the scanner to show the printed code to their camera first, and \"url\" and \"action\" are null here."
     },
     "chance": {
      "type": "boolean",
      "description": "true: the code has several destinations and a scan goes to one of them by chance; \"url\" and \"action\" are null here."
     },
     "location_check": {
      "type": "boolean",
      "description": "true: a scan opens the code only near a spot its owner picked, and \"url\" and \"action\" are null here. The spot is not told here; the page a scan opens holds it."
     },
     "hits": {
      "type": "integer",
      "description": "How many times the code was scanned. Scans by link-preview robots are not counted."
     },
     "created": {
      "type": "string",
      "format": "date"
     },
     "last_opened": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     }
    },
    "required": [
     "code",
     "state"
    ]
   },
   "KeyFacts": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string"
     },
     "url": {
      "type": [
       "string",
       "null"
      ]
     },
     "action": {
      "oneOf": [
       {
        "$ref": "#/components/schemas/Action"
       },
       {
        "type": "null"
       }
      ]
     },
     "state": {
      "type": "string",
      "enum": [
       "blank",
       "active",
       "off",
       "disabled"
      ]
     },
     "expires": {
      "type": [
       "string",
       "null"
      ],
      "format": "date",
      "description": "The day the code expires if it is not scanned or changed before then: 12 months after it was last scanned or changed, or after the day it was made while neither has happened. null for a code that does not expire."
     },
     "key": {
      "type": "string",
      "enum": [
       "claim",
       "scan",
       "account"
      ],
      "description": "claim: the key given when the code was made. scan: the key given to whoever set up a blank code by scanning it first. account: an account key, for a code of its account."
     },
     "second_key": {
      "type": "boolean",
      "description": "Told to the claim key only: a first scanner holds a key too."
     },
     "password": {
      "type": "boolean",
      "description": "Told to the claim key only: the code has a set-up password."
     },
     "scan_password": {
      "type": "boolean",
      "description": "Told to the claim key only: the code has a scan password."
     },
     "camera_check": {
      "type": "boolean",
      "description": "Told to the claim key only: the code has a camera check."
     },
     "webhook": {
      "type": [
       "string",
       "null"
      ],
      "description": "Told to the claim key only: the address called on each counted scan."
     },
     "files": {
      "type": "array",
      "description": "The files of the code's own page, told to the key that can send them.",
      "items": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "size": {
         "type": "integer",
         "description": "In bytes."
        }
       }
      }
     },
     "files_limit": {
      "type": "integer",
      "description": "How many bytes the files of the code can take together."
     },
     "chances": {
      "type": "array",
      "description": "Told to the claim key only: the other destinations of a code that picks by chance, each with its percent. The code's own \"url\" gets the rest.",
      "items": {
       "type": "object",
       "properties": {
        "url": {
         "type": "string"
        },
        "action": {
         "$ref": "#/components/schemas/Action"
        },
        "percent": {
         "type": "integer"
        }
       }
      }
     },
     "location_check": {
      "type": [
       "object",
       "null"
      ],
      "description": "Told to the claim key only: the spot of the code's location check, or null.",
      "properties": {
       "lat": {
        "type": "number"
       },
       "lon": {
        "type": "number"
       }
      }
     },
     "password_allowed": {
      "type": "boolean",
      "description": "Told to the claim key only: this key may set a password on the code."
     },
     "email": {
      "type": "string",
      "description": "The address this key keeps with the code, \"\" for none. The key from making the code and a first scanner's key each have their own, and each is told only its own."
     },
     "updates": {
      "type": "boolean"
     }
    },
    "required": [
     "code",
     "state",
     "key"
    ]
   },
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "string"
     },
     "hint": {
      "type": "string",
      "description": "What to send instead."
     },
     "retry_after": {
      "type": "integer",
      "description": "Seconds to wait, on a 429."
     }
    },
    "required": [
     "error"
    ]
   }
  },
  "securitySchemes": {
   "accountKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "A key made by a signed-in person at https://blankqr.com/codes. It starts with bqk_."
   }
  }
 }
}