{"openapi":"3.1.0","info":{"title":"BetterQR API","version":"1.0.0"},"components":{"securitySchemes":{"apiKey":{"type":"apiKey","in":"header","name":"x-api-key","description":"Organization API key. Create one in Dashboard → Settings → API keys. Secret keys (`bqr_…`) are for your servers and reach `/v1/qr-codes`. App (publishable) keys (`bqr_pk_…`) are safe to ship in a mobile app and reach only `/v1/app/*`."}},"schemas":{"ApiRoot":{"type":"object","properties":{"name":{"type":"string"},"version":{"type":"string"},"documentation":{"type":"string"},"openapi":{"type":"string"}},"required":["name","version","documentation","openapi"]},"Health":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail"]},"version":{"type":"string"},"checks":{"type":"object","properties":{"database":{"type":"string","enum":["pass","fail"]}},"required":["database"]}},"required":["status","version","checks"]},"QrCode":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"slug":{"type":"string"},"type":{"type":"string"},"isDynamic":{"type":"boolean"},"isActive":{"type":"boolean"},"tags":{"type":"array","items":{"type":"string"}},"content":{"nullable":true},"shortUrl":{"type":"string","nullable":true},"imageUrl":{"type":"string"},"createdAt":{"type":"string"},"updatedAt":{"type":"string"}},"required":["id","name","slug","type","isDynamic","isActive","tags","shortUrl","imageUrl","createdAt","updatedAt"]},"Error":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"},"issues":{"type":"array","items":{"type":"object","properties":{"path":{"type":"string"},"message":{"type":"string"}},"required":["path","message"]}}},"required":["code","message"]}},"required":["error"]},"AppOpenResponse":{"type":"object","properties":{"match":{"type":"string","enum":["exact","probable","organic"],"description":"`exact`: matched by the scan ID in the Play referrer or clipboard. `probable`: matched by a scan on the same network in the last hour (only when your organization turned the network fallback on). `organic`: no QR code credited."},"installId":{"type":"string"},"sid":{"type":"string","nullable":true,"description":"The credited scan's ID, or null for organic installs."},"qrCode":{"type":"object","nullable":true,"properties":{"id":{"type":"string"},"name":{"type":"string"},"slug":{"type":"string"},"tags":{"type":"array","items":{"type":"string"}}},"required":["id","name","slug","tags"]},"campaign":{"type":"object","nullable":true,"properties":{"id":{"type":"string"},"name":{"type":"string"},"slug":{"type":"string"}},"required":["id","name","slug"]}},"required":["match","installId","sid","qrCode","campaign"]},"AppOpenRequest":{"type":"object","properties":{"installId":{"type":"string","minLength":1,"maxLength":128,"description":"A stable, per-install ID your app already has: `identifierForVendor` on iOS, the app set ID on Android, or a UUID you generate once and persist. Never an email or advertising ID.","example":"6F9619FF-8B86-D011-B42D-00CF4FC964FF"},"platform":{"type":"string","enum":["ios","android"]},"installReferrer":{"type":"string","maxLength":2048,"description":"Android only. The raw install referrer string from the Play Install Referrer API, sent as-is.","example":"utm_source=poster&bqr_sid=01JBQRZ4X8M2N6P0R3S5T7V9WY"},"clipboardUrl":{"type":"string","maxLength":2048,"description":"iOS only. The URL on the clipboard at first open, if it is a BetterQR scan link. Only read it when the clipboard holds a URL (`UIPasteboard.hasURLs`).","example":"https://betterqr.app/q/jane?sid=01JBQRZ4X8M2N6P0R3S5T7V9WY"},"osVersion":{"type":"string","maxLength":32,"description":"OS version, e.g. `17.5`. Used by the network fallback.","example":"17.5"},"language":{"type":"string","maxLength":35,"description":"BCP 47 device language. Used by the network fallback.","example":"en-GB"},"timezone":{"type":"string","maxLength":64,"description":"IANA time zone. Used by the network fallback.","example":"Europe/London"}},"required":["installId","platform"]},"AppEvent":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"installId":{"type":"string"},"match":{"type":"string","enum":["exact","probable","organic"],"description":"`exact`: matched by the scan ID in the Play referrer or clipboard. `probable`: matched by a scan on the same network in the last hour (only when your organization turned the network fallback on). `organic`: no QR code credited."},"qrCodeId":{"type":"string","nullable":true},"createdAt":{"type":"string"}},"required":["id","name","installId","match","qrCodeId","createdAt"]},"AppEventRequest":{"type":"object","properties":{"installId":{"type":"string","minLength":1,"maxLength":128,"description":"A stable, per-install ID your app already has: `identifierForVendor` on iOS, the app set ID on Android, or a UUID you generate once and persist. Never an email or advertising ID.","example":"6F9619FF-8B86-D011-B42D-00CF4FC964FF"},"name":{"type":"string","pattern":"^[a-z][a-z0-9_]{0,39}$","description":"Event name: lowercase letters, digits and underscores, starting with a letter (max 40).","example":"signup"},"externalId":{"type":"string","minLength":1,"maxLength":128,"description":"Optional opaque ID from your system, e.g. your user ID. Never an email, name or phone number.","example":"user_8f3a2c"}},"required":["installId","name"]}},"parameters":{}},"paths":{"/":{"get":{"summary":"API root","description":"Service metadata and discovery links to the interactive docs and OpenAPI spec.","responses":{"200":{"description":"Service metadata","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiRoot"}}}}}}},"/health":{"get":{"summary":"Health check","description":"Liveness/readiness probe. Returns `pass` (HTTP 200) when the API and its database are reachable, `fail` (HTTP 503) otherwise.","responses":{"200":{"description":"Service healthy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Health"}}}},"503":{"description":"Service unhealthy (a dependency check failed)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Health"}}}}}}},"/v1/qr-codes":{"get":{"summary":"List QR codes","description":"Lists your organization's QR codes, newest first. Paginate with `cursor` (the `id` of the last item of the previous page).","security":[{"apiKey":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"maximum":100,"default":50},"required":false,"name":"limit","in":"query"},{"schema":{"type":"string"},"required":false,"name":"cursor","in":"query"}],"responses":{"200":{"description":"QR codes","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/QrCode"}},"nextCursor":{"type":"string","nullable":true}},"required":["data","nextCursor"]}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Insufficient scope or plan","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"post":{"summary":"Create a QR code","description":"Creates a URL QR code. Dynamic QR codes redirect through BetterQR (`shortUrl`) so the target stays editable; static codes encode the URL directly.","security":[{"apiKey":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":100},"url":{"type":"string","minLength":1,"maxLength":2048},"isDynamic":{"type":"boolean","default":false},"tags":{"type":"array","items":{"type":"string","minLength":1,"maxLength":50},"maxItems":10,"default":[]},"design":{"type":"object","properties":{"fgColor":{"type":"string","pattern":"^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"},"moduleShape":{"type":"string","enum":["square","dots","rounded"]},"eyeShape":{"type":"string","enum":["square","rounded","dots"]},"cornerRadius":{"type":"number","minimum":0,"maximum":100},"errorCorrection":{"type":"string","enum":["L","M","Q","H"]},"logoUrl":{"type":"string","nullable":true,"maxLength":1500000},"frameText":{"type":"string","nullable":true}},"required":["fgColor","moduleShape","eyeShape","cornerRadius"]}},"required":["name","url"]}}}},"responses":{"201":{"description":"Created QR code","content":{"application/json":{"schema":{"$ref":"#/components/schemas/QrCode"}}}},"400":{"description":"Invalid input","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Insufficient scope or plan","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/qr-codes/{id}":{"get":{"summary":"Get a QR code","security":[{"apiKey":[]}],"parameters":[{"schema":{"type":"string","minLength":1},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"QR code","content":{"application/json":{"schema":{"$ref":"#/components/schemas/QrCode"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Insufficient scope or plan","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"patch":{"summary":"Update a QR code","description":"Updates name, target url (URL-type codes), active state, or design. Updating the url of a dynamic QR code changes where existing prints redirect; passing `design` replaces the stored styling.","security":[{"apiKey":[]}],"parameters":[{"schema":{"type":"string","minLength":1},"required":true,"name":"id","in":"path"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":100},"url":{"type":"string","minLength":1,"maxLength":2048},"isActive":{"type":"boolean"},"design":{"type":"object","properties":{"fgColor":{"type":"string","pattern":"^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"},"moduleShape":{"type":"string","enum":["square","dots","rounded"]},"eyeShape":{"type":"string","enum":["square","rounded","dots"]},"cornerRadius":{"type":"number","minimum":0,"maximum":100},"errorCorrection":{"type":"string","enum":["L","M","Q","H"]},"logoUrl":{"type":"string","nullable":true,"maxLength":1500000},"frameText":{"type":"string","nullable":true}},"required":["fgColor","moduleShape","eyeShape","cornerRadius"]}}}}}},"responses":{"200":{"description":"Updated QR code","content":{"application/json":{"schema":{"$ref":"#/components/schemas/QrCode"}}}},"400":{"description":"Invalid input","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Insufficient scope or plan","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/app/open":{"post":{"tags":["App attribution"],"summary":"Report an app's first open","description":"Call once on your app's first launch with an **App (publishable) key**. BetterQR tells you which QR code, if any, led to the install.\n\n**Matching order**\n1. A scan ID (`sid`) in `installReferrer` (Android) or `clipboardUrl` (iOS) → `exact`. Each scan credits one install only.\n2. Otherwise, if your organization turned on the network fallback: the latest scan of one of your QR codes from the same network in the last hour, same platform and OS major version, ranked by language and time zone → `probable`. If the best scans came from different QR codes, nobody is credited.\n3. Otherwise → `organic`.\n\n**Idempotent** on `installId`: calling again for the same install returns the first answer, so it is safe to retry.\n\nDon't send an IP address. BetterQR hashes the request's IP on the server and never stores it raw.","security":[{"apiKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppOpenRequest"}}}},"responses":{"200":{"description":"Attribution result","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppOpenResponse"}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Not an app key (missing app:track), inactive organization, or plan without API access","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded (per key and per client IP)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/app/event":{"post":{"tags":["App attribution"],"summary":"Report a conversion for an install","description":"Records a downstream event, such as `signup`, for an install you already reported with `POST /v1/app/open`. Use an **App (publishable) key**.\n\nThe first event of each name per install is kept. Sending it again returns the original event with HTTP 200, so retries are safe. An install can have up to 20 different event names.","security":[{"apiKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppEventRequest"}}}},"responses":{"200":{"description":"Already recorded; the original event","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppEvent"}}}},"201":{"description":"Event recorded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppEvent"}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Not an app key (missing app:track), inactive organization, or plan without API access","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No install with this installId","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"This install already has the maximum number of event names","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded (per key and per client IP)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}