Tạo QR
Tạo QR code tùy biến bằng public endpoint dùng API Keys.
Endpoint
Đây hiện là public API endpoint duy nhất được tài liệu hóa cho client bên ngoài dùng API key.
POST /v1/qr/generateXác thực:
X-Api-Key: nq_live_your_api_keyQuyền bắt buộc trong Dashboard > API Keys:
Generate QR Code(qr:generate)
Request Body
| Field | Type | Default | Mô tả |
|---|---|---|---|
data | string | required | Nội dung cần encode (tối đa 4096 ký tự) |
width | int | 300 | Chiều rộng theo pixel (50–2000) |
height | int | 300 | Chiều cao theo pixel (50–2000) |
margin | int | 0 | Lề xung quanh QR code |
errorCorrectionLevel | string | "M" | Mức sửa lỗi: L, M, Q, H |
includeSvgRoot | bool | true | Có bao gồm thẻ <svg> gốc hay không |
transparentBackground | bool | false | Nền trong suốt |
bodyStyle | string | "square" | Kiểu module từ danh sách tùy chọn |
bodyShape | string | — | Shape: Circle, Heart, Diamond, Hexagon, Star, RoundedSquare |
bodyBrush | Brush | — | Màu/gradient cho body |
outerEyeStyle | string | "square" | Pattern mắt ngoài |
outerEyeBrush | Brush | — | Màu mắt ngoài |
innerEyeStyle | string | "square" | Pattern mắt trong |
innerEyeBrush | Brush | — | Màu mắt trong |
backgroundBrush | Brush | — | Màu nền |
transparentBackground | bool | false | Nền trong suốt |
logo | Logo | — | Logo ở giữa |
template | string | — | Tên template |
Brush Object
Backend kỳ vọng giá trị PascalCase cho type.
Solid color:
{ "type": "Solid", "color": "#000000" }Linear gradient:
{
"type": "LinearGradient",
"startColor": "#06b6d4",
"endColor": "#a855f7",
"rotation": 45.0
}Radial gradient:
{
"type": "RadialGradient",
"centerColor": "#06b6d4",
"edgeColor": "#0e7490"
}Logo Object
| Field | Type | Default | Mô tả |
|---|---|---|---|
source | string | required | Nội dung SVG của logo hoặc data URI |
width | int | auto | Chiều rộng logo |
height | int | auto | Chiều cao logo |
padding | int | 0 | Padding quanh logo |
removeBackgroundBehind | bool | false | Xóa module phía sau logo |
cornerRadius | int | 0 | Bo góc vùng logo |
Ví dụ
curl -X POST https://api.niceqr.me/v1/qr/generate \
-H "X-Api-Key: nq_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"data": "https://niceqr.me",
"width": 400,
"height": 400,
"errorCorrectionLevel": "H",
"bodyStyle": "rounded",
"bodyShape": "Circle",
"bodyBrush": {
"type": "LinearGradient",
"startColor": "#06b6d4",
"endColor": "#a855f7",
"rotation": 135
},
"outerEyeStyle": "rounded",
"outerEyeBrush": { "type": "Solid", "color": "#06b6d4" },
"backgroundBrush": { "type": "Solid", "color": "#ffffff" }
}'Response
{
"success": true,
"data": {
"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" ...>...</svg>"
}
}Ghi chú
- Endpoint trả về SVG bên trong standard response envelope.
- Các trường hợp thiếu, sai, revoked, expired hoặc suspended API key sẽ cố ý trả về
404 Not Foundvới body rỗng. - Nếu
templateAccessLevellàpremium, tài khoản phải có quyền gói phù hợp cho tùy chọn QR đó.