{"id":305204,"date":"2021-09-12T11:59:20","date_gmt":"2021-09-12T11:59:20","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=305204"},"modified":"2024-07-25T06:14:13","modified_gmt":"2024-07-25T06:14:13","slug":"send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/","title":{"rendered":"Send Request in XML format in USPS Shipping Method&#8217;s API in Magento 2"},"content":{"rendered":"\n<p>In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API.<br><br>Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. <br>In this Controller, we are creating requests in XML format and sending the requests using CURL methods.<br>In API response, we are getting scheduled pickup information for a package.<br><br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Vendor_CustomModule\n * @author    Webkul\n * @copyright Copyright (c) Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\nnamespace Vendor\\CustomModule\\Controller\\Demo;\n\nuse Magento\\Framework\\App\\Action\\Action;\nuse Magento\\Framework\\App\\Action\\Context;\n\nclass MakeXmlRequest extends Action\n{\n    \/**\n     * @var \\Magento\\Shipping\\Model\\Simplexml\\ElementFactory\n     *\/\n    protected $xmlElFactory;\n\n    \/**\n     * @var \\Magento\\Framework\\Controller\\Result\\JsonFactory\n     *\/\n    protected $resultJsonFactory;\n\n    \/**\n     * initialization\n     *\n     * @param Context $context\n     * @param \\Magento\\Shipping\\Model\\Simplexml\\ElementFactory $xmlElFactory\n     * @param \\Magento\\Framework\\Controller\\Result\\JsonFactory $resultJsonFactory\n     *\/\n    public function __construct(\n        Context $context,\n        \\Magento\\Shipping\\Model\\Simplexml\\ElementFactory $xmlElFactory,\n        \\Magento\\Framework\\Controller\\Result\\JsonFactory $resultJsonFactory\n    ) {\n        $this-&gt;xmlElFactory      = $xmlElFactory;\n        $this-&gt;resultJsonFactory = $resultJsonFactory;\n        parent::__construct($context);\n    }\n\n    public function execute()\n    {\n        $userId       = &quot;008COMPAN2890&quot;; \/\/usps userid;\n        $gatewayUrl   = &quot;https:\/\/secure.shippingapis.com\/ShippingAPI.dll&quot;;\/\/usps gateway_secure_url&#039;;\n\n        \/\/request information of customer, address and package\n        $firstName    = &quot;John&quot;;\n        $lastName     = &quot;Doe&quot;;\n        $firmName     = &quot;ABC Corp.&quot;;\n        $suiteOrApt   = &quot;2759 Momorial&quot;;\n        $address2     = &quot;8 WILDWOOD DR&quot;;\n        $urbanization = &quot;&quot;;\n        $city         = &quot;OLD LYME&quot;;\n        $state        = &quot;CT&quot;;\n        $zIP5         = &quot;06371&quot;;\n        $zIP4         = &quot;1844&quot;;\n        $phone        = &quot;5555551234&quot;;\n        $extension    = &quot;201&quot;;\n\n        $estimatedWeight     = &quot;14&quot;;\n        $packageLocation     = &quot;Front Door&quot;;\n        $specialInstructions = &quot;Packages are behind the screen door.&quot;;\n\n        $packVals                 = &#091;];\n        $eachPack                 = &#091;];\n        $eachPack&#091;&quot;ServiceType&quot;]  = &quot;PriorityMailExpress&quot;;\n        $eachPack&#091;&quot;Count&quot;]        = &quot;2&quot;;\n        $packVals&#091;]               = $eachPack;\n        $eachPack                 = &#091;];\n        $eachPack&#091;&quot;ServiceType&quot;]  = &quot;PriorityMail&quot;;\n        $eachPack&#091;&quot;Count&quot;]        = &quot;1&quot;;\n        $packVals&#091;]               = $eachPack;\n\n        \/\/format data in XML format\n        $xml = $this-&gt;xmlElFactory-&gt;create(\n            &#091;&#039;data&#039; =&gt; &#039;&lt;?xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot;?&gt;&lt;CarrierPickupScheduleRequest\/&gt;&#039;]\n        );\n        $xml-&gt;addAttribute(&#039;USERID&#039;, $userId);\n        \n        $xml-&gt;addChild(&#039;FirstName&#039;, $firstName);\n        $xml-&gt;addChild(&#039;LastName&#039;, $lastName);\n        $xml-&gt;addChild(&#039;FirmName&#039;, $firmName);\n        $xml-&gt;addChild(&#039;SuiteOrApt&#039;, $suiteOrApt);\n        $xml-&gt;addChild(&#039;Address2&#039;, $address2);\n        $xml-&gt;addChild(&#039;Urbanization&#039;, $urbanization);\n        $xml-&gt;addChild(&#039;City&#039;, $city);\n        $xml-&gt;addChild(&#039;State&#039;, $state);\n        $xml-&gt;addChild(&#039;ZIP5&#039;, $zIP5);\n        $xml-&gt;addChild(&#039;ZIP4&#039;, $zIP4);\n        $xml-&gt;addChild(&#039;Phone&#039;, $phone);\n        $xml-&gt;addChild(&#039;Extension&#039;, $extension);\n\n        for ($i=0; $i&lt;count($packVals); $i++) {\n            $package = $xml-&gt;addChild(&#039;Package&#039;);\n            $package-&gt;addChild(&#039;ServiceType&#039;, $packVals&#091;$i]&#091;&quot;ServiceType&quot;]);\n            $package-&gt;addChild(&#039;Count&#039;, $packVals&#091;$i]&#091;&quot;Count&quot;]);\n        }\n\n        $xml-&gt;addChild(&#039;EstimatedWeight&#039;, $estimatedWeight);\n        $xml-&gt;addChild(&#039;PackageLocation&#039;, $packageLocation);\n        $xml-&gt;addChild(&#039;SpecialInstructions&#039;, $specialInstructions);\n       \n        $request = $xml-&gt;asXML();\n        $result = $this-&gt;executeCurlRequest($request, $gatewayUrl, &quot;CarrierPickupSchedule&quot;);\n        $data = &#091;&quot;result&quot; =&gt; $result];\n        $resultJson = $this-&gt;resultJsonFactory-&gt;create();\n        return $resultJson-&gt;setData($data);\n    }\n\n    public function executeCurlRequest($xml, $url, $api)\n    {\n        $arrayData = &#091;];\n        try {\n            \/\/Initiate cURL\n            $ch = curl_init();\n            curl_setopt ($ch, CURLOPT_HTTPHEADER, array(&quot;Content-Type: text\/xml&quot;));\n            \n            curl_setopt($ch, CURLOPT_URL, $url);\n\n            curl_setopt($ch, CURLOPT_POSTFIELDS,\n                        &quot;API=&quot;.$api.&quot;&amp;XML=&quot; . $xml);\n            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);\n            $data = curl_exec($ch);\n            curl_close($ch);\n\n            \/\/convert the XML result into array\n            $arrayData = json_decode(json_encode(simplexml_load_string($data)), true);\n        } catch (\\Exception $e) {\n            \\Magento\\Framework\\App\\ObjectManager::getInstance()-&gt;get(&#039;Psr\\Log\\LoggerInterface&#039;)-&gt;debug($e-&gt;getMessage());\n        }\n        return $arrayData;\n    }\n}<\/pre>\n\n\n\n<p>When we will hit this controller in the browser&#8217;s window, we will get the response as the following image:<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"731\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png\" alt=\"APIResponse\" class=\"wp-image-305206\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-300x183.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-250x152.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-768x468.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse.png 1503w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><figcaption class=\"wp-element-caption\">MakeXmlRequest Controller&#8217;s Response<\/figcaption><\/figure>\n\n\n\n<p>Hope this will be helpful. Thanks \ud83d\ude42 You may also check our previous blog for <a href=\"https:\/\/webkul.com\/blog\/create-custom-shipping-method-in-magento2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 custom shipping method development<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API. Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. In this Controller, <a href=\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":249,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,8884,8885],"tags":[12033,8023,832,12034],"class_list":["post-305204","post","type-post","status-publish","format-standard","hentry","category-magento2","category-magento2-marketplace","category-magento2-marketplace-magento2","tag-usps-api","tag-usps-carrier","tag-usps-shipping","tag-xml-request-in-api"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Send Request in XML format in USPS Shipping Method&#039;s API in Magento 2<\/title>\n<meta name=\"description\" content=\"In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API.Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. In this Controller, we are creating requests in XML format and sending the requests using CURL methods.In API response, we are getting scheduled pickup information for a package.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send Request in XML format in USPS Shipping Method&#039;s API in Magento 2\" \/>\n<meta property=\"og:description\" content=\"In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API.Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. In this Controller, we are creating requests in XML format and sending the requests using CURL methods.In API response, we are getting scheduled pickup information for a package.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-12T11:59:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-25T06:14:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png\" \/>\n<meta name=\"author\" content=\"Khushboo Sahu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khushboo Sahu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\"},\"author\":{\"name\":\"Khushboo Sahu\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\"},\"headline\":\"Send Request in XML format in USPS Shipping Method&#8217;s API in Magento 2\",\"datePublished\":\"2021-09-12T11:59:20+00:00\",\"dateModified\":\"2024-07-25T06:14:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\"},\"wordCount\":140,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png\",\"keywords\":[\"USPS API\",\"USPS Carrier\",\"USPS Shipping\",\"XML Request in API\"],\"articleSection\":[\"Magento2\",\"Magento2 marketplace\",\"Magento2 marketplace\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\",\"name\":\"Send Request in XML format in USPS Shipping Method's API in Magento 2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png\",\"datePublished\":\"2021-09-12T11:59:20+00:00\",\"dateModified\":\"2024-07-25T06:14:13+00:00\",\"description\":\"In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API.Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. In this Controller, we are creating requests in XML format and sending the requests using CURL methods.In API response, we are getting scheduled pickup information for a package.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse.png\",\"width\":1503,\"height\":915,\"caption\":\"APIResponse\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Send Request in XML format in USPS Shipping Method&#8217;s API in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\",\"name\":\"Khushboo Sahu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Khushboo Sahu\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send Request in XML format in USPS Shipping Method's API in Magento 2","description":"In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API.Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. In this Controller, we are creating requests in XML format and sending the requests using CURL methods.In API response, we are getting scheduled pickup information for a package.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Send Request in XML format in USPS Shipping Method's API in Magento 2","og_description":"In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API.Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. In this Controller, we are creating requests in XML format and sending the requests using CURL methods.In API response, we are getting scheduled pickup information for a package.","og_url":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-09-12T11:59:20+00:00","article_modified_time":"2024-07-25T06:14:13+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png","type":"","width":"","height":""}],"author":"Khushboo Sahu","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Khushboo Sahu","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/"},"author":{"name":"Khushboo Sahu","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca"},"headline":"Send Request in XML format in USPS Shipping Method&#8217;s API in Magento 2","datePublished":"2021-09-12T11:59:20+00:00","dateModified":"2024-07-25T06:14:13+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/"},"wordCount":140,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png","keywords":["USPS API","USPS Carrier","USPS Shipping","XML Request in API"],"articleSection":["Magento2","Magento2 marketplace","Magento2 marketplace"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/","url":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/","name":"Send Request in XML format in USPS Shipping Method's API in Magento 2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse-1200x731.png","datePublished":"2021-09-12T11:59:20+00:00","dateModified":"2024-07-25T06:14:13+00:00","description":"In Magento 2, sometimes we need to use APIs to get some information for online shipping methods. So, in this blog, we are going to learn that how can we create XML requests and send requests in XML format in API.Here, we have created a Controller File MakeXmlRequest.php inside app\/code\/Vendor\/CustomModule\/Controller\/Demo\/ directory. In this Controller, we are creating requests in XML format and sending the requests using CURL methods.In API response, we are getting scheduled pickup information for a package.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/09\/APIResponse.png","width":1503,"height":915,"caption":"APIResponse"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/send-request-in-xml-format-in-usps-shipping-methods-api-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Send Request in XML format in USPS Shipping Method&#8217;s API in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca","name":"Khushboo Sahu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Khushboo Sahu"},"url":"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/305204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/249"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=305204"}],"version-history":[{"count":7,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/305204\/revisions"}],"predecessor-version":[{"id":454590,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/305204\/revisions\/454590"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=305204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=305204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=305204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}