How to create custom shipping like DHL, UPS, ... in magento 2 so I will be able to connect to third party API and get all the data to create package, tracking numbers and labels? Is there any skeleton Carrier class how to do such thing?

  • You can use Magento2 Sample Shipping module as example github.com/magento/magento2-samples/tree/master/…
    – joni jones
    Commented Feb 2, 2017 at 17:07
  • This is just simple carrier class, in UPS you can see that there are methods like isShippingLabelsAvailable, isTrackingAvailable, requestToShipment and _doShipmentRequest. First two gives you functionality to use tracking and labeling for your shipping. Third one is fired while genrating shipping and in there you have to provide logic to connect to third paty API. There I think I aswered my own question :D
    – Marceli Po
    Commented Feb 3, 2017 at 6:58

1 Answer 1


In the Magento, shipping carriers divided into two types: online and offline shipping.

They should implement \Magento\Shipping\Model\Carrier\CarrierInterface:

  • Check if carrier has shipping tracking option available - isTrackingAvailable()
  • Get allowed shipping methods - getAllowedMethods()

1) For the offline shipping, your custom shipping simply extends from Abstract carrier model- \Magento\Shipping\Model\Carrier\AbstractCarrier.

class CustomOfflineShipping extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements

A good sample here: https://github.com/ajzele/B05032-Foggyline_Shipbox

2) For the online shipping, your module should extends from the abstract online shipping carrier model - Magento\Shipping\Model\Carrier\AbstractCarrierOnline.

We should take a look the USPS shipping or DHL International:


 * USPS shipping
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
class Carrier extends AbstractCarrierOnline
    implements \Magento\Shipping\Model\Carrier\CarrierInterface
  • I allready find it out thx but my question is more about how to generate tracking numbers and labels. What methods should I use? For example requestToShipment this one is fired when you create shipping in admin panel for order. It would be nice to now what type of data should I return to cereate tracking and labes. In DHL or UPS you can see that there are using trackFactory to create trackings. Method _parseXmlTrackingResponse in DHL carrier class.
    – Marceli Po
    Commented Feb 3, 2017 at 7:42

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.