Create Invoice Via REST API for Magento2 for Bundle Product

To create an invoice for an order that contain bundle product you have to prepare the good json.

Basically Magento has two different types of bundle products: dynamic and fixed. That's why I need to add clarification for Expected Result:
I) Bundle dynamic product:

  1. request:
    { "items": [ {"order_item_id": (parent bundle order_item_id), "qty": 1} ] }
    response:
    {"message":"InvoiceDocument Validation Error(s):\nYou can't create an invoice without products."}
  2. request:
    { "items": [ {"order_item_id": (child bundle order_item_id), "qty": 1} ] }
    response:
    partial id of created invoice

II) Bundle fixed product:

  1. request:
    { "items": [ {"order_item_id": (child bundle order_item_id), "qty": 1} ] }
    response:
    {"message":"InvoiceDocument Validation Error(s):\nYou can't create an invoice without products."}
  2. request:
    { "items": [ {"order_item_id": (parent bundle order_item_id), "qty": 1} ] }
    response:
    id of created invoice

 

Example for Dynamic Bundle

Json Code:

{
  "items": [
    {
      "order_item_id": 150,
      "qty": 1
    },
    {
      "order_item_id": 152,
      "qty": 1
    }
  ]
}

where the second order_item_id is the child item_id

Endpoint = "/V1/order/{order_id}/invoice"

Method = "POST"