create invoice with api

Magento 2 API (Updated 2024): Create an Invoice

Learn how to create an invoice for an order using Magento 2 API. A detailed explanation of the purchase will be sent to the customer when you receive payment.

Step 1: Capture payment

Endpoint: POST <host>/rest/V1/order/19/invoice

19 is the order id. Learn how to create an order here.

Authorization: Bearer token – Admin

Payload:

{
  "capture": true,
  "notify": true
}Code language: JSON / JSON with Comments (json)

Response:

An invoice ID, here is 4

capture payment by Magento 2 API

Step 2: View the invoice

Basically, the invoice is similar to the order, except the order contains more details. Create a new request with this endpoint.

Endpoint: GET<host>/rest/V1/invoices/4

Authorization: Bearer token – Admin

Response:

{
    "base_currency_code": "USD",
    "base_discount_amount": 0,
    "base_grand_total": 91,
    "base_discount_tax_compensation_amount": 0,
    "base_shipping_amount": 10,
    "base_shipping_discount_tax_compensation_amnt": 0,
    "base_shipping_incl_tax": 10,
    "base_shipping_tax_amount": 0,
    "base_subtotal": 81,
    "base_subtotal_incl_tax": 81,
    "base_tax_amount": 0,
    "base_to_global_rate": 1,
    "base_to_order_rate": 1,
    "billing_address_id": 38,
    "can_void_flag": 0,
    "created_at": "2020-10-23 09:11:41",
    "discount_amount": 0,
    "email_sent": 1,
    "entity_id": 4,
    "global_currency_code": "USD",
    "grand_total": 91,
    "discount_tax_compensation_amount": 0,
    "increment_id": "000000004",
    "order_currency_code": "USD",
    "order_id": 19,
    "shipping_address_id": 37,
    "shipping_amount": 10,
    "shipping_discount_tax_compensation_amount": 0,
    "shipping_incl_tax": 10,
    "shipping_tax_amount": 0,
    "state": 2,
    "store_currency_code": "USD",
    "store_id": 1,
    "store_to_base_rate": 0,
    "store_to_order_rate": 0,
    "subtotal": 81,
    "subtotal_incl_tax": 81,
    "tax_amount": 0,
    "total_qty": 3,
    "updated_at": "2020-10-23 09:11:41",
    "items": [{
        "base_discount_tax_compensation_amount": 0,
        "base_price": 22,
        "base_price_incl_tax": 22,
        "base_row_total": 22,
        "base_row_total_incl_tax": 22,
        "base_tax_amount": 0,
        "entity_id": 4,
        "discount_tax_compensation_amount": 0,
        "name": "Argus All-Weather Tank",
        "parent_id": 4,
        "price": 22,
        "price_incl_tax": 22,
        "product_id": 783,
        "row_total": 22,
        "row_total_incl_tax": 22,
        "sku": "MT07-M-Gray",
        "tax_amount": 0,
        "order_item_id": 46,
        "qty": 1
    }, {
        "base_price": 0,
        "entity_id": 5,
        "name": "Argus All-Weather Tank-M-Gray",
        "parent_id": 4,
        "price": 0,
        "product_id": 780,
        "sku": "MT07-M-Gray",
        "order_item_id": 47,
        "qty": 1
    }, {
        "base_discount_tax_compensation_amount": 0,
        "base_price": 59,
        "base_price_incl_tax": 59,
        "base_row_total": 59,
        "base_row_total_incl_tax": 59,
        "base_tax_amount": 0,
        "entity_id": 6,
        "discount_tax_compensation_amount": 0,
        "name": "Fusion Backpack",
        "parent_id": 4,
        "price": 59,
        "price_incl_tax": 59,
        "product_id": 89,
        "row_total": 59,
        "row_total_incl_tax": 59,
        "sku": "24-MB02",
        "tax_amount": 0,
        "order_item_id": 48,
        "qty": 1
    }],
    "comments": []
}Code language: JSON / JSON with Comments (json)
view invoice

You will use the response values to create a shipment in the next step.

Step 3: Verify the invoice

After the creation of the invoice, you can check it in the admin panel sales order grid.

Log in to your Magento admin. Then go to Sales, choose Invoices. Search for the invoice, the status should be paid. Go to Sales, choose Orders, the status now should be Processing.

invoice view on admin

In this way, you can create an invoice for a particular order using Magento API. After that, the values will be used to create a shipment. For more information, please refer to Magento DevDocs.