Skip to main content

Scanner API

The Scanner API provides access to barcode and QR code scanning functionality on POS devices, allowing you to subscribe to scan events, monitor available scanner sources, and process scanned data through subscription callbacks. The API enables integration with device cameras, external scanners, and embedded scanning hardware.

Use cases

  • Barcode scanning: Implement barcode scanning for product lookup or inventory management.
  • QR scanning: Build QR code scanning features for customer engagement or loyalty programs.
  • Custom workflows: Create custom scanning workflows that process scan data.
  • Real-time feedback: Implement real-time scanning feedback with immediate processing.

The ScannerApi object provides access to scanning functionality and scanner source information. Access these properties through api.scanner to monitor scan events and available scanner sources.

Anchor to scannerDataSubscribable
scannerDataSubscribable
RemoteSubscribable<>
required

Subscribe to scan events to receive barcode and QR code data when scanned. Supports one subscription at a time. Use for receiving real-time scan results.

Anchor to scannerSourcesSubscribable
scannerSourcesSubscribable
RemoteSubscribable<[]>
required

Subscribe to changes in available scanner sources on the device. Supports one subscription at a time. Use to monitor which scanners are available (camera, external, or embedded).

Examples
import React from 'react';
import {
CameraScanner,
Navigator,
Screen,
Stack,
Text,
useScannerDataSubscription,
useScannerSourcesSubscription,
reactExtension,
} from '@shopify/ui-extensions-react/point-of-sale';

const SmartGridModal = () => {
const {data, source} = useScannerDataSubscription();
const availableScanners = useScannerSourcesSubscription();
const hasCameraScanner = availableScanners.includes('camera');

return (
<Navigator>
<Screen name="Home" title="Home">
<Stack direction="horizontal">
{hasCameraScanner ? (
<CameraScanner />
) : (
<Stack direction="vertical" alignment="space-evenly">
<Text>{`Scanned data: ${data || ''}`}</Text>
<Text>{`Scanned data source: ${source || ''}`}</Text>
</Stack>
)}
</Stack>
</Screen>
</Navigator>
);
};

export default reactExtension('pos.home.modal.render', () => (
<SmartGridModal />
));

  • Manage subscriptions carefully: Remember that RemoteSubscribable supports only one subscription at a time. If you need multiple subscriptions, use makeStatefulSubscribable or manage subscription cleanup to avoid conflicts.
  • Validate scanned data appropriately: Validate scanned data before processing, implementing proper error handling for invalid codes, unsupported formats, or scanning errors.
  • Provide clear scanning feedback: Give users clear feedback about scan results, including success confirmations, error messages, and guidance when scans fail or produce invalid data.
  • Adapt to available scanner sources: Check available scanner sources and adapt your interface accordingly.

  • The Scanner API is only available in action (modal) targets where scanning functionality is supported and can't be used in other targets.
  • RemoteSubscribable supports only one subscription at a time. Use makeStatefulSubscribable if you need multiple components to subscribe to scan events simultaneously.
  • Scanning availability depends on device hardware capabilities and may vary between different POS devices and configurations.
Was this page helpful?