Overview

Function API allows developers to customize and extend the cart and checkout processes by injecting their own pricing logic. To ensure compatibility, the function must adhere to a strict input and output structure.

Cart Input and Output Rules

Cart Input Structure

The function receives structured input data when triggered by the cart or checkout process.

FieldTypeRequiredDescription
cartobjectYesThe shopping cart object
cart.line_itemsarrayYesThe list of items in the cart
productobjectYesThe product information
product.product_idstringYesProduct ID
product.variant_idstringYesVariant ID
product.pricestringYesProduct price
product.product_titlestringYesProduct title
product.metafieldsarray of objectYesA list of metafields associated with the product
Allows users to store additional custom data
idstringYesLine item ID
quantitystringYesQuantity of the item
propertiesstringYesCustom attributes defined by the user

Metafield Definition

Metafield is optional but plays a crucial role in the price adjustment function.

  • Product Metafields can be used to store custom pricing rules, discount strategies, and other extended information.
  • Since functions cannot directly request data from the developer’s own server, using Metafields as a storage method is essential.
FieldTypeRequiredDescription
namespacestringYesA container for a set of metafields. Grouping metafields within a namespace prevents conflicts with other metafields that have the same key name.
keystringYesThe key of the metafield.
valuemixedYesThe data stored in the metafield.

Cart-Transform Input Example

{
    "cart": {
        "line_items": [
            {
                "product": {
                    "product_id": "1231",
                    "variant_id": "1231",
                    "price": "10.00",
                    "title": "test product",
                    "metafields": [
                        {
                            "namespace": "custom-option",
                            "key": "adjust-10-price",
                            "value": "true"
                        }
                    ]
                },
                "id": "1",
                "quantity": 1,
                "properties": "{\"Color\":\"Red\"}"
            }
        ]
    }
}

 

Cart Output Structure

Overview

The output of a Function API execution determines how the system should update relevant data. This is returned in a structured JSON format containing an operations object. The operations define changes such as modifying prices, adjusting inventory, or updating order statuses.

General Output Structure

Note:

  • If multiple operations are performed on the same cart line ID, the system only executes the first operation in the list.
  • Any subsequent update operations for the same ID will be discarded.

Fields Definition

FieldTypeRequiredDescription
operationsarray of operation objectYesShopping cart operation
operations.updatearray of update objectNoList of update operations
operations.update.idstringYesCart line ID
operations.update.pricePrice objectYesIf adjustment_fixed_price is less than 0, the update will not be applied.
If the specified cart line ID does not exist, the update will not be applied.
operations.update.price.
adjustment_fixed_price
stringYesCustom price: Must be within the range [0, 999999999]. The specified amount is added to the product price for price adjustment.

Cart-Transform Output Example

{
    "operations": {
        "update": [
            {
                "id": "1",
                "price": {
                    "adjustment_fixed_price": "10.00"
                }
            }
        ]
    }
}