0

When using the REST API to add products to the cart, you need to add a product_option.extension_attributes.configurable_item_options object to the cartItem payload (POST-ing to /V1/carts/mine/items). So far I got this working for simple products. Now I need to add products that have customizable options that are text fields, I tried sending that as following:

// product_option.extension_attributes.configurable_item_options
{
    "option_id": "16",
    "option_value": "Some text"
}

This returns the following error message: "Error occurred during \"product_option\" processing. Error occurred during \"extension_attributes\" processing. Error occurred during \"configurable_item_options\" processing. Error occurred during \"option_value\" processing. The \"Some text\" value's type is invalid. The \"int\" type was expected. Verify and try again."

If I change "Some text" to 0 it complains not all required options are set, and obviously I'm not passing my content anymore.

For reference; this is the actual option_id information retrieved from rest/V1/products/XX/options

{
    "product_sku": "XX",
    "option_id": 16,
    "title": "Text 1st line",
    "type": "field",
    "sort_order": 7,
    "is_require": true,
    "price": 0,
    "price_type": "fixed",
    "sku": "TEXT-ONE",
    "max_characters": 0,
    "image_size_x": 0,
    "image_size_y": 0
},

Also the full payload of the add-item request:

{
  "cartItem": {
    "sku": "HG-03",
    "qty": 1,
    "quote_id": "80",
    "product_option": {
      "extension_attributes": {
        "configurable_item_options": [
          {
            "option_id": "16",
            "option_value": "Some text"
          }
        ]
      }
    }
  }
}

So to sum it up: How to properly send the value for customisable text fields on products using the REST API in Magento 2.3?

1

Your payload should be something like this:

{
  "cartItem": {
    "sku": "HG-03",
    "qty": 1,
    "quote_id": "80",
    "product_option": {
      "extension_attributes": {
        "custom_options": [
          {
            "option_id": "16",
            "option_value": "Some text"
          }
        ]
      }
    }
  }
}

You are adding custom options, not configurable items options.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.