{
  "openapi": "3.1.0",
  "info": {
    "title": "LinkScan API",
    "version": "1.0.0",
    "summary": "Create, edit and track dynamic QR codes, and render QR images.",
    "description": "Manage dynamic QR codes: codes whose printed pattern holds a short LinkScan link, so the destination can be changed after printing and scans are counted. Also renders one-off static QR images. Available on the Free plan under the same limits as the dashboard. Every error is JSON of the form {\"error\": \"message\"}, sometimes with extra fields.",
    "termsOfService": "https://linkscan.org/terms-of-service",
    "contact": {
      "name": "LinkScan",
      "url": "https://linkscan.org/contact"
    }
  },
  "externalDocs": {
    "description": "API documentation",
    "url": "https://linkscan.org/docs/api"
  },
  "servers": [
    {
      "url": "https://linkscan.org"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {
      "apiKeyHeader": []
    }
  ],
  "paths": {
    "/api/v1/codes": {
      "get": {
        "operationId": "listCodes",
        "summary": "List dynamic QR codes",
        "description": "Returns your own codes and every code in a project you belong to, newest first.",
        "security": [
          {
            "bearerAuth": [
              "codes:read"
            ]
          },
          {
            "apiKeyHeader": [
              "codes:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "description": "Only codes in this project.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of codes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "codes",
                    "total",
                    "limit",
                    "offset"
                  ],
                  "properties": {
                    "codes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Code"
                      }
                    },
                    "total": {
                      "type": "integer",
                      "description": "Number of codes across all pages."
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The request is malformed or fails validation. `details` may list each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope, or your plan does not include the feature.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests, or your plan's creation limit is reached. See Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createCode",
        "summary": "Create a dynamic QR code",
        "description": "Counts towards your plan's creation limit (Free: new codes per day; Advanced: per hour). Returns the code with its short link and an imageUrl for the printable image.",
        "security": [
          {
            "bearerAuth": [
              "codes:write"
            ]
          },
          {
            "apiKeyHeader": [
              "codes:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeInput"
              },
              "example": {
                "destination": "https://example.com/menu",
                "name": "Table menu"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new code.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code"
                  ],
                  "properties": {
                    "code": {
                      "$ref": "#/components/schemas/Code"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The request is malformed or fails validation. `details` may list each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope, or your plan does not include the feature.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The requested custom short code is already taken.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests, or your plan's creation limit is reached. See Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/codes/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The code id.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getCode",
        "summary": "Fetch one code",
        "security": [
          {
            "bearerAuth": [
              "codes:read"
            ]
          },
          {
            "apiKeyHeader": [
              "codes:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "The code.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code"
                  ],
                  "properties": {
                    "code": {
                      "$ref": "#/components/schemas/Code"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The request is malformed or fails validation. `details` may list each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope, or your plan does not include the feature.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such code, or it is not yours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests, or your plan's creation limit is reached. See Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateCode",
        "summary": "Update a code",
        "description": "Send only the fields to change. Changing destination takes effect on the next scan; the printed code stays the same.",
        "security": [
          {
            "bearerAuth": [
              "codes:write"
            ]
          },
          {
            "apiKeyHeader": [
              "codes:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeInput"
              },
              "example": {
                "destination": "https://example.com/new-menu"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated code.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code"
                  ],
                  "properties": {
                    "code": {
                      "$ref": "#/components/schemas/Code"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The request is malformed or fails validation. `details` may list each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope, or your plan does not include the feature.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such code, or it is not yours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The requested custom short code is already taken.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests, or your plan's creation limit is reached. See Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteCode",
        "summary": "Delete a code",
        "description": "Permanently deletes the code and its scan history. Any printed copy stops working. This cannot be undone.",
        "security": [
          {
            "bearerAuth": [
              "codes:write"
            ]
          },
          {
            "apiKeyHeader": [
              "codes:write"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deleted": {
                      "type": "boolean"
                    },
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The request is malformed or fails validation. `details` may list each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope, or your plan does not include the feature.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such code, or it is not yours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests, or your plan's creation limit is reached. See Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/codes/{id}/image": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The code id.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getCodeImage",
        "summary": "Download the printable image of a code",
        "description": "A QR of the code's short link in its saved colours and dot style. Returns the image itself, not JSON.",
        "security": [
          {
            "bearerAuth": [
              "codes:read"
            ]
          },
          {
            "apiKeyHeader": [
              "codes:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "png",
                "svg"
              ],
              "default": "png"
            }
          },
          {
            "name": "size",
            "in": "query",
            "description": "Pixels; defaults to the saved size.",
            "schema": {
              "type": "integer",
              "minimum": 64,
              "maximum": 4096
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The image.",
            "content": {
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The request is malformed or fails validation. `details` may list each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope, or your plan does not include the feature.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such code, or it is not yours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests, or your plan's creation limit is reached. See Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/codes/{id}/scans": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The code id.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getCodeScans",
        "summary": "Scan statistics for a code",
        "description": "Totals are returned on every plan. The day-by-day breakdown needs the Advanced plan; on Free, `daily` is null. LinkScan does not record device, browser or location.",
        "security": [
          {
            "bearerAuth": [
              "codes:read"
            ]
          },
          {
            "apiKeyHeader": [
              "codes:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "description": "How many days of daily data to return.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 365,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Scan statistics.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scans"
                }
              }
            }
          },
          "400": {
            "description": "The request is malformed or fails validation. `details` may list each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope, or your plan does not include the feature.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such code, or it is not yours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests, or your plan's creation limit is reached. See Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/qr/generate": {
      "post": {
        "operationId": "generateQrCode",
        "summary": "Render a one-off static QR image",
        "security": [
          {
            "bearerAuth": [
              "qr:generate"
            ]
          },
          {
            "apiKeyHeader": [
              "qr:generate"
            ]
          }
        ],
        "description": "Encodes the content directly in the pattern. Nothing is saved, the result cannot be edited later and scans are not counted. Returns the image itself, not JSON. Limited to 60 requests per minute per API key.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateRequest"
              },
              "example": {
                "content": "https://example.com",
                "size": 512,
                "format": "png"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The QR code image.",
            "content": {
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The JSON body is missing, malformed or fails validation. `details` lists each problem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No API key was sent, or it is unknown, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The API key does not have the `qr:generate` scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests. See the X-RateLimit-* response headers.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "The image could not be generated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key created in Account → Settings. Keys start with `lsk_` and carry the scopes qr:generate, codes:read and codes:write."
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Alternative to the Authorization header."
      }
    },
    "schemas": {
      "GenerateRequest": {
        "type": "object",
        "required": [
          "content"
        ],
        "properties": {
          "content": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000,
            "description": "The data to encode: a URL, text, Wi-Fi string, vCard, and so on. Up to 2,000 characters."
          },
          "size": {
            "type": "integer",
            "minimum": 64,
            "maximum": 4096,
            "default": 512,
            "description": "Image width and height in pixels, 64 to 4096. Default 512."
          },
          "errorCorrection": {
            "type": "string",
            "enum": [
              "L",
              "M",
              "Q",
              "H"
            ],
            "default": "M",
            "description": "Error correction level: L, M, Q or H. Default M. Use H when adding a logo."
          },
          "foregroundColor": {
            "type": "string",
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "default": "#000000",
            "description": "Colour of the code as a hex value. Default #000000."
          },
          "backgroundColor": {
            "type": "string",
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "default": "#FFFFFF",
            "description": "Background colour as a hex value. Default #FFFFFF."
          },
          "qrStyle": {
            "type": "string",
            "enum": [
              "square",
              "dots",
              "rounded"
            ],
            "default": "square",
            "description": "Shape of the dots: square, dots or rounded. Default square."
          },
          "format": {
            "type": "string",
            "enum": [
              "png",
              "svg"
            ],
            "default": "png",
            "description": "Output format: png or svg. Default png."
          },
          "logoBase64": {
            "type": "string",
            "maxLength": 200000,
            "description": "Logo to place in the centre, as a base64 data URL (about 150 KB at most)."
          },
          "logoSizeRatio": {
            "type": "number",
            "minimum": 0.1,
            "maximum": 0.4,
            "default": 0.25,
            "description": "Logo size as a fraction of the code, 0.1 to 0.4. Default 0.25."
          }
        }
      },
      "CodeInput": {
        "type": "object",
        "properties": {
          "destination": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500,
            "description": "Where a scan should go: usually a URL (also tel:, mailto:, sms: or plain text). Up to 500 characters. Required when creating."
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50,
            "description": "A label for your own reference, up to 50 characters."
          },
          "style": {
            "$ref": "#/components/schemas/Style"
          },
          "projectId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Put the code in one of your projects. Omit or send null for none."
          },
          "customShortCode": {
            "type": "string",
            "minLength": 4,
            "maxLength": 30,
            "description": "Choose the short link (linkscan.org/s/your-name). Advanced plan only; 4-30 lowercase letters, digits or hyphens."
          }
        }
      },
      "Style": {
        "type": "object",
        "properties": {
          "size": {
            "type": "integer",
            "minimum": 64,
            "maximum": 4096,
            "default": 512
          },
          "errorCorrection": {
            "type": "string",
            "enum": [
              "L",
              "M",
              "Q",
              "H"
            ],
            "default": "M"
          },
          "foregroundColor": {
            "type": "string",
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "default": "#000000"
          },
          "backgroundColor": {
            "type": "string",
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "default": "#FFFFFF"
          },
          "qrStyle": {
            "type": "string",
            "enum": [
              "square",
              "dots",
              "rounded",
              "classy",
              "extra-rounded"
            ],
            "default": "square"
          },
          "hasLogo": {
            "type": "boolean",
            "readOnly": true,
            "description": "Whether a logo was added in the dashboard."
          }
        }
      },
      "Code": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "destination": {
            "type": "string",
            "description": "Where a scan currently goes."
          },
          "shortCode": {
            "type": "string"
          },
          "shortUrl": {
            "type": "string",
            "format": "uri",
            "description": "The link encoded in the printed code."
          },
          "isCustomShortCode": {
            "type": "boolean"
          },
          "isActive": {
            "type": "boolean",
            "description": "False if LinkScan has disabled the code; it then stops redirecting."
          },
          "projectId": {
            "type": [
              "string",
              "null"
            ]
          },
          "style": {
            "$ref": "#/components/schemas/Style"
          },
          "scans": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer",
                "description": "All scans."
              },
              "unique": {
                "type": "integer",
                "description": "Unique visitors, counted per day."
              }
            }
          },
          "imageUrl": {
            "type": "string",
            "format": "uri",
            "description": "Fetch with your API key to download the printable image."
          },
          "lastScannedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Scans": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "unique": {
            "type": "integer"
          },
          "lastScannedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "days": {
            "type": "integer"
          },
          "daily": {
            "type": [
              "array",
              "null"
            ],
            "description": "One entry per day with scans, oldest first. Null on the Free plan.",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date"
                },
                "scans": {
                  "type": "integer"
                },
                "uniqueVisitors": {
                  "type": "integer"
                }
              }
            }
          },
          "note": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "details": {
            "description": "A list of validation messages, or a single message.",
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "string"
              }
            ]
          }
        }
      }
    }
  }
}