0

I have a query regarding following Magento2 API

POST "V1/invoices"

with payload

{
    "entity": {
        "base_discount_tax_compensation_amount": null,
        "base_shipping_discount_tax_compensation_amnt": null,
        "discount_tax_compensation_amount": null,
        "order_id": 58,
        "shipping_discount_tax_compensation_amount": 0,
        "total_qty": 2,
        "grand_total": 155,
        "subtotal": 150,
        "items": [
            {
                "base_discount_tax_compensation_amount": null,
                "discount_tax_compensation_amount": null,
                "order_item_id": 74,
                "sku": null,
                "qty": 56,
                "row_total": 150,
                "tax_amount": 152,
                "discount_amount": 23,
                "price": 154
            }
        ]
    }
}

Please clarify following points

  1. Am I supposed to set fields grand_total, subtotal on body level?

  2. Fields qty, row_total, tax_amount, discount_amount inside items array?

These fields are visible on invoice created on Magento2. Attaching screenshot of created invoice below:enter image description here

OR mentioning order_id and order_item_id should be enough??

OR there is some other way , Please do provide info.

1
  • I need your help, when i am generating invoice using same api, my status is pending only. It's not complete. Any idea about it?
    – Sahib
    Aug 22, 2016 at 11:51

1 Answer 1

1

the full json structure for this post you can find it http://devdocs.magento.com/swagger/index.html just click on salesInvoiceRepositoryV1 and then POST /V1/invoices/

i've made a test with the very least values and it created succesfully an nvoice:

{
  "entity": {
    "grandTotal": 54,
    "orderId": 4,
    "totalQty": 1,
    "items": [
      {
        "orderItemId": 5,
        "productId": 156,
        "qty": 1
      }
    ],
    "comments": [],
    "extensionAttributes": {}
  }
}

and got back:

{
  "base_discount_tax_compensation_amount": null,
  "base_shipping_discount_tax_compensation_amnt": null,
  "created_at": "2016-06-17 23:08:48",
  "entity_id": 6,
  "grand_total": 54,
  "discount_tax_compensation_amount": null,
  "increment_id": "000000006",
  "order_id": 4,
  "shipping_discount_tax_compensation_amount": null,
  "total_qty": 1,
  "updated_at": "2016-06-17 23:08:48",
  "items": [
    {
      "base_discount_tax_compensation_amount": null,
      "entity_id": 6,
      "discount_tax_compensation_amount": null,
      "order_item_id": 5,
      "parent_id": 6,
      "product_id": 156,
      "qty": 1,
      "sku": null
    }
  ],
  "comments": [],
  "extension_attributes": []
}

so to answer your questions:

  1. as you'll see from the devdocs grand_total and subtotal are the same level with items ( so per invoice and not invoice item)
  2. yes to all of them and in my test if order_id or order_item_id where missing i got in exception so these are needed.

at this point is up to you to have consistent values inside grandTotal, etc.

2
  • When i create invoice for bundle product,how to pass payload in this api. Sep 18, 2018 at 6:45
  • If you have multiple items,then we will create partial invoice of single item.In this case how to information about grandTotal,discount_amount, tax_amount and price after discount in magento-2.1. Sep 18, 2018 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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