Get a branded QR code for a link
method
GET
host
strait.
version
/v1
resource
/
GET /v1/links/{slug}/qr
Auth: secret key as Authorization: Bearer. Server-side only.
Request
A print-ready QR code (PNG or SVG) that opens the link's short URL. It uses the workspace's QR style (Dashboard → Settings → QR codes: colour, background, app icon in the middle); query parameters override it for this one code. By default the code adds utm_source=qr, so scans show as the qr channel in analytics (an existing utm_source on the link is kept). The code must be darker than its background with a contrast of at least 3:1, or the request is refused with 400. With a logo the code uses error correction H. The logo is the app icon from Settings: PNG, JPEG or WebP in SVG codes, PNG only in PNG codes; X-Strait-Qr-Logo says whether it was embedded. Rate limit: 60 codes a minute per workspace; PNG renders also share a server-wide budget (large PNGs may get 429, retry or use SVG).
Parameters
slugrequired string path- The link's slug: the part after your link domain, e.g.
summer format"png" | "svg" query- Image format
sizeinteger query- Width and height in pixels
margininteger query- Quiet zone around the code, in modules
colorstring query- Code colour as hex (
1f2937, or%231f2937). Default: the workspace's QR colour, else black. backgroundstring query- Background colour as hex. Default: the workspace's QR background, else white.
logoboolean query- Put the app icon in the middle. Default: the workspace's QR setting.
presetstring query- Start from a saved QR style (Settings → QR codes) instead of the workspace default; color, background and logo still override it. Unknown id: 400.
trackboolean query- Add utm_source=qr so scans count as the qr channel
downloadboolean query- true: Content-Disposition attachment (a browser saves the file)
tenantIdstring query- Dashboard sessions only: the workspace id (a secret key already names its workspace)
Response
- 200 The QR code
- 400 Invalid parameter, or colours that would not scan (code lighter than the background, or contrast under 3:1)
- 401 Missing or invalid secret key / session
- 404 No active link with this slug in the workspace
- 429 More than 60 codes a minute for this workspace (Retry-After: 1), or PNG rendering is busy server-wide (Retry-After: 2; SVG is not limited by it)
curl -X GET "https://strait.link/v1/links/summer/qr?format=png&size=1024" \
-H "Authorization: Bearer $SECRET_KEY" \
--fail -o summer-qr.pngimport { writeFile } from 'node:fs/promises';
const res = await fetch('https://strait.link/v1/links/summer/qr?format=png&size=1024', {
headers: { Authorization: `Bearer ${process.env.SECRET_KEY}` },
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
await writeFile('summer-qr.png', Buffer.from(await res.arrayBuffer()));
console.log(res.status, res.headers.get('x-strait-qr-url'));import os
import requests
res = requests.get(
"https://strait.link/v1/links/summer/qr?format=png&size=1024",
headers={"Authorization": f"Bearer {os.environ['SECRET_KEY']}"},
)
res.raise_for_status()
with open("summer-qr.png", "wb") as f:
f.write(res.content)
print(res.status_code, res.headers.get("X-Strait-Qr-Url"))<?php
// Plain PHP with ext-curl, no packages. In Laravel, Http::withToken($secretKey)->get($url) sends the same request.
$ch = curl_init('https://strait.link/v1/links/summer/qr?format=png&size=1024');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SECRET_KEY'),
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status !== 200) {
throw new RuntimeException("HTTP $status: $response");
}
file_put_contents('summer-qr.png', $response);
echo $status, PHP_EOL;import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
// Java 17+, java.net.http only (no dependencies).
public class Main {
public static void main(String[] args) throws Exception {
HttpRequest request = HttpRequest.newBuilder(URI.create("https://strait.link/v1/links/summer/qr?format=png&size=1024"))
.header("Authorization", "Bearer " + System.getenv("SECRET_KEY"))
.GET()
.build();
// Saves the body to summer-qr.png; check the status before using the file.
HttpResponse<Path> res = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofFile(Path.of("summer-qr.png")));
System.out.println(res.statusCode() + " " + res.headers().firstValue("X-Strait-Qr-Url").orElse(""));
}
}package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
req, err := http.NewRequest(http.MethodGet, "https://strait.link/v1/links/summer/qr?format=png&size=1024", nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SECRET_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
msg, _ := io.ReadAll(res.Body)
log.Fatalf("HTTP %d: %s", res.StatusCode, msg)
}
out, err := os.Create("summer-qr.png")
if err != nil {
log.Fatal(err)
}
defer out.Close()
if _, err := io.Copy(out, res.Body); err != nil {
log.Fatal(err)
}
fmt.Println(res.StatusCode, res.Header.Get("X-Strait-Qr-Url"))
}The response, printed
HTTP/1.1 200 OK
Content-Type: image/png
Content-Disposition: inline; filename="summer-qr.png"
X-Strait-Qr-Url: https://hilltop.strait.link/summer?utm_source=qr
X-Strait-Qr-Logo: offHTTP/1.1 200 OK
Content-Type: image/svg+xml
Content-Disposition: inline; filename="summer-qr.svg"
X-Strait-Qr-Url: https://hilltop.strait.link/summer?utm_source=qr
X-Strait-Qr-Logo: off<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 37 37" shape-rendering="crispEdges"><rect width="37" height="37" fill="#ffffff"/><path fill="#1f2937" d="M2 2h7v1h-7z…"/></svg>