Cart
Create and change the cart, and read the delivery options and dates for it.
subbly.cart is both the data and the methods. It carries every cart field
straight on the object โ subbly.cart.id, subbly.cart.items,
subbly.cart.total โ and the methods below change it. Each of those methods
copies the response onto the same object and resolves with it, so the value you
await and subbly.cart are one and the same. There is only ever one cart per
SDK instance, and fields the response leaves out keep their old values.
Amounts are whole numbers in the minor unit of the cart currency; see Amounts and dates.
Most methods take an optional params.expand list; the values it accepts are
under Expand parameters.
Creates a new cart and stores its ID in the subbly_cart_id cookie for 365
days. It replaces whatever cart the SDK already held, so call it once, and use
subbly.cart.load to come back to a cart you already have.
The cookie is a plain one on path=/, with no Secure, HttpOnly or
SameSite attribute.
Method parameters
payloadoptionalCartCreatePayloadWhat the new cart starts with. Pass null or leave it out for an empty
cart. The TypeScript type is the wider update payload, but the create
endpoint reads only the four fields below; set anything else with
subbly.cart.update afterwards.
paramsoptionalCartResourceParamsRelations to include.
expandoptionalstring[]The relations to fill in. The values are listed at the top of this page.
ReturnsPromise<CartModel>
The cart, which is subbly.cart itself.
Create a cart
Create a cart in a currency, with a coupon
Loads a cart by ID into subbly.cart. Leave the ID out to refresh the cart the
SDK already holds.
Unlike create, this does not write the cookie. Subbly.init writes it itself
after a successful load.
Method parameters
cartIdoptionalstringUUID of the cart. Leave it out to reload the cart already held. With no ID and
no cart held, the call throws Error('Cart ID is required') at once, without
reaching the network.
paramsoptionalCartResourceParamsRelations to include.
expandoptionalstring[]The relations to fill in. The values are listed at the top of this page.
ReturnsPromise<CartModel>
The cart, which is subbly.cart itself. Its fields are written out under
Create a cart.
Load a cart by ID
Refresh the cart in hand
Changes the cart itself rather than its items: who is buying, where it ships, how it ships, which discounts apply, and when a subscription starts. Send only the fields you change.
Most of it works for a guest. Three fields point at records only a signed-in
customer has: paymentMethodId, shippingAddressId and billingAddressId.
Method parameters
payloadRequiredCartUpdatePayloadThe fields to change. Every one is optional.
paramsoptionalCartResourceParamsRelations to include.
expandoptionalstring[]The relations to fill in. The values are listed at the top of this page.
ReturnsPromise<CartModel>
The updated cart, which is subbly.cart itself. Its fields are written out
under Create a cart.
Set the guest details
Set the delivery address and the method
Remove the coupon
Adds a product, a plan or a bundle to the cart. Adding the same one-time item again raises its quantity instead of making a second line.
The payload has a shape per kind of item. All three share productId,
quantity and metadata; the rest depends on what you are adding.
Method parameters
payloadRequiredCartItemAddPayloadThe item to add.
paramsoptionalCartResourceParamsRelations to include.
expandoptionalstring[]The relations to fill in. The values are listed at the top of this page.
ReturnsPromise<CartModel>
The updated cart, which is subbly.cart itself. Its fields are written out
under Create a cart. The call rejects with code: 'out_of_stock'
when the product ran out.
Add a one-time product
Add a subscription with survey answers
Add a bundle
Changes one line in the cart: the quantity, the survey answers, the gift details or the bundle contents. To change which product a line is for, remove it and add the new one.
Method parameters
cartItemIdRequiredstringUUID of the line, from cart.items[].id.
payloadRequiredCartResourceUpdateItemPayloadWhat to change. Every field is optional, and the shape follows the kind of item the line holds.
paramsoptionalCartResourceParamsRelations to include.
expandoptionalstring[]The relations to fill in. The values are listed at the top of this page.
ReturnsPromise<CartModel>
The updated cart, which is subbly.cart itself. Its fields are written out
under Create a cart.
Change the quantity
Removes one line from the cart.
Method parameters
cartItemIdRequiredstringUUID of the line, from cart.items[].id.
paramsoptionalCartResourceParamsRelations to include.
expandoptionalstring[]The relations to fill in. The values are listed at the top of this page.
ReturnsPromise<CartModel>
The updated cart, which is subbly.cart itself. Its fields are written out
under Create a cart.
Remove an item
Gets the dates on which the subscription in the cart can start. Send the one the
customer picks to subbly.cart.update as startsAt.
It uses the cart the SDK holds, so load or create a cart first.
ReturnsPromise<CartResourceStartDatesResponse>
The dates allowed. The API fills one of the two fields and sets the other to
null: a fixed list of dates, or an open range. Handle both.
Get the start dates
Gets the dates on which a gift subscription in the cart can start. Send the one
the customer picks to subbly.cart.update as giftInfo.startsAt.
ReturnsPromise<CartResourceGiftingDatesResponse>
The dates allowed, in the same shape subbly.cart.getStartDates returns.
Get the gifting dates
Gets the delivery options available for the cart at a destination. Send the ID
of the one the customer picks to subbly.cart.update as shippingMethodId.
Only countryId and zip are needed. Pass the rest when a carrier quotes on
the full address.
Method parameters
paramsRequiredCartShippingMethodsParamsWhere the order is going.
ReturnsPromise<ShippingMethodDelivery[]>
The delivery options. Read type first: it is shipping_option for a carrier
delivery and local_delivery for the shop's own, and it decides which of the
fields below are set.
Get the shipping methods
Gets the pick-up points available for the cart. Send the ID of the one the
customer picks to subbly.cart.update as shippingMethodId, along with
pickupInfo for who collects the order.
ReturnsPromise<ShippingMethodPickup[]>
The pick-up points. The array is empty when the shop offers none.
Get the pick-up points
Assigns the cart to the signed-in customer. It sets attached to true and
customerId to their ID, and clears the guest details in customer. Call it
after the customer signs in and before you charge the cart.
It needs a signed-in customer.
Method parameters
paramsoptionalCartResourceParamsRelations to include.
expandoptionalstring[]The relations to fill in. The values are listed at the top of this page.
ReturnsPromise<CartModel>
The attached cart, which is subbly.cart itself. Its fields are written out
under Create a cart.
Attach the customer after a log-in