Skip to main content

Camera API

The Camera API provides access to the device's camera, enabling photo capture directly within POS UI extensions. The API requests camera permissions if not already enabled, opens the native camera interface, and returns the image data including dimensions, file size, and base64 string for immediate display or server upload.

Use cases

  • Photo capture: Capture photos for product documentation, damage verification, or visual records.
  • Proof workflows: Create photo-based proof workflows for deliveries, returns, or customer verification.
  • Visual documentation: Document inventory conditions or store displays.
  • Customer engagement: Implement features requiring visual capture for custom orders or personalization.
Support
Targets (28)

The CameraApi object provides properties for capturing photos using the device camera. Access these properties through shopify.camera to take photos and retrieve image data with metadata.

Anchor to takePhoto
takePhoto
(options?: ) => Promise<>
required

Launch the device's camera to take a photo.

Examples

jsx

import {render} from 'preact';
import {useState} from 'preact/hooks';

export default async () => {
render(<Extension />, document.body);
};

const Extension = () => {
const [isProcessing, setIsProcessing] = useState(false);

const handleCaptureAndUpload = async () => {
setIsProcessing(true);
try {
const photo = await shopify.camera.takePhoto({
quality: 0.8,
maxWidth: 1520,
maxHeight: 1520,
});

// Upload the image to your backend server
// (Replace with your actual backend endpoint)
await fetch('https://your-backend.com/api/upload', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
image: photo.base64,
mimeType: photo.type,
}),
});

shopify.toast.show('Photo uploaded successfully!');
} catch (error) {
shopify.toast.show(`Error: ${error.message}`);
} finally {
setIsProcessing(false);
}
};

return (
<s-tile
heading="Upload Photo"
onClick={handleCaptureAndUpload}
disabled={isProcessing}
/>
);
};

  • Optimize image quality: Use appropriate quality and size settings to balance image quality with file size and upload performance.
  • Provide feedback: Show loading states while processing images and clear success/error messages after capture.
  • Handle errors gracefully: Account for scenarios where users cancel, camera is unavailable, or permissions are denied.

  • Camera functionality requires the device to have a camera and appropriate permissions granted by the user.
  • Only one camera operation can be in progress at a time. Attempting to call takePhoto() while a capture is already in progress will result in a rejected promise.
  • Base64 strings can be memory-intensive for large images. Use appropriate maxWidth, maxHeight, and quality settings to optimize performance.
  • The facingMode parameter may not behave consistently on all Android devices, because camera-facing behavior varies across manufacturers. If a requested mode isn't supported, the rear-facing camera is used by default, and users can still manually switch cameras from the camera interface.
Was this page helpful?