The QRCode API generates custom QR codes for any content. It supports custom colors, size, and several image formats.
HTTP GET
Returns a QRCode image binary specified by input parameters.
data
(required) - data to encode in the QR code.
format
(required) - image format to return. Must be one of the following: png
, jpg
, jpeg
, eps
, svg
.
size
(optional) - size of the QR code image to generate. The output will be a square image with (size x size) dimensions.
fg_color
(optional) - foreground color of the QR code. Must be a 6-digit hex color (e.g. 00ff00
for green). Default is 000000
(black)
bg_color
(optional) - background color of the QR code. Must be a 6-digit hex color (e.g. 00ff00
for green). Default is ffffff
(white)
X-Api-Key
(required) - API Key associated with your account.
Accept
(may be required) - depending on the programming language and HTTP request library (e.g. Python's requests
), you may need to add a header indicating the content type(s) to accept in the result. Set the value according to your format
parameter:
png
: image/png
jpg
: image/jpg
jpeg
: image/png
eps
: application/postscript
svg
: image/svg+xml
Live Demo!
https://api.api-ninjas.com/v1/qrcode?format=png&data=
import requests
import shutil
data = 'https://api-ninjas.com'
fmt = 'png'
api_url = 'https://api.api-ninjas.com/v1/qrcode?data={}&format={}'.format(data, fmt)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY', 'Accept': 'image/png'}, stream=True)
if response.status_code == requests.codes.ok:
with open('img.jpg', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
else:
print("Error:", response.status_code, response.text)
var data = 'https://api-ninjas.com';
var fmt = 'png'
$.ajax({
method: 'GET',
url: 'https://api.api-ninjas.com/v1/qrcode?data=' + data + '&format=' + fmt,
headers: { 'X-Api-Key': 'YOUR_API_KEY' },
contentType: 'application/json',
success: function(result) {
console.log(result);
},
error: function ajaxError(jqXHR) {
console.error('Error: ', jqXHR.responseText);
}
});