Skip to content
Ayra Docs

JavaScript API

The Ayra app embed exposes a small storefront JavaScript API as window.Ayra, so theme code can read the signed-in customer’s wallet, open the wallet launcher, add a variant to the wishlist or register for a restock alert, and react to changes through DOM events, without scraping Ayra’s blocks. The API is available after the ay:ready event, is read-mostly by design (every write goes through Ayra’s authenticated endpoint and is validated server-side), and is versioned: Ayra.version is 1 for the private beta, and breaking changes get a new major with both versions served for a release cycle.

The API is attached by the core bundle (defer), so it may not exist when inline theme scripts run. Wait for it:

window.addEventListener('ay:ready', ({ detail }) => {
  console.log(Ayra.version, detail.modules); // 1, { loyalty: true, referrals: true, ... }
});

// Or, if your script runs after the bundle:
if (window.Ayra?.isReady) start();

Ayra.ready() returns a promise that resolves once the bundle has loaded the shop settings and identified the customer (or confirmed there is none).

Status: live for beta merchants; planned ships with the module named.

Method / propertyStatusReturnsNotes
Ayra.versionLivenumberAPI major version
Ayra.isReadyLivebooleanTrue after ay:ready
Ayra.ready()LivePromise<void>Resolves when ready
Ayra.modulesLive{ [module]: boolean }Which modules are on for this shop
Ayra.settingsLiveobjectThe public settings (ayra.settings_public): labels, earn ratio, tiers
Ayra.on(event, handler)Live() => voidSugar for addEventListener on the ay:* DOM events; returns an unsubscribe function
Method / propertyStatusReturnsNotes
Ayra.customerLive{ id, tier, stage, preferredChannel } | nullThe signed-in customer, or null for guests
Ayra.customer.identify({ email })LivePromise<boolean>Attaches a guest’s actions to an email after an explicit action (newsletter form, restock registration). Never call it without the customer typing their email
MethodStatusReturnsNotes
Ayra.wallet.get()LivePromise<{ total, points, storeCredit, vouchers, tier, nextTier }>Cached 60 s; ay:wallet.updated fires when it changes
Ayra.wallet.pointsFor({ amount })LivenumberPoints a cart or product total would earn, tier multiplier applied; pure, no request
Ayra.wallet.openLauncher(tab?)LivevoidOpens the floating wallet launcher on wallet, earn, tiers or referrals
Ayra.wallet.redeem(rewardHandle)LivePromise<{ ok, storeCreditIssued }>Converts points to store credit from the catalogue; the customer must be signed in
MethodStatusReturnsNotes
Ayra.referrals.get()LivePromise<{ code, url, invited, pending, granted }>Signed-in customers only
Ayra.referrals.share(channel)LivePromise<void>Opens the native share sheet or the channel’s share URL and records ay:referral.shared

Wishlist, back in stock, pre-order, subscriptions, reviews

Section titled “Wishlist, back in stock, pre-order, subscriptions, reviews”
MethodStatusReturnsNotes
Ayra.wishlist.add(variantId) / .remove(variantId)Planned (Wishlist)Promise<void>Guests get a cookie-backed list merged on login
Ayra.wishlist.has(variantId)Planned (Wishlist)booleanSynchronous from local state
Ayra.wishlist.list()Planned (Wishlist)Promise<Item[]>
Ayra.restock.register(variantId, { channel, email })Planned (Back in Stock)Promise<void>email only for guests
Ayra.preorder.info(variantId)Planned (Pre-Order){ enabled, expectedShipDate, limit }From the variant metafield; synchronous
Ayra.subscriptions.plans(productId)Planned (Subscriptions)Promise<Plan[]>Selling plans with the save offers
Ayra.reviews.summary(productId)Planned (Reviews){ average, count, distribution }From the product metafield; synchronous
Ayra.reviews.open(productId)Planned (Reviews)voidOpens the review form modal

All ay:* DOM events are listed on the Events page. Ayra.on is the preferred way to subscribe:

const off = Ayra.on('ay:wallet.updated', (wallet) => {
  document.querySelector('[data-points]').textContent = wallet.points;
});

Methods that talk to Ayra reject with an AyraError carrying code (not_signed_in, module_off, rate_limited, invalid, network) and a human-readable message. Read code, never the message, in your logic.

  • Expose another customer’s data, or any data for a guest beyond what they created in this session.
  • Grant points or credit. Earning is decided by rules on the server; there is no client method for it.
  • Bypass Journey Guard. Nothing in the API sends a message.

Something missing or wrong on this page? Ask us and we will fix the docs.