Methods
Most of Shopify App Bridge's functionality relies on actions. See the Actions section to learn more about how to use these.
Most of Shopify App Bridge's functionality relies on actions. See the Actions section to learn more about how to use these.
Anchor to Initialization methodsInitialization methods
Anchor to [object Object]createApp(config)
createApp(config)Returns an app object. Used to initialize your app instance.
The config object should contain the following keys:
| Key | Type | Description |
|---|---|---|
apiKey | string | The client ID provided for your application in the Dev Dashboard. |
host | string | The base64-encoded origin/domain of the Shopify shop, which is provided by Shopify as a query parameter on the initial load of your app in the Shopify Admin. The host is set dynamically and should be stored in the session from the initial load. |
In the following example, config is a valid App Bridge configuration object. Learn more about configuring App Bridge.
In the following example, config is a valid App Bridge configuration object. Learn more about configuring App Bridge.
Modular JavaScript
import createApp from '@shopify/app-bridge';
const app = createApp(config);CDN-hosted
var AppBridge = window['app-bridge'];
var createApp = AppBridge.createApp;
const app = createApp(config);Anchor to App object methodsApp object methods
Anchor to [object Object]app.dispatch(action)
app.dispatch(action)Dispatches an action to Shopify App Bridge. Hosts (like Shopify Admin and Shopify Mobile) can subscribe to actions to listen for these dispatches.
| Key | Type | Description |
|---|---|---|
action | Action | One of Shopify App Bridge's included actions. |
Anchor to [object Object]app.error(callback)
app.error(callback)Subscribe to all errors, including those that are caused by actions. Returns a method you can use to unsubscribe from all errors.
| Key | Type | Description |
|---|---|---|
callback | function | The function you want to execute when an error occurs. |
Anchor to [object Object]app.getState()
app.getState()Returns a Promise which, when resolved, returns information about your app's current state, including the currently logged in staff member.
Anchor to [object Object]app.subscribe(callback, id?)
app.subscribe(callback, id?)Subscribe to all actions. Returns a method you can use to unsubscribe.
Arguments:
| Key | Type | Description |
|---|---|---|
callback | function | The function you want to execute when an action is dispatched. |
id | int | The ID of a particular action set instance to subscribe to (optional). |
Anchor to [object Object]app.subscribe(eventNameSpace, callback, id?)
app.subscribe(eventNameSpace, callback, id?)When eventNameSpace or id are provided, this method subscribes to actions of the provided type.
Arguments:
| Key | Type | Description |
|---|---|---|
eventNameSpace | string | Include this to subscribe only to actions of a particular type: for example, Modal.Action.OPEN. (optional) |
callback | function | The function you want to execute when an action is dispatched. |
id | int | The ID of a particular action set instance to subscribe to (optional). |
Anchor to Platform methodsPlatform methods
The following utility methods, available in the app-bridge package, return true or false depending on which platform an app is running on:
isShopifyMobile: Returnstrueif the app is running on Shopify Mobile.isShopifyPOS: Returnstrueif the app is running on Shopify POS.isShopifyPing: Returnstrueif the app is running on Shopify Ping.isMobile: Returns true if any of the conditions above are true.isShopifyEmbedded: Returnstrueif the app is running as an embedded app.