1

We use ShipStation to send tracking information to Magento and I'm trying to retrieve the order shipping / tracking information once this is saved to the order.

If I use sales_order_shipment_track_save_after for my event / observer, I can get the tracking information, however, it doesn't seem like this event is called when updated via ShipStation api.

If I change the event to sales_order_shipment_save_after, this gets triggered by ShipStation but it doesn't appear that I can get tracking information from this event.

Any ideas how I can get tracking information when it's updated via api from ShipStation?

2 Answers 2

3

Was able to grab tracking info using the event sales_order_shipment_save_after and the following in my observer:

$shipment = $observer->getEvent()->getShipment();

foreach ($shipment->getAllTracks() as $track) {
  $tracking = $track;
}

And as it turns out, this event / observer was actually being called by the ShipStation API however the shipment was created using XML Object. So I just ended up json_encoding / decoding the xml tracking info:

$tracking = json_encode($tracking->getData());
$tracking = json_decode($tracking, true);

From here, I was able to grab all of the needed tracking information coming from ShipStation:

$trackingNumber = $tracking['track_number'];
$carrier = $tracking['carrier_code'];
1

Have you tried logging API rest calls and going from there.

https://github.com/vladflonta/magento2-webapi-log

But essentially it sounds like you are going to either have to introduce your own event in an override or modify something like the above to only catch shipstation calls.

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.