Skip to content

About

A comprehensive boilerplate and reference guide for mastering the Shopify App Bridge v4 API in Remix/React apps. Features interactive examples of all core APIs including Toasts, Modals, Fullscreen, Intents, and direct GraphQL Admin access.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Shopify App Bridge API Mastery

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.


🛠 Features Breakdown

1. Toast Notifications

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 });

2. Contextual Save Bar

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".

3. Modals

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.

4. Fullscreen Mode

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();

5. Resource Picker

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);

6. Standard Picker List

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;

7. Intents (Create Resources)

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);

8. Direct Admin API Access (GraphQL)

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();

9. Scanner (Mobile App Only)

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);
}

10. Native System Share

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,
});

11. Core App & Context Properties

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()

🚀 How to use this Repository

  1. Review app/routes/app._index.jsx to see real, functioning implementations of each of the APIs outlined above.
  2. Use this as a reference or boilerplate to implement Shopify Admin UI features quickly.
  3. Every button in the UI corresponds to a specific App Bridge capability, demonstrating both the Javascript logic and the required markup to power it.

📚 Resources

About

A comprehensive boilerplate and reference guide for mastering the Shopify App Bridge v4 API in Remix/React apps. Features interactive examples of all core APIs including Toasts, Modals, Fullscreen, Intents, and direct GraphQL Admin access.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages