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 |
|---|---|---|---|
data | string | yes | Content to encode (URL, text, vCard, WiFi, etc.) |
size | integer | no | Image size in pixels: 50-2000 (default: 300) |
format | string | no | Output format: png, svg (default: png) |
error_correction | string | no | L (7%), M (15%), Q (25%), H (30%) — default: M |
margin | integer | no | Quiet zone margin: 0-10 (default: 2) |
foreground_color | string | no | Hex color for dark modules (default: #000000) |
background_color | string | no | Hex color for light modules (default: #FFFFFF) |
response_type | string | no | image (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 |
|---|---|---|
| 401 | MISSING_API_KEY | No API key provided |
| 422 | VALIDATION_ERROR | Invalid parameters |
| 500 | QR_GENERATION_FAILED | Data too long or encoding error |