{"id":2586,"date":"2024-12-31T20:23:00","date_gmt":"2024-12-31T20:23:00","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/magento-2-api-set-shipping-billing-information\/"},"modified":"2025-04-24T09:44:52","modified_gmt":"2025-04-24T04:14:52","slug":"magento-2-api-set-shipping-billing-information","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-api-set-shipping-billing-information\/","title":{"rendered":"Magento 2 API &#8211; Set Shipping &#038; Billing Information"},"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 tutorial on&nbsp;<em><strong>Magento 2 API \u2013 Set Shipping &amp; Billing Information<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My last blog post of the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API<\/a>&nbsp;series was all about creating a cart and adding products to it. In case you missed reading it, check it out at&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-create-cart-add-products-to-cart\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API \u2013 Create Cart &amp; Add Products to Cart<\/a>. This blog post is all about preparing the cart for checkout by entering the shipping &amp; billing details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s go!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Magento 2 API to Prepare for Checkout<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Your customer has already added their desired products to the cart and willing to place the order. Now what? You need to get the billing and shipping information from the customers and display the appropriate shipping methods along with costs to them. You can use this complete guide on preparing the customer for checkout by setting the shipping and billing information through Magento 2 API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Estimate Shipping Costs&nbsp;Using Magento 2 Rest API<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In order to display the available shipping methods and&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/configure-magento-2-shipping-table-rates\/\" target=\"_blank\" rel=\"noreferrer noopener\">estimate the shipping costs<\/a>, Magento 2 needs the billing and shipping information from the client. You can use the&nbsp;<em>store_url\/rest\/V1\/carts\/mine\/estimate-shipping-methods&nbsp;<\/em>endpoint to send the information through a POST request along with the customer access token and fetch the required details. You can refer to the example provided below for a better understanding of Magento 2 API for setting shipping &amp; billing information:<\/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\/carts\/mine\/estimate-shipping-methods<\/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>Bearer Token:<\/strong>&nbsp;&lt;Customer_token&gt;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Body:<\/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=\"\">{    \"address\": {\n      \"region\": \"Gujarat\",\n      \"region_id\": 544,\n      \"region_code\": \"GJ\",\n      \"country_id\": \"IN\",\n      \"street\": [\n        \"Shiv Elite\"\n        ],\n      \"postcode\": \"364001\",\n      \"city\": \"Bhavnagar\",\n      \"firstname\": \"Sanjay\",\n      \"lastname\": \"Jethva\",\n      \"customer_id\": 1,\n      \"email\": \"sanjay@gmail.com\",\n      \"telephone\": \"8141102201\",\n      \"same_as_billing\": 1\n  }\n}\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/06\/Estimate-Shipping-Costs-1.png\" alt=\"Estimate Shipping Costs\" class=\"wp-image-50671\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Response:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Magento 2 authorizes the request through the customer access token and replies with the available shipping methods and estimated costs according to the information submitted in the request. An example of the response is provided below:<\/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    {\n        \"carrier_code\": \"freeshipping\",\n        \"method_code\": \"freeshipping\",\n        \"carrier_title\": \"Free Shipping\",\n        \"method_title\": \"Free\",\n        \"amount\": 0,\n        \"base_amount\": 0,\n        \"available\": true,\n        \"error_message\": \"\",\n        \"price_excl_tax\": 0,\n        \"price_incl_tax\": 0\n    },\n \n    {\n        \"carrier_code\": \"flatrate\",\n        \"method_code\": \"flatrate\",\n        \"carrier_title\": \"Flat Rate\",\n        \"method_title\": \"Fixed\",\n        \"amount\": 10,\n        \"base_amount\": 10,\n        \"available\": true,\n        \"error_message\": \"\",\n        \"price_excl_tax\": 10,\n        \"price_incl_tax\": 10\n    }\n]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you can use the response of the API request to display all the available shipping methods along with costs to the customers on the frontend.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Set Shipping &amp; Billing Information Using Magento 2 REST API<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In the next step, the customer selects his\/her preferred shipping method, enters the shipping &amp; billing information, and proceeds to checkout. You can use the&nbsp;<em>store_url\/V1\/carts\/mine\/shipping-information&nbsp;<\/em>and send the information through a POST request to fetch the payment information. Not to mention that this API requires customer access, and therefore, the client needs to pass the access token for authorization. You can refer to the example provided below for more details:<\/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\/V1\/carts\/mine\/shipping-information<\/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>Bearer Token:<\/strong>&nbsp;&lt;Customer_token&gt;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Body:<\/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=\"\">{  \"addressInformation\": {\n      \"shipping_address\": {\n       \"region\": \"Gujarat\",\n       \"region_id\": 580,\n       \"region_code\": \"GJ\",\n       \"country_id\": \"IN\",\n       \"street\": [\n   \"Shiv Elite\"\n ],\n \"postcode\": \"364001\",\n \"city\": \"Bhavnagar\",\n \"firstname\": \"Jignesh\",\n \"lastname\": \"Parmar\",\n \"email\": \"jignesh.meetanshi@gmail.com\",\n \"telephone\": \"8141102201\"\n  },\n  \"billing_address\": {\n      \"region\": \"Gujarat\",\n       \"region_id\": 580,\n       \"region_code\": \"GJ\",\n       \"country_id\": \"IN\",\n       \"street\": [\n   \"Shiv Elite\"\n ],\n \"postcode\": \"364001\",\n \"city\": \"Bhavnagar\",\n \"firstname\": \"Jignesh\",\n \"lastname\": \"Parmar\",\n \"email\": \"jignesh.meetanshi@gmail.com\",\n \"telephone\": \"8141102201\"\n  },\n  \"shipping_carrier_code\": \"flatrate\",\n  \"shipping_method_code\": \"flatrate\"\n  }\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/06\/Magento-2-API-Shipping-Billing-Information-1.png\" alt=\"Magento 2 API Shipping Billing Information\" class=\"wp-image-50674\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Res<\/strong><strong>p<\/strong><strong>onse:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On successful authorization of the request, Magento 2 will respond back with all the available payment options that you can display to the customers on the frontend.<\/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    {\n        \"carrier_code\": \"freeshipping\",\n        \"method_code\": \"freeshipping\",\n        \"carrier_title\": \"Free Shipping\",\n        \"method_title\": \"Free\",\n        \"amount\": 0,\n        \"base_amount\": 0,\n        \"available\": true,\n        \"error_message\": \"\",\n        \"price_excl_tax\": 0,\n        \"price_incl_tax\": 0\n    },\n    {\n        \"carrier_code\": \"flatrate\",\n        \"method_code\": \"flatrate\",\n        \"carrier_title\": \"Flat Rate\",\n        \"method_title\": \"Fixed\",\n        \"amount\": 5,\n        \"base_amount\": 5,\n        \"available\": true,\n        \"error_message\": \"\",\n        \"price_excl_tax\": 5,\n        \"price_incl_tax\": 5\n    }\n]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Shipping and billing information are vital for estimating the shipping costs and displaying the available payment methods in Magento 2. I hope this&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API<\/a>&nbsp;tutorial will help you prepare the customers for checkout using API. In case you still have any doubts or queries regarding the provided solution, feel free to comment. I will be happy to help. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share this useful Magento 2 API tutorial 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-cart-add-products-to-cart\/\">Magento 2 API &#8211; Create Cart &amp; Add Products<\/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-order\/\">Magento 2 API \u2013 Create Order<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello, Magento peeps! I am back with another tutorial on&nbsp;Magento 2 API \u2013 Set Shipping &amp; Billing Information. My last blog post of the&nbsp;Magento 2&#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-2586","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2586","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=2586"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2586\/revisions"}],"predecessor-version":[{"id":12893,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2586\/revisions\/12893"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}