{"id":2594,"date":"2024-12-31T20:23:15","date_gmt":"2024-12-31T20:23:15","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/magento-2-api-create-an-invoice\/"},"modified":"2025-03-17T09:03:16","modified_gmt":"2025-03-17T09:03:16","slug":"magento-2-api-create-an-invoice","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-api-create-an-invoice\/","title":{"rendered":"Magento 2 API &#8211; Create an Invoice"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello Magento peeps!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I am back with another blog post on&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API<\/a>. My last blog post was about&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-create-order\/\" target=\"_blank\" rel=\"noreferrer noopener\">creating an order using Magento 2 API<\/a>. In this post, I will show you how to create an invoice using Magento 2 API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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&nbsp;<em><strong>Magento 2 API to create an invoice<\/strong><\/em>&nbsp;after the payment is received. In this post, I will show you how you can&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/auto-generate-invoices-and-shipments-for-backend-orders-in-magento-2\/\">generate invoices in Magento 2<\/a>&nbsp;using the REST API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, let\u2019s begin!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Create an Invoice Using REST API in Magento 2?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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:&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-admin-token\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Get Admin Access Token in Magento 2 Using REST API<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method:&nbsp;<\/strong>POST<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>URL:&nbsp;<\/strong><em>store_url\/rest\/V1\/order\/&lt;order_id&gt;\/invoice<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Headers:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Content-Type:&nbsp;<\/strong>application\/json<\/li>\n\n\n\n<li><strong>Authorization:&nbsp;<\/strong>Bearer &lt;admin token&gt;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Payload:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"capture\": true,\n  \"notify\": true\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Response:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It will return the invoice ID.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to View an Invoice Using REST API in Magento 2?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method:&nbsp;<\/strong>GET<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>URL:&nbsp;<\/strong><em>store_url\/rest\/V1\/invoices\/&lt;invoice_id&gt;<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Header:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Content-Type:&nbsp;<\/strong>application\/json<\/li>\n\n\n\n<li><strong>Authorization:&nbsp;<\/strong>Bearer &lt;admin token&gt;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Response:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It will return the invoice details, including the&nbsp;<em>order_item_id<\/em>, which can be further used to create a shipment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it! This is how you can create and view an invoice in Magento 2 using REST API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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!  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share this Magento 2 API guide with your developer friends via social media.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading.  <\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-create-order\/\">Magento 2 API \u2013 Create Order<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-create-cart-price-rule\/\">Magento 2 API &#8211; Create Cart Price Rule<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello Magento peeps! I am back with another blog post on&nbsp;Magento 2 API. My last blog post was about&nbsp;creating an order using Magento 2 API&#8230;.<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2594","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2594"}],"version-history":[{"count":1,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2594\/revisions"}],"predecessor-version":[{"id":3859,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2594\/revisions\/3859"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}