getShipmentTracking method

Future<List<ShipmentTracking>> getShipmentTracking(
  1. String shipmentId
)

Get shipment tracking

Implementation

Future<List<ShipmentTracking>> getShipmentTracking(String shipmentId) async {
  try {
    final response = await _client.authenticatedRequest<Map<String, dynamic>>(
      '/rest/V1/shipments/$shipmentId/tracks',
    );

    if (response.statusCode == 200) {
      final List<dynamic> tracks = response.data!['items'] ?? [];
      return tracks.map((track) => ShipmentTracking.fromJson(track)).toList();
    } else {
      throw Exception(
        'Failed to get shipment tracking: ${response.statusMessage}',
      );
    }
  } on DioException catch (e) {
    throw Exception('Failed to get shipment tracking: ${e.message}');
  } catch (e) {
    throw Exception('Failed to get shipment tracking: $e');
  }
}