API Documentation

POST /api/generate
Generate QR Code

Generate a QR code with custom content, size, colors, and error correction level.

Request Parameters
Parameter Type Description Required
content string The content to encode in the QR code. Can be text, URL, or formatted data (vCard, WiFi, etc.) Yes
size integer Size of the QR code in pixels (100-1000) No (default: 300)
margin integer White space margin around the QR code (0-50) No (default: 25)
foregroundColor string Hex color code for QR code foreground (#000000-#FFFFFF) No (default: #000000)
backgroundColor string Hex color code for QR code background (#000000-#FFFFFF) No (default: #FFFFFF)
errorCorrection string Error correction level (L, M, Q, H) No (default: M)
Error Correction Levels
Low (L)

7% Recovery

Medium (M)

15% Recovery

Quartile (Q)

25% Recovery

High (H)

30% Recovery

Example Request
curl -X POST https://qr.nifty.app/api/generate \
    -H "Content-Type: application/json" \
    -d '{
        "content": "https://example.com",
        "size": 300,
        "margin": 25,
        "foregroundColor": "#000000",
        "backgroundColor": "#FFFFFF",
        "errorCorrection": "M"
    }'

Error Correction Levels

  • L - Low (7% recovery)
  • M - Medium (15% recovery)
  • Q - Quartile (25% recovery)
  • H - High (30% recovery)

Response

{
    "success": true,
    "image": "string"          // Base64 encoded PNG image with data URI scheme
}
Success Response
{
    "success": true,
    "image": "data:image/png;base64,..."  // Base64 encoded image with data URI
}
Error Response
{
    "error": "Error message description"
}
Code Examples
Basic URL QR Code
$ch = curl_init('https://qr.nifty.app/api/generate');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode([
        'content' => 'https://example.com'
    ])
]);

$response = curl_exec($ch);
$result = json_decode($response, true);

if ($result['success']) {
    $qrCode = $result['image']; // Base64 encoded image
}
WiFi Configuration
$data = [
    'content' => 'WIFI:T:WPA;S:NetworkName;P:Password;;'
];

$ch = curl_init('https://qr.nifty.app/api/generate');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode($data)
]);

$response = curl_exec($ch);
$result = json_decode($response, true);
vCard Contact
$vcard = implode("\n", [
    'BEGIN:VCARD',
    'VERSION:3.0',
    'FN:John Doe',
    'TEL:+1234567890',
    'EMAIL:john@example.com',
    'END:VCARD'
]);

$data = ['content' => $vcard];

$ch = curl_init('https://qr.nifty.app/api/generate');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode($data)
]);

$response = curl_exec($ch);
$result = json_decode($response, true);
Styled QR Code
$data = [
    'content' => 'https://example.com',
    'size' => 400,
    'margin' => 25,
    'foregroundColor' => '#0984e3',
    'backgroundColor' => '#f5f7fa',
    'errorCorrection' => 'H'
];

$ch = curl_init('https://qr.nifty.app/api/generate');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode($data)
]);

$response = curl_exec($ch);
$result = json_decode($response, true);

if ($result['success']) {
    // Save as file
    $imageData = base64_decode(explode(',', $result['image'])[1]);
    file_put_contents('qrcode.png', $imageData);
}