QR Code API Documentation

Complete reference for the QR Code Generator API

Authentication

All API requests require an API key. You can pass it in three ways:

Authorization: Bearer sk_live_your_key_here
X-API-Key: sk_live_your_key_here
Query: ?api_key=sk_live_your_key_here

GET POST /v1/qr/generate

Generate a QR code. By default returns the image binary directly. Set response_type=json to get base64-encoded data instead.

Parameters

Field Type Required Description
datastringyesContent to encode (URL, text, vCard, WiFi, etc.)
sizeintegernoImage size in pixels: 50-2000 (default: 300)
formatstringnoOutput format: png, svg (default: png)
error_correctionstringnoL (7%), M (15%), Q (25%), H (30%) — default: M
marginintegernoQuiet zone margin: 0-10 (default: 2)
foreground_colorstringnoHex color for dark modules (default: #000000)
background_colorstringnoHex color for light modules (default: #FFFFFF)
response_typestringnoimage (binary) or json (base64) — default: image

Example: Get image directly

curl "https://snapapis.com/api/v1/qr/generate?api_key=sk_live_abc123&data=https://example.com&size=400" \ --output qrcode.png

Example: Get JSON with base64

curl "https://snapapis.com/api/v1/qr/generate?api_key=sk_live_abc123&data=Hello&response_type=json"

JSON Response (response_type=json)

{
  "success": true,
  "data": {
    "format": "png",
    "size": 300,
    "file_size": 1842,
    "duration_ms": 12,
    "mime_type": "image/png",
    "image_base64": "iVBORw0KGgo..."
  }
}

Code Examples

JavaScript (fetch)

const response = await fetch(
  `https://snapapis.com/api/v1/qr/generate?api_key=${API_KEY}&data=${encodeURIComponent(url)}&size=400`
);
const blob = await response.blob();
const imgUrl = URL.createObjectURL(blob);

Python (requests)

import requests

response = requests.get(
    'https://snapapis.com/api/v1/qr/generate',
    params={
        'api_key': API_KEY,
        'data': 'https://example.com',
        'size': 400,
        'foreground_color': '#6D28D9',
    }
)

with open('qrcode.png', 'wb') as f:
    f.write(response.content)

HTML (inline image)

<!-- Direct image URL -->
<img src="https://snapapis.com/api/v1/qr/generate?api_key=YOUR_KEY&data=https://example.com" />

Error Codes

HTTP Code Description
401MISSING_API_KEYNo API key provided
422VALIDATION_ERRORInvalid parameters
500QR_GENERATION_FAILEDData too long or encoding error