Skip to main content
A fixed-price Build-a-Box sells one parent product at one price, and the customer chooses what goes inside it, such as the scents, flavors or blends. Appstle’s own box page does all of this for you. This guide shows how to do the same from your own UI: add the box to the cart, then let the customer change its contents later without creating a second subscription.
Steps 1, 2 and 4 and Add a one-time extra run in the customer’s browser. Steps 1 and 4 and the one-time extra call Appstle’s Storefront API through Shopify’s App Proxy, so they need no API key; it isn’t Shopify’s Storefront GraphQL API. Step 3 and Save from your server instead use the Admin API from your server, with an API key. If the store changed its App Proxy path, replace /apps/subscriptions with it. Read Build your own frontend first if you haven’t used the App Proxy before.

What you’ll build

  • A cart add that puts a fixed-price box in the cart with a selling plan, and carries the customer’s choices as line item properties.
  • An account-page call that saves a changed selection on the customer’s existing subscription line.
  • An optional call that adds a one-time extra, such as a gift, to the customer’s next order.

Before you start

  • A fixed-price box (a Fixed Pricing Bundle), enabled in the Build-A-Box section of the Appstle Subscriptions app. Note its reference: the box list shows it as Ref, and the API calls it uniqueRef.
  • A selling plan attached to the box’s parent product.
  • A signed-in customer for Step 4 and for one-time extras. Steps 1 and 2 also work for guests.
  • For one-time extras, Customers can add one-time products turned on under Customer Portal → Customize portal → Features → One-time products. New stores start with it off.

How a fixed-price box is stored

A fixed-price box is one ordinary line: the box’s parent product with a selling plan. The customer’s choices travel on that line as five line item properties, and they stay on the subscription line after checkout. That is why you can change the choices later by updating that line’s properties, without adding a line or a subscription. Shopify doesn’t show properties whose names start with an underscore to the customer at checkout, so only products appears on the order summary.

Step 1: Read the box

Get the box’s rules and its choices. The call goes through the App Proxy, so it needs no API key and works for guests as well as signed-in customers:
The reference lists the same call under /apps/subscriptions/cp/api/, which needs a signed-in customer. The call answers 204 with an empty body when no box has this reference or the box is disabled. bundle.singleProductSettings is a JSON string. After parsing, it holds one entry per parent product, so a box with several parents has several entries. Use the entry whose sourceProduct is the parent you sell:
Read the rest from Shopify’s product JSON (/products/<handle>.js). The parent product’s selling_plan_groups[].selling_plans[].id is the selling plan. For a PRODUCT choice, its variants[].id and variants[].sku go into __appstle-bb-variants and _appstle-bb-product-sku. For a VARIANT choice, read the product at its productHandle and use the variant whose id matches. Offer only these choices: Appstle’s box page refuses anything else, and your UI must too.
The same box is available to your server as GET /api/external/v2/build-a-box/{handle} with an API key, where {handle} is the uniqueRef. It answers 404 while the box is disabled. See Retrieve Build-A-Box bundle details by handle.

Step 2: Add the box to the cart

Add the parent variant with the selling plan and the five properties. This is Shopify’s Cart API, so no Appstle call is involved:
Keep the total of the picks between minQuantity and maxQuantity. Shopify’s cart add doesn’t check it, but the save in Step 4 does.
Shopify answers 422 with Cannot apply selling plan to variant when the selling plan isn’t attached to the parent variant. Take the plan ID from the parent product’s selling_plan_groups.

Cart clearing

The Cart Clearing Behavior setting in the store’s Build-A-Box settings applies only to Appstle’s own box page. Your /cart/add.js call leaves the cart as it is. To start the customer with an empty cart, call Shopify’s POST /cart/clear.js before you add the box.

Step 3: Check the subscription after checkout

When the customer pays, Shopify creates the subscription, and the five properties are copied onto its line unchanged. Read the contract with the Admin API on your server to confirm:
On the storefront, the signed-in customer reads the same data from GET /apps/subscriptions/cp/api/subscription-customers-detail/valid/{customerId} (reference), where {customerId} is the customer’s numeric Shopify ID ({{ customer.id }} in Liquid). Each contract has a subscriptionContractId, and its contractDetailsJSON is a JSON string with one entry per line. Each entry has a lineId and the line’s customAttributes. The box line is the one whose customAttributes include _appstle-bb-id.

Step 4: Save a changed selection

To change what is in the box, send the new properties for the existing line. Don’t add a second line or a new subscription:
Send contractId and lineId in the query string and the properties as a JSON array in the body: On success the call returns 200 with the updated contract, in the same shape as the Step 3 response, and the line carries the new properties. The line ID doesn’t change and the customer still has one subscription. See Edit custom attributes on a single line item.

What the save checks

The app runs these checks before it saves a customer’s change. A failed check answers 400 with application/problem+json, and its title holds the message. The time-window, gift and frozen-subscription messages are written for the customer: show them without the UserGeneratedError: prefix. The others point to a problem in your request or the customer’s picks, so show your own text for them, such as “Choose between 1 and 4 items.” A customer can change only products, __appstle-bb-variants and _appstle-bb-product-sku. Every other Appstle property keeps its old value, whether you send it or not. Properties that aren’t Appstle’s, such as a gift message from another app, work differently: the line keeps exactly the ones you send, and a property you leave out is removed. Always send each existing one back unchanged. Adding, changing or leaving one out is refused only when the store has turned off Customers can edit custom details (Customer Portal → Customize portal → Features → Product attributes, shown when Show custom order and product details is on; its older name is Allow customers to edit attribute values). Until a store saves that setting, the API treats it as on: the portal hides its own edit control, but your call succeeds, and any property you left out is removed. Don’t rely on the setting to protect a property you didn’t send. A call without a signed-in customer answers 401. Storefront calls are rate limited per customer and per store: a call over a limit answers 429 with a Retry-After header, so wait that many seconds before you retry. Save once, when the customer confirms the new box, not on every change.
The time-window, frozen-subscription and edit-permission checks depend on the store’s customer portal settings. The other checks apply to every store.

Save from your server instead

The Admin API has an equivalent call for your own back office. It uses an API key and acts as the merchant, so none of the customer checks above run, including the box’s minimum and maximum. It replaces the line’s properties with exactly the list you send: send all five box properties and every other property the line should keep.
See Update line item attributes for a subscription contract.

Add a one-time extra

A customer can add an extra product to their next order, such as a gift or an extra bag, next to the box. Call Add a line item to a subscription contract with isOneTimeProduct set to true. The extra becomes its own line on the same subscription, and the box line keeps its properties. Each call adds a new line, even when the customer already added the same product as an extra, so a repeated call adds it twice. If a call times out, read the customer’s contracts again (the storefront call at the end of Step 3) and look for a line with the same variant and _appstle-one-time-product before you retry.
All four parameters go in the query string, and the call has no body: On success the call returns 200 with the updated contract. The extra is a new entry in lines.nodes that carries the property _appstle-one-time-product set to true:
What happens to the extra:
  • It stays on the subscription until the next order bills successfully, and Appstle then removes the line.
  • It’s charged at the product’s own price in the subscription’s currency. The subscription’s discount applies to it only when the store has turned on Customers can use subscription discounts on one-time products. On a prepaid subscription the price is multiplied by the number of deliveries in each billing period.
  • After the add, Appstle emails the customer about the new product unless the store has turned that email off. Appstle can also update the subscription’s shipping price after the call returns, so read the contract again before you show the next order’s total.
  • To remove it before then, call Remove a line item from a subscription contract with its line ID. That call is refused when the store has turned off Customers can remove products; the API doesn’t check Customers can remove one-time products. The gift, product-change window and prepaid checks below apply to it too, and so does the frozen-subscription check, with no exception for stores that allow adds while frozen.
  • The calls with one-offs in the path belong to an older mechanism: adding through them is discontinued, and they don’t list extras added this way. Read and remove the extra through the contract’s lines.

What the add checks

For a signed-in customer, the call refuses the add with a 400 when any of these fail. As in Step 4, the body is application/problem+json and its title holds the message. The minimum quantity, the product-change window and the frozen-subscription message are the store’s own settings, so the numbers and wording differ from store to store. Show the messages to the customer without the UserGeneratedError: prefix. Permission denied, Subscription cannot be modified means the store doesn’t let customers make this add, so stop offering extras on that subscription. Every add, including one from the Admin API, is also refused once the subscription has 50 lines (the default limit): UserGeneratedError: A subscription cannot contain more than 50 distinct products. Currently, there are 50 products. Each extra is a line until the next order, so remove extras the customer no longer wants. As in Step 4, a call without a signed-in customer answers 401, and a call over the rate limit answers 429 with a Retry-After header. From your server, the Admin API’s Add product to subscription takes the same isOneTimeProduct parameter, with an API key. It acts as the merchant, so of the checks above only the 50-line limit applies. If you later change an extra’s properties with Update line item attributes for a subscription contract, keep _appstle-one-time-product in the list: without it, the line stays on the subscription after the next order.

Next steps

Build your own frontend

Selling plans, the cart and the customer portal from your own UI.

JavaScript hooks

Events the widget fires that your code can listen to.

Authentication

Admin API keys and how storefront calls are authenticated.

Integration guide

Server-side calls for subscriptions and contracts.