Magento2 Rest APIs: add a bundle to cart

Yeah, with Magento2 it’s hard even to perform some common tasks.

Here’s how to add a bundle to an existent cart.

Let’s assume that our bundle has bundle01 as its SKU.

First of all, we need to get some info that we are going to pass as parameters later.

GET /products/bundle01?searchCriteria

Here, we need to take note of some info.

First of all, in the extension_attributes section, take note of the various option_id fields in the bundle_product_options section.

Let’s assume that our options_id are 643, 644, 645.

Now, let’s look at the product_links section, and take note of the various id values.

  • adsense



  • Let’s assume that our ids are 704,705,706.

    Now we are ready for our call:

    POST /carts/mine/items
    {
    "cart_item": {
        "quote_id": <quote_id>,
        "sku": "bundle-01",
        "qty": 1,
        "product_option": {
        "extension_attributes": {
            "bundle_options": [{
                "option_id": 643,
                "option_qty": 1,
                "option_selections": [704]
                }, {
                "option_id": 644,
                "option_qty": 1,
                "option_selections": [705]
                }, {
                "option_id": 645,
                "option_qty": 1,
                "option_selections": [706]
                }]
            }
        }
    }
    }
    

     

    Leave a Comment

    Your email address will not be published. Required fields are marked *