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.
Anchor to Use casesUse cases
- 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.
Anchor to MethodsMethods
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 capturecapturecapture() => Promise<ScannerPayload>() => Promise<ScannerPayload>requiredrequired
Opens the device camera to scan a barcode. Returns a Promise that resolves to a
containing the scanned data.
ScannerPayload
The result returned after a successful barcode scan.
- data
The scanned barcode data as a string.
string
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 });
}
Examples
Description
Look up products by scanning their barcode. This example captures a barcode and queries the Admin API to find the matching product variant.
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?