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?

asked Apr 7, 2021 at 8:53

1 Answer 1

2

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.

answered Apr 7, 2021 at 10:27
2
  • 1
    Thank you so much! Commented Apr 7, 2021 at 14:04
  • you are most welcome! Commented Apr 8, 2021 at 6:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.