Methods
Initialization methods
Anchor link to section titled "Initialization methods"createApp(config)
Anchor link to section titled "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 Partner 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. |
App object methods
Anchor link to section titled "App object methods"app.dispatch(action)
Anchor link to section titled "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. |
app.error(callback)
Anchor link to section titled "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. |
app.getState()
Anchor link to section titled "app.getState()"Returns a Promise which, when resolved, returns information about your app’s current state, including the currently logged in staff member.
app.subscribe(callback, id?)
Anchor link to section titled "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). |
app.subscribe(eventNameSpace, callback, id?)
Anchor link to section titled "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). |
Platform methods
Anchor link to section titled "Platform methods"The following utility methods, available in the app-bridge
package, return true
or false
depending on which platform an embedded app is running on:
isShopifyMobile
: Returnstrue
if the app is running on Shopify Mobile.isShopifyPOS
: Returnstrue
if the app is running on Shopify POS.isShopifyPing
: Returnstrue
if the app is running on Shopify Ping.isMobile
: Returns true if any of the conditions above are true.isShopifyEmbedded
: Returnstrue
if the app is running as an embedded app.