Host capabilities
Use what the store dashboard offers your embedded app, such as a save bar, a barcode scanner, file uploads and printing, and check what each host supports.
Your embedded app runs inside a host: the store dashboard in a browser today, and the Tanqory mobile apps next. The host offers capabilities your page cannot have on its own, such as the dashboard's save bar, a barcode scanner, uploads into the store's storage and printing. You ask for each one with an App Bridge request, the same way as titleBar.set in Embedded apps and App Bridge. The examples below use the bridge() helper from that page.
The host always shows its own screens, in its own words. Your page gets a result: the code that was scanned, references to the uploaded files, the button that was pressed. It never gets the camera, the merchant's files on disk, or the dashboard's page.
Check what the host supports
ready answers with features, the list of requests this host answers, and capabilities, details of the requests that have options. Check before you show a button, and keep a way to do the job without it:
const info = await bridge('ready', { clientVersion: 'my-app-1.0' });
const can = (type) => info.features.includes(type);
if (can('scanner.capture')) showScanButton();
// On the dashboard in a browser: { camera: false, formats: [...] }, so the scanner is a sheet where the merchant types the code.
console.log(info.capabilities?.['scanner.capture']);A host that does not know a request answers it with the error code UNSUPPORTED. New requests are added under the same protocol version, so an older host simply leaves them out of features.
Declare the device features you use
The scanner, file uploads and printing need a line in your app's configuration first. In the partner dashboard, open your app, then Configuration and Device features, turn on each one you use and say in a sentence why. The merchant sees the list and your reasons when they install the app, and app review checks that you use what you declared.
| Device feature | Requests it allows |
|---|---|
| Barcode scanner | scanner.capture |
| Upload files | files.pick |
print.open (and window.print() in the frame) |
A request for a feature you did not declare is refused with NOT_PERMITTED.
The requests
| Request | Payload | Answer | Needs |
|---|---|---|---|
context.get | {} | { storeId, locale, platform, surface, colorScheme, currencyCode?, timezone? } | nothing |
saveBar.show | { saving? } | {} | nothing |
saveBar.hide | {} | {} | nothing |
scanner.capture | { formats?, prompt? } | { cancelled: true } or { cancelled: false, data, format?, source } | Barcode scanner declared |
files.pick | { accept?, multiple?, source? } | { cancelled: true } or { cancelled: false, files: [{ resourceUrl, filename, mimeType, size }] } | Upload files declared, and the write_files, write_images, write_products or write_themes scope |
print.open | { path? } | {} | Print declared |
share.open | { title?, text?, url? } (text or an https url) | { shared } | nothing |
clipboard.write | { text } | {} | nothing |
intents.invoke | { action: create or edit, type: product, collection, customer, discount or page, id? } | { code: ok, closed or opened, id? } | the write scope of that type |
modal.openPage | { path, title?, size?: small, large or fullscreen } | { result? } | nothing |
modal.close | { result? } (from the page inside the dialog) | {} | nothing |
| Event (the host to your page) | Payload | When |
|---|---|---|
saveBar.save | {} | The merchant pressed Save on the save bar |
saveBar.discard | {} | The merchant pressed Discard |
Events arrive like answers, with kind: "event" and a type. Add this to the message listener of the helper:
if (m.kind === 'event' && m.type === 'saveBar.save') saveMyForm();
if (m.kind === 'event' && m.type === 'saveBar.discard') resetMyForm();Store context
context.get answers with facts about the store and the host: the store's id, its currency (ISO 4217) and time zone (IANA), the merchant's language, platform (web, ios or android), surface (admin) and colorScheme (light or dark), so your page can match the dashboard. It never includes the staff member's name or email. The session token's sub says who is using your app; read their details on your server with an online access token and the read_users scope.
Save bar
While your form has unsaved changes, show the dashboard's own save bar. It has a Save and a Discard button, and while it is shown the dashboard asks the merchant before they leave your app.
await bridge('saveBar.show'); // a field changed
await bridge('saveBar.show', { saving: true }); // your save is running
await bridge('saveBar.hide'); // saved, or the changes were discardedScan a barcode or QR code
const r = await bridge('scanner.capture', { formats: ['qr', 'ean13'], prompt: 'Scan the room key' });
if (!r.cancelled) lookUp(r.data); // r.source is 'camera', or 'typed' when the merchant typed it inOn the dashboard in a browser there is no camera scanner: the merchant types the code into the dashboard's sheet, and source is typed. Treat both the same way. Formats: qr, ean13, ean8, upca, upce, code128, code39, code93, itf, codabar, datamatrix, pdf417, aztec.
Upload files
Two ways, and both work in every host:
- A file input in your page.
<input type="file">opens the browser's own chooser, and the file stays in your page. Send it to your own server. files.pick. The dashboard opens the chooser, uploads what the merchant picks into the store's staged storage with the merchant's own permissions, and answers with references. Your page never handles the bytes.
const r = await bridge('files.pick', { accept: ['image/*', 'application/pdf'], multiple: 3 });
if (!r.cancelled) await fetch('/api/attach', { method: 'POST', body: JSON.stringify(r.files) });Then attach them from your server with your access token. resourceUrl is what fileCreate takes as originalSource (or a product media source):
mutation AttachFiles($files: [FileCreateInput!]!) {
fileCreate(files: $files) { files { id fileStatus } userErrors { field message } }
}{ "files": [{ "originalSource": "<resourceUrl>", "filename": "room-plan.png", "contentType": "IMAGE" }] }Each file is at most 50 MB, and at most 10 in one request. The store's checks run when the file is attached: its type is read from its content, location data is removed from photos, and a file that fails the malware scan is refused. Your server can also call stagedUploadsCreate itself with any of the four scopes above.
A page inside the dashboard's frame cannot print: the browser ignores window.print() there. Ask the host instead:
await bridge('print.open', { path: '/bookings/today?sheet=1' });The dashboard opens that page of your app in a new tab with the usual launch parameters, a fresh id_token and print=1. In that tab there is no dashboard to talk to, so do not send App Bridge requests: render the page from the id_token, then call window.print() yourself once everything has loaded.
print.open and files.pick must follow a click or tap by the merchant in your page. Send them from the click handler; otherwise they are refused with NOT_PERMITTED.
A page of your app in the dashboard's dialog
modal.openPage opens a page of your app (a path on your App URL) in the dashboard's own dialog, in a second frame with modal=1 in its launch parameters. That page uses App Bridge as usual, with a short list of requests (sessionToken.get, context.get, toast.show, loading.set, clipboard.write), and closes the dialog with modal.close, passing a result back:
// The page that opens it
const { result } = await bridge('modal.openPage', { path: '/rooms/pick', title: 'Pick a room', size: 'small' });
// The page inside the dialog (it sees modal=1 in its address)
await bridge('modal.close', { result: 'room-12' });If the merchant closes the dialog any other way, the answer has no result.
Share and copy
share.open opens the device's share sheet with your text and https link. Where the browser has none (most desktops), the dashboard copies the link instead, says so, and answers shared: false. clipboard.write copies text and shows "Copied". Neither works without a click in your page, and there is no way to read the clipboard.
Open the dashboard's own create and edit pages
intents.invoke sends the merchant to the dashboard's own page for creating or editing a product, collection, customer, discount or page, with their own permissions. It needs your app's write scope for that type (write_products for products and collections, write_customers, write_discounts, write_content for pages). On the dashboard in a browser, the page opens in a new tab and the answer is { code: "opened" }: read the result from the Admin API or a webhook. The mobile apps open their own screen and answer ok with the new id, or closed.
Errors
| Code | Means |
|---|---|
UNSUPPORTED | This host does not offer the request: check features |
NOT_PERMITTED | The device feature is not declared, the scope is missing, the merchant's staff permissions do not allow it, or it was not sent from a click |
BUSY | Another dashboard sheet (a dialog, a picker or the scanner) is already open |
UNAVAILABLE | The host could not do it now, for example an upload failed or the browser blocked the new tab |
Where each capability works
| Request | Dashboard in a browser | Tanqory mobile apps |
|---|---|---|
context.get, saveBar.* | Yes | Coming |
scanner.capture | Typed entry | Coming, with the camera |
files.pick | Yes, from the computer | Coming, with the camera and photos |
print.open | Yes, in a new tab | Coming |
share.open, clipboard.write | Yes (a copy where there is no share sheet) | Coming |
intents.invoke | Yes, in a new tab (opened) | Coming, with the result |
modal.openPage | Yes | Coming |
Check features rather than this table: a host lists exactly what it answers.