Fuel usage API Examples

  1. Estimate the fuel consumption for a route

Get the information fuel consumption for a given route

Example on getting information about estimated fuel consumption in a route:

// initialisation with your API KEY
$MY_API_KEY_HERE = 'YOUR-API-KEY-HERE';
$base_url = "https://api.searoutes.com/fs/fuel";
// send the API key in the request
$curl_headers = array(
    'accept: application/json ',
    'Content-Type: application/json ',
    'x-Api-key: '.$MY_API_KEY_HERE,
);
// initialize curl and pass the Api key in the header
$curl = curl_init();

// define our search parameters
$requestParameters = array(
    'speed' => 15,
    'departure' => 1500249900,
    'eta' => 1501113900,
    'journeytime' => 864000,
);
$postData = array(
    'routepoints' =>
        array(

            array(
                'lon' => 9.9000000000000004,
                'lat' => 53.5,
                'trackDistance' => 0,
            ),
            array(
                'lon' => 9.9130830764770508,
                'lat' => 53.532833099365234,
                'trackDistance' => 2.0258852653699129,
            ),
            array(
                'lon' => 9.9016208648681641,
                'lat' => 53.539619445800781,
                'trackDistance' => 2.6032170529582448,
            ),
            array(
                'lon' => 9.9011907577514648,
                'lat' => 53.541893005371094,
                'trackDistance' => 2.7406085273890799,
            ),
            array(
                'lon' => 9.8941736221313477,
                'lat' => 53.542018890380859,
                'trackDistance' => 2.9910744389999544,
            ),
        ),
);
// create the new url with the specific parameter
$url = $base_url."?".http_build_query($requestParameters, '', "&");

//this is a post request
$postDataString = json_encode($postData);
$curl_headers[] = 'Content-Length:'.strlen($postDataString);
curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_headers);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postDataString);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
curl_close($curl);
print ($response);

     

          // initialisation with your API KEY
          final String MY_API_KEY_HERE = "YOUR-API-KEY-HERE";
          // base url for the subsequent requests
          final String base_url = "https://api.searoutes.com/fs/fuel";
          // provide a search query
          final String url = base_url + "?speed=15&&departure=1500249900&eta=1501113900&journeytime=864000";

  final String jsonBody = "{\"routepoints\": [{\"lon\": 9.9, \"lat\": 53.5, \"trackDistance\": 0 }, {\"lon\": 9.91308307647705, \"lat\": 53.532833099365234, \"trackDistance\": 2.025885265369913 }, {\"lon\": 9.901620864868164, \"lat\": 53.53961944580078, \"trackDistance\": 2.603217052958245 }, {\"lon\": 9.901190757751465, \"lat\": 53.541893005371094, \"trackDistance\": 2.74060852738908 }, {\"lon\": 9.894173622131348, \"lat\": 53.54201889038086, \"trackDistance\": 2.9910744389999544 } ] }";

          HttpsURLConnection con = (HttpsURLConnection) new URL(url).openConnection();
          con.setRequestProperty("Content-length", String.valueOf(jsonBody.length()));
          con.setRequestMethod("POST");
          con.setRequestProperty("x-Api-key", MY_API_KEY_HERE);
          con.setRequestProperty("accept", "application/json");
          con.setRequestProperty("Content-Type", "application/json");

          con.setDoOutput(true);
          con.setDoInput(true);

          DataOutputStream output = new DataOutputStream(con.getOutputStream());
          output.writeBytes(jsonBody);
          output.close();

          DataInputStream input = new DataInputStream(con.getInputStream());

          for (int c = input.read(); c != -1; c = input.read()) {
              System.out.print((char) c);
          }
          input.close();
     

# Python 3
import requests

# initialisation with your API KEY
MY_API_KEY_HERE = 'YOUR-API-KEY-HERE'
base_url = "https://api.searoutes.com/fs/fuel"

# custom headers with our API key
request_headers = {
    'accept': 'application/json',
    'Content-Type': 'application/json',
    'x-api-key': MY_API_KEY_HERE
}

request_params = {
    'speed': 15,
    'departure': 1500249900,
    'eta': 1501113900,
    'journeytime': 864000
}

request_body = {
    "routepoints": [
        {
            "lon": 9.9,
            "lat": 53.5,
            "trackDistance": 0
        },
        {
            "lon": 9.91308307647705,
            "lat": 53.532833099365234,
            "trackDistance": 2.025885265369913
        },
        {
            "lon": 9.901620864868164,
            "lat": 53.53961944580078,
            "trackDistance": 2.603217052958245
        },
        {
            "lon": 9.901190757751465,
            "lat": 53.541893005371094,
            "trackDistance": 2.74060852738908
        },
        {
            "lon": 9.894173622131348,
            "lat": 53.54201889038086,
            "trackDistance": 2.9910744389999544
        }
    ]
}

# create the new url with the specific parameter
url = base_url
response = requests.post(url, headers=request_headers, json=request_body, params=request_params)
print(response.text)

     

The returned object will be a JSON object that contains the information about the requested fuel consumption for the given route. For example the request above will return:

  {
    "w": {
      "2to4": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 220457.2297377729,
          "total": 220457.2297377729,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 62825.357737147104,
          "total": 283282.58747492,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 14950.967046536769,
          "total": 298233.55452145677,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 27255.749356268218,
          "total": 325489.303877725,
          "seca": true
        }
      ],
      "4to6": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 372174.2908722543,
          "total": 372174.2908722543,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 106061.31172214478,
          "total": 478235.60259439907,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 25240.11376273713,
          "total": 503475.7163571362,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 46012.9577103317,
          "total": 549488.6740674679,
          "seca": true
        }
      ],
      "6to8": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 497790.0234754091,
          "total": 497790.0234754091,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 141858.97346176713,
          "total": 639648.9969371762,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 33759.12074159764,
          "total": 673408.1176787738,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 61543.18517036121,
          "total": 734951.302849135,
          "seca": true
        }
      ],
      "8to10": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 636073.6419721901,
          "total": 636073.6419721901,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 181266.69808745175,
          "total": 817340.3400596419,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 43137.23832785431,
          "total": 860477.5783874962,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 78639.57910722242,
          "total": 939117.1574947186,
          "seca": true
        }
      ],
      "10plus": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 647437.904528036,
          "total": 647437.904528036,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 184505.25760912913,
          "total": 831943.1621371652,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 43907.93981576987,
          "total": 875851.1019529351,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 80044.57495249086,
          "total": 955895.676905426,
          "seca": true
        }
      ]
    },
    "p": {
      "2to4": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 220457.2297377729,
          "total": 220457.2297377729,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 62825.357737147104,
          "total": 283282.58747492,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 14950.967046536769,
          "total": 298233.55452145677,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 27255.749356268218,
          "total": 325489.303877725,
          "seca": true
        }
      ],
      "4to6": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 372174.2908722543,
          "total": 372174.2908722543,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 106061.31172214478,
          "total": 478235.60259439907,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 25240.11376273713,
          "total": 503475.7163571362,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 46012.9577103317,
          "total": 549488.6740674679,
          "seca": true
        }
      ],
      "6to8": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 497790.0234754091,
          "total": 497790.0234754091,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 141858.97346176713,
          "total": 639648.9969371762,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 33759.12074159764,
          "total": 673408.1176787738,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 61543.18517036121,
          "total": 734951.302849135,
          "seca": true
        }
      ],
      "8to10": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 636073.6419721901,
          "total": 636073.6419721901,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 181266.69808745175,
          "total": 817340.3400596419,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 43137.23832785431,
          "total": 860477.5783874962,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 78639.57910722242,
          "total": 939117.1574947186,
          "seca": true
        }
      ],
      "10plus": [
        {
          "v": 15,
          "dur": 0,
          "lon": 9.9,
          "lat": 53.5,
          "trackDistance": 0,
          "ts": 1500249900,
          "fuel": 0,
          "total": 0,
          "seca": true
        },
        {
          "v": 15,
          "dur": 250.12930076433858,
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "trackDistance": 2.025885265369913,
          "ts": 1500250150,
          "fuel": 647437.904528036,
          "total": 647437.904528036,
          "seca": true
        },
        {
          "v": 15,
          "dur": 71.28123137423937,
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "trackDistance": 2.603217052958245,
          "ts": 1500250221,
          "fuel": 184505.25760912913,
          "total": 831943.1621371652,
          "seca": true
        },
        {
          "v": 15,
          "dur": 16.963267376393773,
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "trackDistance": 2.74060852738908,
          "ts": 1500250238,
          "fuel": 43907.93981576987,
          "total": 875851.1019529351,
          "seca": true
        },
        {
          "v": 15,
          "dur": 30.924191220222635,
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "trackDistance": 2.9910744389999544,
          "ts": 1500250269,
          "fuel": 80044.57495249086,
          "total": 955895.676905426,
          "seca": true
        }
      ]
    }
  }

For more information about this API please refer to the Fuel consumption API Documentation.