Frequently Asked Question
QR Code API
Overview
The QR Code API generates QR codes in various formats (PNG, SVG, HTML) with customizable colors, sizes, error correction levels, and optional logo overlay. It supports encoding URLs, text, vCards, WiFi configurations, and any other data up to 2KB.
Version
1.004
Endpoint
/v2/qr
Authentication
This API requires authentication using an API key. The key should be passed in the X-API-Key header.
Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| data | string | Yes* | - | Raw content to encode in QR code (max 2048 chars). Use for simple text without special URL characters. |
| data64 | string | Yes* | - | Base64 encoded content (max 4096 chars). Use for URLs with query strings or special characters. Takes priority over data if both provided. |
| format | string | No | png | Output format: png (base64), svg, html |
| size | int | No | 3 | Module size in pixels (1-20). Each QR "square" will be this many pixels. Ignored if width is specified. |
| width | int | No | - | Target image width in pixels (50-2000). Overrides size calculation for precise output dimensions. |
| ecl | string | No | L | Error correction level: L (7%), M (15%), Q (25%), H (30%). Higher = more redundancy, larger QR code. |
| color | string | No | 000000 | Foreground color as 6-digit hex (e.g., FF0000 for red) |
| bgcolor | string | No | FFFFFF | Background color as 6-digit hex (e.g., FFFF00 for yellow) |
| invert | int | No | 0 | Swap foreground and background colors: 0 = normal, 1 = inverted |
| logo | string | No | - | Base64 encoded logo image (PNG, JPG, GIF) to overlay in center. Supports URL-safe base64. |
| logo_size | int | No | 20 | Percentage of QR code that logo covers (10-30). Larger logos reduce scanability. |
* Either data or data64 must be provided.
Response
The API returns a JSON object with the following structure:
| Field | Type | Description |
|---|---|---|
| status | string | "success" or error message starting with HTTP code |
| format | string | Output format used: "base64", "svg", or "html" |
| mimetype | string | MIME type: "image/png", "image/svg+xml", or "text/html" |
| data | string | The QR code data (base64 for PNG, raw for SVG/HTML) |
| datauri | string | Complete data URI for PNG format (ready for img src) |
| dimensions | object | Size information: modules, width, height |
| logo_applied | boolean | Whether logo was successfully overlaid (only if logo provided) |
| logo_error | string | Error message if logo overlay failed |
Example: Simple Text QR Code
Request:
GET /v2/qr?data=Hello+World&format=png&width=200 Response:
{
"status": "success",
"format": "base64",
"mimetype": "image/png",
"data": "iVBORw0KGgoAAAANS...",
"datauri": "data:image/png;base64,iVBORw0KGgoAAAANS...",
"dimensions": {
"modules": 21,
"width": 200,
"height": 200
}
} Example: URL with Query String (using data64)
When encoding URLs with & or = characters, use base64 encoding:
Original URL: https://example.com/page?id=123&ref=456
Base64 encoded: aHR0cHM6Ly9leGFtcGxlLmNvbS9wYWdlP2lkPTEyMyZyZWY9NDU2
GET /v2/qr?data64=aHR0cHM6Ly9leGFtcGxlLmNvbS9wYWdlP2lkPTEyMyZyZWY9NDU2&format=png&width=300 PHP example:
$url = "https://example.com/page?id=123&ref=456";
$data64 = base64_encode($url);
$apiUrl = "https://api.example.com/v2/qr?data64=" . urlencode($data64) . "&format=png"; Example: Custom Colors
GET /v2/qr?data=ColorfulQR&format=png&width=200&color=0066CC&bgcolor=FFFFCC Creates a blue QR code on a light yellow background.
Example: Inverted Colors
GET /v2/qr?data=InvertedQR&format=png&width=200&invert=1 Creates a white QR code on a black background (or swaps custom colors if specified).
Example: QR Code with Logo
Add a centered logo overlay for branding. The API automatically upgrades to high error correction (H) when a logo is provided.
GET /v2/qr?data=https://example.com&format=png&width=300&logo=iVBORw0KGgo...&logo_size=20 Important notes for logos:
- Logo should be base64 encoded (PNG, JPG, or GIF)
- URL-safe base64 is supported (
-and_instead of+and/) - Keep logo_size at 20% or less for reliable scanning
- Simple, high-contrast logos work best
- Error correction is automatically set to H (30%) when logo is used
PHP example with logo:
$logoData = base64_encode(file_get_contents('logo.png'));
$url = "https://api.example.com/v2/qr?data=https://mysite.com&width=300&logo=" . urlencode($logoData) . "&logo_size=15"; Example: SVG Output
GET /v2/qr?data=VectorQR&format=svg&size=5&color=333333 Response:
{
"status": "success",
"format": "svg",
"mimetype": "image/svg+xml",
"data": "..."
} Example: HTML Output
GET /v2/qr?data=HTMLQR&format=html&size=3 Returns div-based HTML that can be embedded directly in web pages.
Error Correction Levels
| Level | Recovery | Use Case |
|---|---|---|
| L | ~7% | Default. Best for clean display environments. |
| M | ~15% | Good balance of size and error tolerance. |
| Q | ~25% | Higher reliability for printed codes. |
| H | ~30% | Maximum reliability. Required for logo overlay. |
Error Handling
- Missing data:
{"status": "400 : Missing required parameter 'data'"} - Invalid base64 in data64: Falls back to raw
dataparameter - Generation failure:
{"status": "500 : Failed to generate QR code"} - PNG generation without GD:
{"status": "500 : PNG generation failed - GD or Imagick library required"} - Logo overlay failure: Returns QR without logo plus
logo_applied: falseandlogo_errorwith details
Notes
- QR codes are always square (width = height).
- PNG format requires the GD library to be installed on the server.
- SVG and HTML formats work without any image libraries.
- The
dataurifield can be used directly in antag. - For WiFi QR codes, use format:
WIFI:T:WPA;S:NetworkName;P:Password;; - For vCards, use standard vCard 3.0 or 4.0 format.
- Maximum data capacity depends on error correction level and content type.
Security
- Ensure that the API key is kept secure and not exposed in client-side code.
- All responses are sent with the "Content-Type: application/json" header.
- Logo images are validated as proper image formats before processing.
- Input data is sanitized to prevent injection attacks.
