0

For a webshop project, I'm using Snipcart V 3.0

I can successfully add an item to the cart using the JavaScript SDK:

await Snipcart.api.cart.items.add({
    id: 'myId',
    name: 'myName',
    price: 0.00,
    url: 'myURL',
    image: 'myImage',
    quantity: 1,
    maxQuantity: 2,
    customFields: [{
        "name": "MycustomName",
        "value": "MyCustomValue"
    }]
});

This works, but custom fields do not show up. What I am doing wrong here? How can I add custom fields programmatically?

The documentations states:

The add method adds an item to the cart. It can take a ProductDefinition
or an array of ProductDefinition as an argument

Product definition reference found at https://docs.snipcart.com/v3/sdk/reference#core-models-ProductDefinition isn't really helpful with respect to customFields.

Any help is appreciated!

  • Do you get any error back? Looking at the documentation, it seems that the `type` parameter is required for ProductDefinition. – drnugent Jul 18 '20 at 21:37
  • No, adding the ``type`` parameter didn't cure the problem. All I'm getting on the console is: DevTools failed to load SourceMap: Could not load content for https://cdn.snipcart.com/themes/v3.0.16/default/app.37f83f27.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE – Andreas Deininger Jul 19 '20 at 07:11

1 Answers1

1

The typing for the customFields property is an array of CustomField.

type is indeed required, but you'll need to set type:"textbox"