0

Is There any possibility to fetch all shipping methods using rest api in magento2

Thanks

2
  • check here
    – Hitesh
    Commented Oct 10, 2018 at 6:28
  • Hi @hits thanks for your reply, it is retrieving cart shipping methods, but i want all the shipping methods in magento Commented Oct 10, 2018 at 6:31

2 Answers 2

1

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 : [];
}
?>
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.