Skip to main content

Scanner API

The Scanner API allows you to use the mobile device's camera to scan barcodes. Use this API to capture barcode data and integrate it into your app's workflow on Shopify POS.

  • Product lookup: Scan barcodes to quickly look up products in the store catalog.
  • Inventory management: Scan items during inventory counts or stocktaking workflows.
  • Order processing: Scan package barcodes during fulfillment or receiving workflows.
  • Custom scanning: Implement custom barcode scanning workflows that process scan data for your app's needs.

The scanner API provides a capture method that opens the mobile device's scanner to capture a barcode. It returns a Promise resolving to the scanned barcode data or an error.

Anchor to capture
capture
() => Promise<>
required

Opens the device camera to scan a barcode. Returns a Promise that resolves to a ScannerPayload containing the scanned data.

Examples

js

// Scan a product barcode and look it up
try {
const { data: barcode } = await shopify.scanner.capture();

// Look up the product variant by barcode
const response = await fetch('shopify:admin/api/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
query getVariantByBarcode($barcode: String!) {
productVariants(first: 1, query: $barcode) {
nodes {
id
title
price
product {
title
}
}
}
}
`,
variables: { barcode: `barcode:${barcode}` }
})
});

const { data } = await response.json();
const variant = data.productVariants.nodes[0];

if (variant) {
shopify.toast.show(`Found: ${variant.product.title} - ${variant.title}`);
} else {
shopify.toast.show('Product not found', { isError: true });
}
} catch (error) {
shopify.toast.show('Scan cancelled or failed', { isError: true });
}

Was this page helpful?