Create and query nested cart lines
Anchor to Creating nested cart linesCreating nested cart lines
You can add a nested cart line from a variety of Shopify APIs:
Anchor to Query for nested cart linesQuery for nested cart lines
Nested cart lines are represented across the following APIs:
- Cart Ajax API
- Checkout UI Extension API
- Function API
- Liquid API
- Order API
- Storefront API
- Webhook API
Anchor to Create nested cart linesCreate nested cart lines
To create a nested cart line, specify a parent
in the API input.
Anchor to Storefront APIStorefront API
Use the parent
field in the cart mutation input. You can reference the parent by lineId
(for existing line items in the cart) or merchandiseId
(for adding both parent and nested cart lines in the same request).
- Only one of
lineId
ormerchandiseId
should be used per line. - The response will return the nested cart line with a reference to its parent cart line under the
parentRelationship
object.
Example: Add TV and attach Warranty as an add-on
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
Variables
JSON response
Anchor to Cart AJAX APICart AJAX API
You can reference the parent by specifying a parent_line_key
(for existing line items in the cart) or parent_id
(for adding both parent and nested cart lines in the same request) in the API input.
Notes:
- Only one of
parent_line_key
orparent_id
should be used per line. - The response will return the nested cart line with a reference to its parent cart line under the
parent_relationship
object.
Example: Add TV and attach a warranty as an add-on.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
Variables
JSON response
Anchor to Checkout UI ExtensionCheckout UI Extension
Example: Add a warranty as an add-on to a product in the cart
Preact
Anchor to Next stepsNext steps
- Learn how to build an add-ons app