How to use customFields property in product definition when using the ADD item to cart method?

I need to attach a unique JSON string with each item in an order. Is it possible to use customFields? If so, where would it appear in the dashboard when I process the order.

// add item to cart
async function add_planner_toCart(planner_data){
  try {
    let response_msg = await Snipcart.api.cart.items.add({
        id: 'Custom-Treeplanner',
        name: 'Custom Planner',
        price: 44.99,
        url: '/planner',
        quantity: 1,
        minQuantity: 1,
        stackable: 'never',
        customField: JSON.stringify(planner_data),
    });
    console.log(response_msg)
  } catch (error) {
      console.log(error)
  }
}

And does adding an item entirely in javascript change the security?

I found that the customFields property takes an array of objects. Is there more detail anywhere in the docs?

Hi there,

Here is an example:

Snipcart.api.cart.items.add({
        id: 'Custom-Treeplanner',
        name: 'Custom Planner',
        price: 44.99,
        url: '/planner',
        quantity: 1,
        minQuantity: 1,
        stackable: 'never',
 "customFields": [
                {
                    "name": "test",
                    "placeholder": "",
                    "displayValue": "",
                    "type": "textbox",
                    "options": "",
                    "required": false,
                    "value": "",
                    "operation": null,
                    "optionsArray": null
                },
                {
                    "name": "dropdown",
                    "placeholder": "",
                    "displayValue": "test",
                    "type": "dropdown",
                    "options": "test|test2",
                    "required": false,
                    "value": "test",
                    "operation": null,
                    "optionsArray": [
                        "test",
                        "test2"
                    ]
                }
            ]
    })
1 Like