Endpoints such as FlightInfoEx and InFlightInfo can return the planned Route or Waypoints, respectively, for a flight. Both GetLastTrack and GetHistoricalTrack can return the actual path flown.
In both cases the decoded route or waypoints can produce the total distance by calculating the distance between each successive lat-long pair. FlightXML provides LatLongsToDistance, or as mentioned in the linked thread, it is possible to implement this algorithm ourself.