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)
tags:
  - name: Cart
paths:
  /cart:
    post:
      summary: Create Cart
      operationId: createCart
      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
      tags:
        - Cart
      security:
        - api_key: []
      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'
  /cart/{cid}:
    get:
      summary: Get Cart
      operationId: getCart
      description: |
        Get an existing cart by cart token. You can get a cart token by calling the Create Cart endpoint.

        ### Required API key scope
        - Carts
      tags:
        - Cart
      security:
        - api_key: []
      parameters:
        - in: path
          name: cid
          schema:
            type: string
          required: true
          description: The unique identifier token associated with a cart.
      responses:
        "200":
          description: "Success"
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Cart'
                  - $ref: '#/components/schemas/CartNotFound'
        "401":
          description: "Unauthorized"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedResponse'
    post:
      summary: Update Cart
      operationId: updateCart
      description: |
        Modify an existing cart. Note that the array of product variants included in the
        request will overwrite the cart's existing contents.

        ### Required API key scope
        - Carts
      tags:
        - Cart
      security:
        - api_key: []
      parameters:
        - in: path
          name: cid
          schema:
            type: string
          required: true
          description: The unique identifier token associated with a cart.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCartRequest'
      responses:
        "200":
          description: "Success"
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/UpdatedCart'
                  - $ref: '#/components/schemas/CartNotUpdated'
                  - $ref: '#/components/schemas/CartNotFound'
                  - $ref: '#/components/schemas/EmptyCart'
                  - $ref: '#/components/schemas/VariantNotFound'
                  - $ref: '#/components/schemas/InvalidCart'
        "401":
          description: "Unauthorized"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedResponse'
    delete:
      tags:
        - Cart
      summary: "Delete Cart"
      operationId: deleteCart
      security:
        - api_key: []
      description: |
        Delete an existing cart in Shop Now On-Store.

        ### Required API key scope
        - Carts
      parameters:
        - in: path
          name: cid
          schema:
            type: string
          required: true
          description: The unique identifier token associated with a cart.
      responses:
        "200":
          description: "Successful"
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/CartNotFound'
                  - $ref: '#/components/schemas/CartNotDeleted'
                  - $ref: '#/components/schemas/DeletedCart'
        "401":
          description: "Unauthorized"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedResponse'
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==
    UpdateCartRequest:
      type: object
      required:
        - cart
      properties:
        cart:
          type: array
          description: An array of product variant identifiers.
          items:
            $ref: "#/components/schemas/Variant"
    Cart:
      type: object
      properties:
        cart:
          description: An array of product variants representing the contents of the cart.
          type: array
          items:
            $ref: "#/components/schemas/Variant"
    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:
              type: array
              items:
                $ref: "#/components/schemas/Variant"
              description: An array of product variants representing the contents of the cart.
            shopify:
              type: string
              description: The Base64-encoded liquid cart object, if one was provided in the request.
              example: c2FtcGxlLXN0cmluZw==
    UpdatedCart:
      type: object
      properties:
        updated:
          type: boolean
          example: true
          description: Whether the cart was updated successfully.
        data:
          type: object
          properties:
            cart:
              type: array
              description: An array of product variants representing the contents of the cart.
              items:
                $ref: "#/components/schemas/Variant"
    DeletedCart:
      type: boolean
      example: true
      description: Whether the cart was deleted.
    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:
              type: array
              description: An array of product variants representing the contents of the cart.
              items:
                $ref: "#/components/schemas/Variant"
    CartNotFound:
      type: object
      properties:
        errors:
          type: object
          properties:
            message:
              type: string
              description: The error message returned when the cart token included in the request couldn't be found.
              example: 'No cart found for the provided token.'
    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:
              type: array
              description: An array of product variants representing the contents of the cart.
              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:
              type: array
              description: An array of product variants representing the contents of the cart.
              items:
                $ref: "#/components/schemas/Variant"
    CartNotUpdated:
      type: object
      properties:
        errors:
          type: object
          properties:
            message:
              type: string
              description: The error message returned when the cart couldn't be saved.
              example: 'Error saving cart update.'
        data:
          type: object
          properties:
            cart:
              type: array
              description: An array of product variants representing the contents of the cart.
              items:
                $ref: "#/components/schemas/Variant"
    CartNotDeleted:
      type: object
      properties:
        errors:
          type: object
          properties:
            message:
              type: string
              description: The error message returned when the cart couldn't be deleted.
              example: 'Failed to delete cart.'
    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'
