QR codes_
Generate QR codes from text strings with customizable size and margin for authentication, sharing, and data encoding.
2 min read
The QR code endpoint generates QR code images from any text string. QR codes are commonly used for two-factor authentication, sharing links, encoding data, and enabling quick access to information.
Generate QR code
Generate a QR code image from a text string. The QR code can be scanned by any standard QR code reader.
import { Client, Avatars } from "appwrite";
const client = new Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') .setProject('<PROJECT_ID>');
const avatars = new Avatars(client);
const result = avatars.getQR({ text: 'https://example.com', size: 300, margin: 1, download: false});
console.log(result); // Resource URLParameters
The getQR method accepts the following parameters:
| Parameter | Type | Description |
|---|---|---|
| text | string | The text string to encode in the QR code. Can be a URL, authentication URI, or any text data. |
| size | integer | The size of the QR code in pixels. Accepts values between 0-1000. Defaults to 200 if not provided. |
| margin | integer | The margin around the QR code in pixels. Accepts values between 0-10. Defaults to 1 if not provided. |
| download | boolean | Whether to download the image or return a URL. Defaults to false. |
Two-factor authentication
QR codes are commonly used for two-factor authentication (2FA). When setting up TOTP authentication, you can generate a QR code from the authenticator URI.
// After creating an MFA authenticatorconst authenticator = await account.createMfaAuthenticator({ type: 'totp'});const qrCode = avatars.getQR({ text: authenticator.uri, size: 400, margin: 2});Customization
Adjust the size and margin of QR codes to match your design requirements. Larger sizes improve scanability, while appropriate margins ensure the QR code is properly recognized by scanners.
// Small QR code with minimal marginconst smallQR = avatars.getQR({ text: 'https://example.com', size: 150, margin: 0});
// Large QR code for printingconst largeQR = avatars.getQR({ text: 'https://example.com', size: 800, margin: 3});
// Standard size for web displayconst standardQR = avatars.getQR({ text: 'https://example.com', size: 300, margin: 1});Use cases
QR codes are commonly used for:
- Two-factor authentication: Generate QR codes for TOTP authenticator setup
- Team invitations: Create QR codes for team invite links to enable quick member onboarding
- Link sharing: Create QR codes for URLs to enable quick access
- Event tickets: Generate QR codes for event registration and check-in
- Wi-Fi credentials: Encode Wi-Fi network information for easy connection
- Contact information: Share vCard data encoded in QR codes
Was this page helpful?
Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.