This repository serves as a comprehensive guide and boilerplate for mastering the Shopify App Bridge v4 API. It demonstrates how to leverage the global shopify object available via @shopify/app-bridge-react (specifically the useAppBridge hook) to create deeply integrated and interactive Shopify applications.
All code examples can be found in app/routes/app._index.jsx.
Display simple, non-blocking messages to the user.
// Success/Info Toast
shopify.toast.show("This is a simple toast");
// Error Toast
shopify.toast.show("This is an error toast", { isError: true, duration: 5000 });Show a save bar across the top of the admin interface to prompt users to save or discard unsaved changes.
// Show Save Bar
shopify.saveBar.show("my-save-bar");
// Hide Save Bar
shopify.saveBar.hide("my-save-bar");Requires a <ui-save-bar id="my-save-bar"> component in your JSX containing buttons with id="save-button" and id="discard-button".
Open dialogs over the current page to prompt for user action or display information.
shopify.modal.show("my-modal");Requires a <s-modal id="my-modal"> or standard <ui-modal> component in your JSX.
Toggle the application into full screen mode to maximize workspace, hiding the Shopify Admin navigation.
// Enter Fullscreen
shopify.fullscreen.enter();
// Exit Fullscreen
shopify.fullscreen.exit();Launch Shopify's native resource picker to allow users to select products, collections, or other resources.
const picker = await shopify.resourcePicker({ type: "product" });
console.log(picker);Create a custom picker to select from a predefined list of items.
const picker = await shopify.picker({
heading: "Select a template",
multiple: false,
headers: [
{ content: "Templates" },
{ content: "Created by" },
{ content: "Times used", type: "number" },
],
items: [
{ id: "1", heading: "Template A", data: ["User A", "0"] },
// ...
],
});
const selected = await picker.selected;Invoke native admin intents, such as opening the native "Create Product" page in a modal.
shopify.loading(true); // Show loading bar
const product = await shopify.intents.invoke("create:shopify/Product");
const response = await product.complete;
shopify.loading(false);Send GraphQL requests directly to the Admin API from the frontend. This utilizes Shopify's built-in session token authentication automatically.
const requestProducts = await fetch("shopify:admin/api/graphql.json", {
method: "POST",
body: JSON.stringify({
query: `
query GetProducts {
products(first: 5) {
edges { node { id title } }
}
}`,
}),
});
const { data } = await requestProducts.json();Trigger the device camera to scan barcodes when the app is running within the Shopify Mobile App.
try {
const result = await shopify.scanner.capture();
console.log("Scanner result:", result);
} catch (e) {
console.error("Scanner error:", e);
}Trigger the operating system's native share dialog.
await shopify.share({
title: "App Bridge Share",
text: "Check out this awesome Shopify app!",
url: window.location.href,
});Retrieve contextual information about the environment, store, and app configuration.
- Check Available Features:
await shopify.features.available() - Get Store Configuration:
shopify.config.shop,shopify.config.locale - Get Theme Extensions:
await shopify.app.extensions() - Get Environment Info:
shopify.environment - Get Current User:
await shopify.user() - Get Current Scopes:
await shopify.scopes.query() - Get Auth Token:
await shopify.idToken()
- Review
app/routes/app._index.jsxto see real, functioning implementations of each of the APIs outlined above. - Use this as a reference or boilerplate to implement Shopify Admin UI features quickly.
- Every button in the UI corresponds to a specific App Bridge capability, demonstrating both the Javascript logic and the required markup to power it.