Function Input and Output Protocol

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.

Field

Type

Required

Description

cart

object

Yes

The shopping cart object

cart.line_items

array

Yes

The list of items in the cart

product

object

Yes

The product information

product.product_id

string

Yes

Product ID

product.variant_id

string

Yes

Variant ID

product.price

string

Yes

Product price

product.product_title

string

Yes

Product title

product.metafields

array of object

Yes

A list of metafields associated with the product
Allows users to store additional custom data

id

string

Yes

Line item ID

quantity

string

Yes

Quantity of the item

properties

string

Yes

Custom 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

Field

Type

Required

Description

operations

array of operation object

Yes

Shopping cart operation

operations.update

array of update object

No

List of update operations

operations.update.id

string

Yes

Cart line ID

operations.update.price

Price object

Yes

If 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

string

Yes

Custom 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"
                }
            }
        ]
    }
}