Is There any possibility to fetch all shipping methods using rest api in magento2
Thanks
Is There any possibility to fetch all shipping methods using rest api in magento2
Thanks
A Shipping Methods in the Magento is based on cart. Without a cart you can't obtain desired result, because a methods could not do calculations by weight, by subtotal (min/max), by customer location etc. If you wish to obtain all available shipping carriers installed, you can parse store setting from the carriers
section (but you should write own module with api access to this kind of data):
<?php
/**
* Return array of carriers.
* If $isActiveOnlyFlag is set to true, will return only active carriers
*
* @param bool $isActiveOnlyFlag
* @return array
*/
public function getAvailableMethods($isActiveOnlyFlag = false)
{
$carriers = $this->shippingConfig->getAllCarriers();
foreach ($carriers as $carrierCode => $carrierModel) {
if (!$carrierModel->isActive() && (bool)$isActiveOnlyFlag === true) {
continue;
}
$carrierMethods = $carrierModel->getAllowedMethods();
if (!$carrierMethods) {
continue;
}
foreach ($carrierMethods as $methodCode => $methodTitle) {
$methods[] = $carrierCode . '_' . $methodCode;
}
}
return !empty($methods) ? $methods : [];
}
?>
You can try following based on your requirement
- /V1/carts/:cartId/shipping-methods
- /V1/carts/mine/shipping-methods
- /V1/guest-carts/:cartId/shipping-methods
Reference file : vendor/magento/module-quote/etc/webapi.xml
Reference link : https://devdocs.magento.com/guides/v2.2/rest/list.html