> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loopreturns.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Cart

> Create a cart object and populate it with one or more product variants.
Quantities are not supported — repeat a variant ID to represent a quantity
greater than one.

> 📘 Optional `shopify` snapshot
>
> The `shopify` field is optional and only needed when the shop is configured
> to use Shopify Scripts. Most headless stores can omit it.

### Required API key scope
- Carts (must be the only scope on the key)




## OpenAPI

````yaml post /cart
openapi: 3.1.0
info:
  title: Cart API (On-Store)
  description: This API can be used to manage your shop's carts.
  version: v1
servers:
  - url: https://api.loopreturns.com/api/2026-10
    description: 2026-10 (Stable)
  - url: https://api.loopreturns.com/api/2026-07
    description: 2026-07
  - url: https://api.loopreturns.com/api/unstable
    description: Unstable (Preview)
security: []
tags:
  - name: Cart
paths:
  /cart:
    post:
      tags:
        - Cart
      summary: Create Cart
      description: >
        Create a cart object and populate it with one or more product variants.

        Quantities are not supported — repeat a variant ID to represent a
        quantity

        greater than one.


        > 📘 Optional `shopify` snapshot

        >

        > The `shopify` field is optional and only needed when the shop is
        configured

        > to use Shopify Scripts. Most headless stores can omit it.


        ### Required API key scope

        - Carts (must be the only scope on the key)
      operationId: createCart
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCartRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/CreatedCart'
                  - $ref: '#/components/schemas/EmptyCart'
                  - $ref: '#/components/schemas/VariantNotFound'
                  - $ref: '#/components/schemas/CartNotSaved'
                  - $ref: '#/components/schemas/InvalidCart'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedResponse'
      security:
        - api_key: []
components:
  schemas:
    CreateCartRequest:
      type: object
      required:
        - cart
      properties:
        cart:
          type: array
          items:
            $ref: '#/components/schemas/Variant'
          description: An array of product variants.
        shopify:
          description: >
            A Base64-encoded cart snapshot, used to reflect additional
            transaction

            details from the commerce provider (e.g. Shopify) such as automatic

            discounts. Optional — most integrations can omit it.


            Loop only consumes this snapshot server-side when the shop is
            configured

            to use Shopify Scripts. When decoded, it is a JSON object shaped
            like a

            subset of the Shopify Ajax cart (`/cart.js`), including `currency`,

            `total_price`, `total_discount`, `cart_level_discount_applications`,
            and

            per-line `items[]`. Headless storefronts that don't use Shopify
            Scripts

            should omit this field.
          type: string
          example: c2FtcGxlLXN0cmluZw==
    CreatedCart:
      type: object
      properties:
        token:
          type: string
          example: 46923497728c9a7b5o8a433zz5c0bbbb683319824778
          description: The cart's unique identifier.
        data:
          type: object
          description: Echoes the contents of the create request.
          properties:
            cart:
              description: >-
                An array of product variants representing the contents of the
                cart.
              type: array
              items:
                $ref: '#/components/schemas/Variant'
            shopify:
              type: string
              description: >-
                The Base64-encoded liquid cart object, if one was provided in
                the request.
              example: c2FtcGxlLXN0cmluZw==
    EmptyCart:
      type: object
      properties:
        errors:
          type: object
          properties:
            message:
              type: string
              description: >-
                The error message returned when an attempt is made to create an
                empty cart.
              example: Cart is empty.
        data:
          type: object
          properties:
            cart:
              type: array
              description: An array of product variant IDs (empty if cart is empty).
              items:
                $ref: '#/components/schemas/Variant'
    VariantNotFound:
      type: object
      properties:
        errors:
          type: object
          properties:
            message:
              type: string
              description: >-
                The error message returned when one of the product variants
                included in the request couldn't be found.
              example: Variant ID 777777 not found.
        data:
          type: object
          properties:
            cart:
              description: >-
                An array of product variants representing the contents of the
                cart.
              type: array
              items:
                $ref: '#/components/schemas/Variant'
    CartNotSaved:
      type: object
      properties:
        errors:
          type: object
          properties:
            message:
              type: string
              description: The error message returned when the cart couldn't be created.
              example: There was an error attempting to create the cart.
        data:
          type: object
          properties:
            cart:
              description: >-
                An array of product variants representing the contents of the
                cart.
              type: array
              items:
                $ref: '#/components/schemas/Variant'
    InvalidCart:
      type: object
      properties:
        errors:
          type: object
          properties:
            message:
              type: string
              description: >-
                The error message returned when the request includes one or more
                invalid variant IDs.
              example: Cart should contain a list of variant IDs.
        data:
          type: object
          properties:
            cart:
              description: >-
                An array of product variants representing the contents of the
                cart.
              type: array
              items:
                $ref: '#/components/schemas/Variant'
    UnauthorizedResponse:
      type: object
      required:
        - errors
      properties:
        errors:
          type: string
          example: Unauthorized.
    Variant:
      description: >-
        A product variant, provided either as a plain variant ID or as an object
        with a `variant_id`.
      oneOf:
        - type: integer
          description: The unique identifier associated with a product variant.
          example: 39076568408247
        - type: object
          properties:
            variant_id:
              type: integer
              description: The unique identifier associated with a product variant.
              example: 39076568408247
          required:
            - variant_id
  securitySchemes:
    api_key:
      type: apiKey
      name: X-Authorization
      in: header

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.