QR Code API
Endpoints for generating and decoding custom QR Codes.
GET/api/qr-code/generate/{apiKey}/{text}
A simple endpoint to quickly generate a QR code for any text or URL. Returns a PNG image directly.
Example Request
# Embed directly in HTML:
<img src="https://codingmantra.com/api/qr-code/generate/YOUR_API_KEY/hello%20world" alt="QR Code" />
# Or use with curl:
curl -X GET 'https://codingmantra.com/api/qr-code/generate/YOUR_API_KEY/hello%20world' -o qr.png
Example Response
The API returns a direct `image/png` response, not JSON.
GET/api/qr-code/generate-base64/{apiKey}/{text}
A simple endpoint to quickly generate a QR code for any text or URL. Returns a JSON object containing a Base64 data URI of the PNG image.
Example Request
curl -X GET 'https://codingmantra.com/api/qr-code/generate-base64/YOUR_API_KEY/hello%20world' \
-H 'Authorization: Bearer YOUR_API_KEY'
Example Response
{
"data": {
"qrCodeDataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
}
POST/api/qr-code/generate
Generate a custom QR code for various data types like URLs, text, Wi-Fi credentials, and more. Requires authentication. The response will be a JSON object containing a Base64 data URI of the generated PNG image.
Request Body
The request body must include a `type` field which determines the other required fields. Below are the schemas for each type.
Shared Design Parameters (Optional)
Field | Type | Description |
---|---|---|
size | number | Size of the QR code in pixels (e.g., 512). Default: 512. |
fgColor | string | Foreground color in hex format (e.g., "#0A66C2"). Default: #000000. |
bgColor | string | Background color in hex format. Default: #FFFFFF. |
logoUrl | string | URL of a logo to embed in the center. |
logoSizeRatio | number | Ratio of the logo size to the QR code size (0.1 to 0.4). Default: 0.2. |
isTransparent | boolean | If true, background will be transparent. Default: false. |
Type: `url`
Field | Type | Description |
---|---|---|
value | string | The URL to encode (e.g., "https://codingmantra.com"). |
Type: `text`
Field | Type | Description |
---|---|---|
value | string | The plain text to encode. |
Type: `wifi`
Field | Type | Description |
---|---|---|
ssid | string | The name of the Wi-Fi network. |
password | string | The network password. |
encryption | string | Encryption type: 'WPA', 'WEP', or 'nopass'. |
Type: `email`
Field | Type | Description |
---|---|---|
to | string | Recipient email address. |
subject | string | Email subject. (Optional) |
body | string | Email body. (Optional) |
Type: `vcard`
Field | Type | Description |
---|---|---|
firstName | string | First name. |
lastName | string | Last name. |
organization | string | Company name. (Optional) |
phoneWork | string | Work phone number. (Optional) |
string | Email address. (Optional) | |
website | string | Website URL. (Optional) |
Type: `upi`
Field | Type | Description |
---|---|---|
upiId | string | The UPI ID (VPA) of the payee. |
payeeName | string | The name of the payee. |
amount | number | The payment amount. Optional. |
note | string | A note for the transaction. Optional. |
Example Request (URL type)
curl -X POST 'https://codingmantra.com/api/qr-code/generate' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"type": "url",
"value": "https://codingmantra.com",
"size": 512,
"fgColor": "#0A66C2",
"logoUrl": "https://codingmantra.com/assets/icons/logo-1024.png"
}'
Example Request (UPI type)
curl -X POST 'https://codingmantra.com/api/qr-code/generate' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"type": "upi",
"upiId": "example@upi",
"payeeName": "John Doe",
"amount": 150.50,
"note": "Payment for services"
}'
Example Response (All POST types)
{
"data": {
"qrCodeDataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
}
POST/api/qr-code/decode
Decode a QR code from a provided image URL or Base64 data URI. Requires authentication. The response will be a JSON object containing the decoded text.
Request Body
Provide exactly one of the following fields:
Field | Type | Description |
---|---|---|
url | string | A publicly accessible URL of the QR code image. |
base64 | string | A Base64 data URI of the QR code image. |
Example Request
# By URL
curl -X POST 'https://codingmantra.com/api/qr-code/decode' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"url": "https://example.com/path/to/your/qrcode.png"
}'
# By Base64
curl -X POST 'https://codingmantra.com/api/qr-code/decode' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"base64": "data:image/png;base64,iVBORw0KGgo..."
}'
Example Response
{
"data": {
"decodedText": "https://codingmantra.com"
}
}