Skip to content
moxon home

QR Code Generation

The /qrcode endpoint generates a QR Code from a URL provided as a parameter. This endpoint is useful for quickly generating an image in PNG format.

gethttps://api.moxon.dev/v5/qrcode
Try itget/v5/qrcode

Parameters

  • urlstringrequired

    The URL to encode in the QR Code. Must contain the full address

  • format"png" | "base64"optional

    Response format: png (default, direct image) or base64 (JSON data URL)

  • sizenumberoptional

    Image size in pixels (50-2000, default 200)

  • marginnumberoptional

    Quiet zone in modules (0-10, default 4)

  • correctionstringoptional

    Error correction level: L, M, Q or H (default M)

    • L
    • M
    • Q
    • H
  • darkstringoptional

    Module color in hexadecimal (e.g. 000000)

  • lightstringoptional

    Background color in hexadecimal (e.g. ffffff)

  • iconstringoptional

    HTTPS URL of an image to overlay at the center of the QR Code

  • iconSizenumberoptional

    Icon size in pixels (default 20% of size, max 40% of size)

  • iconPaddingnumberoptional

    White padding around the icon in pixels (default 5, 0-50)

  • iconRadiusnumberoptional

    Border radius of the icon background in pixels (default 0, max = perfect circle)

Good to know

When an icon is provided, the error correction level is automatically set to H to ensure readability. The icon URL must use HTTPS, with a 5s timeout and a 2MB size limit.

Keep the icon small

A large iconSize combined with generous iconPadding covers more QR Code modules, making it harder to scan. Keep the icon + padding area well below 40% of the total size for reliable results.

Response

By default (format=png), the endpoint returns a direct PNG image (Content-Type: image/png), usable in an <img> tag:

<img src="https://api.moxon.dev/v5/qrcode?url=https://moxon.dev" alt="QR Code" />

With format=base64, the response is a JSON object:

  • resultstring

    Base64 PNG data URI of the QR Code

Code Examples

Error Handling

If parameters are missing or invalid, the API will return an error:

  • 400Please provide a valid URLThe url parameter is missing or invalid
  • 400format must be one of: png, base64Invalid format value
  • 400size must be a numberThe size parameter is not a number
  • 400size must be between 50 and 2000The size is out of range
  • 400margin must be a numberThe margin parameter is not a number
  • 400margin must be between 0 and 10The margin is out of range
  • 400correction must be one of: L, M, Q, HInvalid error correction level
  • 400Invalid color (use hex like ff6600)A dark or light color is malformed
  • 400Icon URL must use HTTPSThe icon URL does not use HTTPS
  • 400Failed to fetch icon: HTTP {status}The icon URL returned a non-OK response
  • 400Icon URL must point to an imageThe icon content-type is not an image
  • 400Icon must be under 2MBThe icon exceeds the 2MB size limit
  • 400iconSize must be a numberThe iconSize parameter is not a number
  • 400iconSize must be between 10 and {max}The iconSize is out of range (max = 40% of size)
  • 400iconPadding must be a numberThe iconPadding parameter is not a number
  • 400iconPadding must be between 0 and 50The iconPadding is out of range
  • 400iconRadius must be a numberThe iconRadius parameter is not a number
  • 400iconRadius must be between 0 and {max}The iconRadius is out of range