Appearance
Generate QR Code
Generate a QR code from any text, URL, or data.
Endpoint
GET /api/generateAuthentication
Requires API key via Authorization header, X-API-Key header, or api_key query parameter.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
data | string | ✅ | - | Content to encode. Max 2,953 characters. |
size | number | - | 300 | Image size in pixels. Range: 50-2000. |
format | string | - | png | Output format: png or svg. |
color | string | - | 000000 | QR code color (hex, without #). |
background | string | - | ffffff | Background color (hex, without #). |
errorCorrection | string | - | M | Error correction: L, M, Q, or H. |
margin | number | - | 4 | Quiet zone margin in modules. Range: 0-10. |
logo | string | - | - | URL to logo image (Pro plan). |
logoSize | number | - | 20 | Logo size as percentage of QR code. |
Response
Returns the QR code image directly with appropriate Content-Type:
image/pngfor PNG formatimage/svg+xmlfor SVG format
Examples
Basic QR Code
bash
curl "https://www.qrcodeapi.io/api/generate?data=https://example.com" \
-H "Authorization: Bearer YOUR_API_KEY" \
-o qr.pngCustom Colors
bash
curl "https://www.qrcodeapi.io/api/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G \
--data-urlencode "data=https://example.com" \
--data "color=4F46E5" \
--data "background=F3F4F6" \
-o purple-qr.pngSVG Output
bash
curl "https://www.qrcodeapi.io/api/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G \
--data-urlencode "data=https://example.com" \
--data "format=svg" \
-o qr.svgLarge Size with High Error Correction
bash
curl "https://www.qrcodeapi.io/api/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G \
--data-urlencode "data=https://example.com" \
--data "size=1000" \
--data "errorCorrection=H" \
-o large-qr.pngWith Logo Overlay (Pro Plan)
bash
curl "https://www.qrcodeapi.io/api/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G \
--data-urlencode "data=https://example.com" \
--data-urlencode "logo=https://example.com/logo.png" \
--data "logoSize=25" \
--data "errorCorrection=H" \
-o branded-qr.pngLogo Best Practices
When using logo overlay, always set errorCorrection=H to ensure the QR code remains scannable even with the logo covering part of the code.
Error Correction Levels
| Level | Recovery | Use Case |
|---|---|---|
L | ~7% | High density data, clean environment |
M | ~15% | Standard use (default) |
Q | ~25% | Outdoor use, some damage expected |
H | ~30% | Logo overlay, harsh conditions |
Code Examples
JavaScript
javascript
async function generateQR(data, options = {}) {
const params = new URLSearchParams({
data,
size: options.size || 300,
format: options.format || 'png',
color: options.color || '000000',
background: options.background || 'ffffff',
errorCorrection: options.errorCorrection || 'M'
});
const response = await fetch(
`https://www.qrcodeapi.io/api/generate?${params}`,
{
headers: {
'Authorization': `Bearer ${API_KEY}`
}
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.message);
}
return response.blob();
}
// Usage
const qrBlob = await generateQR('https://example.com', {
size: 500,
color: '22c55e'
});Python
python
import requests
def generate_qr(data, **options):
params = {
'data': data,
'size': options.get('size', 300),
'format': options.get('format', 'png'),
'color': options.get('color', '000000'),
'background': options.get('background', 'ffffff'),
'errorCorrection': options.get('error_correction', 'M')
}
response = requests.get(
'https://www.qrcodeapi.io/api/generate',
params=params,
headers={'Authorization': f'Bearer {API_KEY}'}
)
response.raise_for_status()
return response.content
# Usage
qr_image = generate_qr('https://example.com', size=500, color='22c55e')
with open('qr.png', 'wb') as f:
f.write(qr_image)PHP
php
<?php
function generateQR($data, $options = []) {
$params = http_build_query([
'data' => $data,
'size' => $options['size'] ?? 300,
'format' => $options['format'] ?? 'png',
'color' => $options['color'] ?? '000000',
'background' => $options['background'] ?? 'ffffff',
'errorCorrection' => $options['errorCorrection'] ?? 'M'
]);
$context = stream_context_create([
'http' => [
'header' => "Authorization: Bearer " . API_KEY
]
]);
return file_get_contents(
"https://www.qrcodeapi.io/api/generate?{$params}",
false,
$context
);
}
// Usage
$qr = generateQR('https://example.com', ['size' => 500]);
file_put_contents('qr.png', $qr);
?>Error Responses
| Status | Message | Description |
|---|---|---|
| 400 | data parameter required | Missing required data parameter |
| 400 | Invalid size | Size not in range 50-2000 |
| 400 | Invalid format | Format not png or svg |
| 401 | Invalid API key | Authentication failed |
| 429 | Rate limit exceeded | Too many requests |
See Error Codes for complete error documentation.
Related
- Dynamic Links - Editable QR code URLs
- Batch Generation - Generate multiple QR codes
- Custom Styling - Design tips