Skip to content
APIs Pricing Docs Guides Log in Start free

QR Code quickstart

You need an API key whose role includes qrcode.generate (the default Developer role does).

cURL

curl -X POST https://webknx.com/api/v1/qrcode \
  -H "Authorization: Bearer $WEBKNX_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data":"https://example.com","size":512,"error_correction":"high"}' \
  --output qrcode.png

Node.js

import { writeFile } from "node:fs/promises";

const res = await fetch("https://webknx.com/api/v1/qrcode", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBKNX_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ data: "https://example.com", size: 512 }),
});

if (!res.ok) {
  const { error } = await res.json();
  throw new Error(`${error.code}: ${error.message} (${error.request_id})`);
}
await writeFile("qrcode.png", Buffer.from(await res.arrayBuffer()));

Python

import os, requests

res = requests.post(
    "https://webknx.com/api/v1/qrcode",
    headers={"Authorization": f"Bearer {os.environ['WEBKNX_SECRET_KEY']}"},
    json={"data": "https://example.com", "size": 512},
    timeout=15,
)
if res.status_code != 200:
    raise RuntimeError(res.json()["error"])
open("qrcode.png", "wb").write(res.content)