Skip to main content
This guide is for frontend developers who want to use Appstle’s subscription backend but build their own storefront UI instead of using the default widget. It covers the product page (rendering selling plans, adding subscriptions to cart), the customer portal (viewing and managing active subscriptions, or embedding Appstle’s portal on one of your pages), and the JavaScript events you can hook into.
This guide covers the Storefront API surface (/cp/api/...), which is designed for customer-facing storefront code. If you are building a server-side integration, see the Integration guide instead — it covers the Admin API (/api/external/v2/..., authenticated with X-API-Key).

When to build your own vs. use the widget

The Appstle subscription widget (appstle-subscription.js) is injected automatically on your storefront and handles selling-plan rendering, cart integration, and the customer portal out of the box. Build your own frontend when you need:
  • A product page UI that doesn’t match what the widget renders (custom layout, framework-specific components, headless storefronts)
  • A customer portal that matches your own account page design rather than the default portal
  • Programmatic control over subscription flows (e.g. a React/Vue app that manages state itself)
If you only need to react to widget interactions — tracking analytics, showing/hiding elements, applying conditional logic — you can keep the default widget and listen to its JavaScript events instead of replacing it entirely. To show Appstle’s own portal inside one of your pages instead of building one, see Embed the customer portal on a page.

Architecture overview

Appstle’s Storefront APIs are served through Shopify’s App Proxy. When a request hits your shop’s domain at the proxy path, Shopify forwards it to Appstle’s backend with authentication parameters attached.
The default proxy path is /apps/subscriptions. Merchants can customize this in their Shopify admin, but apps/subscriptions is the standard default.
Storefront API requests must go through the App Proxy on your shop’s domain. You cannot call Appstle’s backend directly from the browser — requests that bypass the proxy will fail authentication.

Authentication

The Storefront API does not use API keys. Authentication depends on the context: A few portal endpoints work without a logged-in customer (portal settings, custom CSS, magic link emails). Everything else — viewing contracts, skipping orders, updating addresses — requires the customer to be authenticated through a Shopify session.

Rate limits

Storefront API calls are limited for each signed-in customer and for the store as a whole. The limits count every call to the store’s storefront endpoints, including the calls the Appstle widget and customer portal make. Treat these numbers as the most you should send: A call without a signed-in customer gets 401 before any limit is counted, except on the few endpoints that work without one (portal settings, custom CSS and magic link emails), which are counted per IP address instead. Paths that differ only in a numeric ID count as one endpoint. A call over a limit can get 429 Too Many Requests with a Retry-After: 30 header and the body {"error":"Rate limit exceeded. Try again later."}, or an HTML error page when the request’s Accept header includes text/html. Wait the Retry-After seconds before you retry. Because the per-endpoint limits are shared by every customer on the store, don’t poll: call an endpoint when the customer acts, and keep what it returns for as long as the page is open.

Product page: rendering selling plans

On product pages, you typically don’t need the Storefront API at all. Shopify’s native Liquid and Product JSON already include the selling plan data that Appstle configures.

Getting selling plan data from Shopify Liquid

Every Shopify product with subscription selling plans exposes them in the selling_plan_groups array:
You can also access this data as JSON for use in JavaScript:

Getting selling plan data from Shopify Product JSON

In theme JavaScript, fetch the product from Shopify’s Ajax API. A visitor doesn’t need to sign in. Use the .js URL, not .json, which returns no selling plan data:

Getting selling plan data from the Appstle Storefront API

For richer subscription data than Shopify’s native objects provide, use the Appstle endpoints below. They work only for a signed-in customer:
There is also a v2 endpoint that accepts optional variantIds for variant-specific data:
To list all selling plans available in the shop:
A visitor who isn’t signed in gets 401 from these endpoints. On product pages, use Shopify’s Liquid objects or the product JSON above.

Adding a subscription to cart

Adding a subscription item to the Shopify cart uses Shopify’s standard Cart API — you include the selling_plan ID alongside the variant ID. On a theme with the Appstle app embed on, the Appstle widget script can change the selling plan in these requests: read When the Appstle app embed is on before you go live.

Using the Cart AJAX API

Using a form

If you prefer a traditional form submission:
A fixed-price Build-a-Box also needs line item properties that carry the customer’s choices. See Build a fixed-price Build-a-Box with a custom UI. A Dynamic Pricing Build-a-Box needs a discount code for its tiers: see Build a Dynamic Pricing Build-a-Box with a custom UI.
A gift plan also needs the recipient’s details as line item properties (properties in /cart/add.js, properties[...] fields in a form). When the store’s Subscription Validations checkout rule is active, checkout refuses a gift without them. See Sell gift subscriptions from your own storefront.
Omitting the selling_plan field (or setting it to empty) adds the item as a one-time purchase. If a product has requires_selling_plan: true, the cart add will fail without a valid selling plan ID.

When the Appstle app embed is on

While the Appstle Subscriptions app embed is on in the theme, the widget script (appstle-subscription.js) can change the add-to-cart requests your code sends from a product page. It does this only while the store’s add-to-cart interceptor is on. Appstle turns the interceptor on when a store installs the app, and only Appstle support can turn it off. A headless storefront has no theme, so it never loads the script and this section doesn’t apply to it. On a product page that has an Appstle selling plan group, the script sets the selling plan in /cart/add requests to the one selected in the Appstle widget. The widget’s selection counts even when you hide the widget:
  • If the widget has a plan selected, for example because it selects a subscription by default, an item your code adds as a one-time purchase can go into the cart as a subscription to that plan.
  • If the widget is on one-time purchase or isn’t on the page, the script can remove the selling_plan your code sends, and the item goes into the cart as a one-time purchase. A fetch call with a JSON body, like the example above, can lose its plan this way.
1

Keep the app embed on

The same script also shows the Appstle widget on your other product pages, adds the customer portal link to the account page, loads a customer portal you embed on a page, and sends the JavaScript events. Leave the embed on and turn off only the interceptor.
2

Ask Appstle support to turn off the interceptor

Before you go live with your own picker, email support@appstle.com with the store’s myshopify.com domain and ask for the add-to-cart interceptor to be turned off, or ask the merchant to. The interceptor is store-wide, so if the Appstle widget still sells subscriptions on other product pages, test one of those pages in the next step too.
3

Test the cart

On each product page your customers will use, add a subscription and a one-time purchase, then read the cart:
A subscription line shows its selling plan ID, and a one-time line shows one-time. If a line doesn’t match what you added, something on the page changed your request.

Subscription options on upsell and product cards

Use this pattern when a product appears outside its own page, such as an upsell in the cart, a recommendation block or a card in a collection, and the customer should choose one-time or subscribe on the card. It needs no Appstle API call, and the customer doesn’t have to be signed in.
1

Read the product's plans

Fetch the product’s .js URL, as in Getting selling plan data from Shopify Product JSON. Each variant lists the plans it can use in selling_plan_allocations, with its price for each plan, so the card can show the subscribe price without a second call. Prices are in the smallest unit of the store currency, cents for USD:
A trimmed response:
2

Show the choice

Put a one-time and a subscribe option on the card, and keep the customer’s choice in your own code. When the product or the variant has requires_selling_plan: true, offer only the subscribe option. Appstle’s widget events don’t fire for a picker you build, as the events section explains.
3

Add the item

Send selling_plan only for a subscription. Leave it out for a one-time purchase. To refresh the cart in the same call, add sections (the IDs of the theme sections to render) and sections_url (the page they render for):
A subscription line in the response carries its plan in selling_plan_allocation:
4

Refresh the cart on the page

sections holds the rendered HTML of each section you asked for, keyed by its section ID. Replace the cart drawer’s markup with it instead of making a second request. Section IDs come from your theme: the id of a section’s element is shopify-section- followed by the section ID. See Shopify’s Section Rendering API for the details.
The cart refuses two requests with a 422 and a message in description: A response is {"status": 422, "message": "Cart Error", "description": "…"}. While the Appstle app embed is on, the widget script can change an add-to-cart request. Add an item from your card, read the cart as described in When the Appstle app embed is on, and check that the line has the plan you sent. If you don’t need your own markup, Appstle’s cart widget lets customers switch a cart item between one-time and subscription without code from you. It fires the cart widget events. The merchant sets it up on the Cart Widget tab of the widget settings in the Appstle Subscriptions app.

Customer portal: managing subscriptions

Once a customer is logged in, you can call the Storefront API through the App Proxy to build a custom subscription management UI. All of these endpoints are under:
The customer must have an active Shopify session. Shopify’s App Proxy handles authentication automatically.

Identifying the logged-in customer

Returns the Shopify customer ID as an integer. Returns 401 if no customer is logged in.

Listing a customer’s subscriptions

Get the full subscription profile (active, paused, and cancelled contracts):
Or get just the customer’s contract IDs, whatever their status:
For detailed contract data:

Viewing upcoming and past orders

Upcoming orders for a contract:
Past orders (paginated):

Updating subscription status

Pause, resume, or cancel a subscription:
Optional query parameters for pause: pauseReason, pauseFeedback, pauseDurationCycle.
To cancel with feedback:

Skipping and unskipping orders

Managing line items

Add a product:
Remove a product:
Update quantity:

Editing line item properties

Line item properties (Shopify calls them custom attributes) are key-value pairs stored on one subscription line, such as a gift message or a grind choice. To let a customer change them, send the line’s full list of properties:
Read lineId and the line’s current properties from lines.nodes[] (id and customAttributes) in the contract. On success the call returns 200 and the updated contract, in the same shape. The reference page lists every field. The call replaces the line’s properties. It doesn’t merge them:
  • The line keeps exactly the properties in your list. A property you leave out is removed. To change one, send every property back with your change in it. To remove them all, send [].
  • Appstle’s own properties don’t change. Keys such as _appstle-bb-id, __appstle-bb-name, _min-cycles and _appstle-one-time-product keep their stored values whatever you send, so you can send them back as you read them or leave them out.
  • A Build-a-Box line’s selection is the exception. products, __appstle-bb-variants and _appstle-bb-product-sku change the box’s contents, and the call checks them against the box’s limits. Leave them out of a properties edit. To change the contents, see Build a fixed-price Build-a-Box with a custom UI.
  • Each key can appear once. A repeated key returns 400 with errorKey duplicateAttributeKey.
In your UI, let the customer edit only properties whose keys don’t start with an underscore, and never products. Shopify treats underscore keys as private, and every Appstle key except products starts with one. This example reads a line’s properties, changes the gift message and keeps the rest:
This is the line in the response, trimmed to the fields that matter. The Build-a-Box properties the example left out are still there:

When the call is refused

A refused call returns 400 with Content-Type: application/problem+json. When its message starts with UserGeneratedError:, the text after the prefix is written for the customer: show it, and don’t match on its wording. This is the body for a repeated key:
The call is also refused when:
  • The contract isn’t the signed-in customer’s. The message is Contract does not exist, with no prefix, and errorKey is invalidContract. Check the contractId your code sends.
  • It’s a gift subscription. The buyer can’t change a gift subscription from the storefront. The message is This is a gift subscription, so it can't be changed here. Please contact us if anything needs to change., and errorKey is giftBuyerReadOnly.
  • The store has turned off customer editing. The setting is Customers can edit custom details. The message is Permission denied, Editing attributes is not allowed, and errorKey is enableEditAttributes. It applies only when the properties change: sending a line’s properties back unchanged isn’t refused. A store that never saved the setting allows the change through this call, though Appstle’s own portal doesn’t offer editing until the store turns the setting on.
  • The store’s window for product changes is closed. The window covers property edits too, except on a paused subscription. The message is Product modifications cannot be made within 3 days of your next billing date or Product modifications can only be made within 7 days of your next billing date, with the store’s own number of days, and errorKey is productOperationTimeRestriction.
  • The subscription hasn’t reached its minimum number of orders. This applies when the store freezes subscriptions until then, and when the line has a _min-cycles property. The message is the store’s own freeze message, for example Subscription cannot be modified until 3 orders have completed.
A call without a signed-in customer gets 401, and a call over a rate limit gets 429: see Rate limits. Save once, when the customer confirms the change, not on every keystroke.

Discounts

Apply a discount code:
Remove a discount:

Updating shipping address

Request body (application/json):

Changing billing date

Changing frequency

Switch to a compatible selling plan frequency:
Or change billing interval directly:

Portal settings and styling

To load the merchant’s portal configuration (labels, features, display settings):
This endpoint does not require customer authentication — it returns the portal’s display configuration. For custom CSS:
For the full list of Storefront API endpoints with request/response schemas, see the Storefront API group in the sidebar.

Embed the customer portal on a page

Use the embed to show Appstle’s own customer portal inside a page of your store, such as /pages/community, instead of rebuilding the portal from the Storefront API. The portal runs inside your page, so the customer stays on it and the address keeps your page’s path.
This embeds the customer portal that Appstle serves through the app proxy. The portal that appears inside Shopify’s own customer account pages is a separate Shopify customer account extension, and you can’t embed it elsewhere.

Add the portal to a page

Add an element with the id AppstleCustomerPortal to the page. On a Shopify page, switch the editor to HTML view (the <> button) and paste:
When the widget script loads, it finds the element and fills it with the portal. You don’t call anything. A signed-in customer sees their subscriptions. A visitor who isn’t signed in sees a form that emails them a sign-in link. That link opens the store’s main subscription page, not your page. The portal keeps its own route in the address bar after a #, so #/subscriptions/list appears after your page’s path once it loads. It draws only when the hash is empty or one of its own routes, such as #/subscriptions/list. With any other hash, such as #account, the element stays empty. If your page uses the hash for its own tabs or anchors, clear it before the portal starts:

Start the portal from your own code

Call window.appstleSubscriptionCustomerPortalInit(selector) when the element has a different id or your code adds it after the page loads. The function may not exist until the widget script has loaded, so when it isn’t there yet, wait for the ReadyToEmbed event:
Each call loads the portal again, replaces what is inside the element and fires AppstleSubscription:CustomerPortal:Embedded. If no element matches the selector, the call does nothing and fires no event. Call it once per page view.

Stores that use the Customer Account API

When Enable Customer Account API is on under Shop Settings in the Appstle app, the portal reads subscriptions through Shopify’s Customer Account API. A customer with no current Shopify sign-in for the app is sent to Shopify to sign in, and then back. That is a full page navigation, so your page unloads and loads again. With the setting off, there is no sign-in trip. The setting is off by default. The customer comes back to the page they left, with ca_authenticated=true added to the address: /pages/community?ca_authenticated=true#/subscriptions/list. Nothing is mounted yet when the page loads again, so:
  • If the element is in the page’s HTML, the portal loads on its own and removes ca_authenticated from the address once it is running.
  • If your code adds the element, run your start-up code again. A page that hides the portal behind a tab or a button should open that view when location.search contains ca_authenticated or the hash starts with #/subscriptions, and then start the portal.
If the sign-in fails, the customer comes back with ca_error and the reason in the address instead. The portal shows the message Customer Account API Error with the reason, falls back to its standard API and still lists the subscriptions. Two things can still take the customer off your page:
  • The customer comes back to your page only if its host is the store’s myshopify.com domain or the Public Domain shown in Shop Settings, www included. Appstle sets Public Domain to the store’s primary domain when the app is installed, and only Appstle support can change it: if your page is on another domain, contact support@appstle.com. From any other host, the customer lands on /apps/subscriptions, the main portal address.
  • Shopify limits how long the sign-in lasts, and the app doesn’t receive a refresh token to renew it in the background. A customer who opens the portal after the sign-in has expired makes the trip again. If the portal must stay on your page on every visit, keep Enable Customer Account API off.
For the events the embed fires, see JavaScript events.

Headless storefronts

A headless storefront, such as a Hydrogen app or your own front end on Shopify’s Storefront API, has no Shopify theme. That means no Appstle app embed, no widget script and no add-to-cart interceptor. You don’t need them: Shopify’s APIs carry the subscription through the cart and checkout, and Appstle creates and manages the subscription after checkout.
This section uses Shopify’s own Storefront API with a Storefront access token. That token is public: it can read products and build carts, nothing more. It isn’t the Appstle Admin API key, which must stay on your server. The calls below were run on API version 2026-10 with a token that had the unauthenticated_read_selling_plans, unauthenticated_read_product_listings and unauthenticated_write_checkouts scopes.

Read the plans

Ask for sellingPlanGroups on the product and sellingPlanAllocations on each variant. A product that has no plan returns empty lists.
A trimmed response:

Add a subscription to the cart

Create the cart with the variant as merchandiseId and the plan as sellingPlanId. Both are GraphQL IDs:
To add a line to an existing cart, run cartLinesAdd with the cart’s id and the same lines. Leave out sellingPlanId for a one-time purchase. Send customers to checkoutUrl to pay. A variant of a product with requiresSellingPlan: true can’t go in the cart without a plan. The mutation returns no cart and this error:

What happens at checkout

When the customer pays for a cart with a selling plan, Shopify creates the order and Appstle creates the subscription contract for it within seconds. The contract is the same as one made through a theme. It appears in the Admin API, it sends the usual webhooks, and its next billing date follows the plan. You write no code for this step.

Plans with a two-step price

A plan can charge one price for its first orders and a different price after that. Appstle counts the orders of each subscription contract, the checkout order plus every successful renewal. Once a contract has had as many orders as the first step covers, Appstle changes its price for the orders after that. Each contract keeps its own count, so a customer who starts a second subscription on the same plan pays the first price again. To show the steps on your storefront, read the plan’s priceAdjustments: orderCount is the number of orders a step covers, and null means the step always applies. See Shopify’s SellingPlanPriceAdjustment for the fields.

Give customers their portal

Customers manage their subscriptions in Appstle’s customer portal, which Shopify serves through the app proxy at /apps/subscriptions on the store’s myshopify.com domain. The portal page renders inside the store’s theme, so that storefront has to stay open: a storefront password page or a theme that sends every page to your front end also keeps customers out of the portal. Send customers there with a sign-in link that your server requests with your Admin API key. Never call these endpoints from the browser, where the key would be exposed. A read-only key gets 403 from both.
  • Generate the link. Call Generate customer portal link with the customer’s Shopify ID. The response has manageSubscriptionLink, which opens the portal signed in as that customer and expires after 2 hours. Its host is the Public Domain in Shop Settings, which Appstle sets to the store’s primary domain when the app is installed.
  • Build the link yourself when the store’s primary domain is your headless front end, which doesn’t serve the app proxy. Call Generate customer portal authentication token with customerId, and put the URL-encoded token on the myshopify.com domain: https://your-shop.myshopify.com/apps/subscriptions?token=TOKEN. The token also expires after 2 hours.
If Enable Customer Account API is on, Shopify’s sign-in sends customers back only to the myshopify.com domain or the Public Domain. See Stores that use the Customer Account API.

Next steps

Using JavaScript widget events

On a theme with the Appstle Subscriptions app embed on, the widget script (appstle-subscription.js) loads even when you build your own UI. It dispatches these events on both document and window. A headless storefront doesn’t load the script, so it gets none of them.

Key events for custom frontends

Which of these events fire depends on which Appstle UI is on the page:
  • Subscription widget: widgetInitialised, SellingPlanSelected, SellingPlanDeSelected, sellingPlanChanged and AddToCartIntent fire only from Appstle’s own widget. None of them fire for a picker you build yourself, so keep its state in your own code. If the Appstle widget is still on the page, even hidden, these events come from it and follow its selection, not your picker’s.
  • Cart widget: CartWidget:Updated, SwitchedToSubscription and SwitchedToOneTime fire only from Appstle’s cart widget.
  • Customer portal: CustomerPortal:ReadyToEmbed fires on every page once the widget script has loaded, and CustomerPortal:Embedded fires each time the portal is added to an element.
For the full event reference, see JavaScript hooks.

Listening to events in your custom UI

Widget initialization event

The appstle:subscription-widget:loaded event fires once, on window only, when the widget script has initialized. Its detail.api is the same object as window.AppstleSubscriptionWidget. If your script runs after the widget’s, the event has already fired, so check for the object first:

End-to-end example: custom product page subscription UI

This example shows how to render selling plans, let the customer select one, and add a subscription to cart — all without using the default widget UI.
This example uses Shopify’s native product data and Cart API, so it doesn’t need the Appstle widget on the page. On a theme with the Appstle app embed on, the widget script can still change the selling plan this example sends: see When the Appstle app embed is on.

Further reading

Fixed-price Build-a-Box

Add a fixed-price Build-a-Box to the cart and save a customer’s changed selection.

Dynamic Pricing Build-a-Box

Add a customer’s picks to the cart and get the tier discount code for checkout.

Webhooks

Receive real-time events when subscriptions change.

JavaScript hooks

Complete list of widget events you can listen to.

Authentication

Admin API keys and storefront authentication details.

Partner integration

Connect a third-party platform on behalf of multiple merchants.

Integration guide

Server-side Admin API integration for backend developers.