Magento 2 API – Create an Invoice

Hello Magento peeps!

I am back with another blog post on Magento 2 API. My last blog post was about creating an order using Magento 2 API. In this post, I will show you how to create an invoice using Magento 2 API.

An invoice is the receipt of payment made by the customer, which contains complete details about the order payment. In Magento 2, invoices are generated as soon as the payment is completed, which also acknowledges the customers about the payment. If you are developing another storefront based on Magento 2, you can use the Magento 2 API to create an invoice after the payment is received. In this post, I will show you how you can generate invoices in Magento 2 using the REST API.

So, let’s begin!

How to Create an Invoice Using REST API in Magento 2?

In Magento 2, the order invoice can be generated soon after the payment is captured. Invoice generation requires admin-level access, and therefore the client needs to pass the admin access token along with the API request. You can also refer to this blog: How to Get Admin Access Token in Magento 2 Using REST API.

Generating invoice in Magento 2 using API is really easy. The client just needs to pass the order number in the request URL using a POST request.

Method: POST

URL: store_url/rest/V1/order/<order_id>/invoice

Headers:

  • Content-Type: application/json
  • Authorization: Bearer <admin token>

Payload:

Response:

It will return the invoice ID.

How to View an Invoice Using REST API in Magento 2?

You can use the Magento 2 API to view the invoice once it is generated. The client needs to pass the invoice ID to the API endpoint to view the invoice along with the API admin access token.

Method: GET

URL: store_url/rest/V1/invoices/<invoice_id>

Header:

  • Content-Type: application/json
  • Authorization: Bearer <admin token>

Response:

It will return the invoice details, including the order_item_id, which can be further used to create a shipment.

That’s it! This is how you can create and view an invoice in Magento 2 using REST API.

Conclusion

If you are creating a new storefront or mobile app based on Magento 2, you may require to use the Magento 2 API to create and view an invoice after the payment is successful. I hope this blog post will guide you through the Magento 2 API. In case you still have any doubts or queries, feel free to comment. I will be happy to help you! 😃

Also, do not forget to share this Magento 2 API guide with your developer friends via social media. 😊

Thanks for reading. 🍀

◄ Magento 2 API – Create OrderComing Soon ►

5
(based on 5 Reviews)
Magento 2 API – Create an InvoiceAuthor Magento Badge

Jignesh Parmar

An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.

Leave a Reply

Your email address will not be published.