My website has been using Toll Calculator API v1 successfully and I am attempting to upgrade to v2. I am using PHP to connect, here is what I have so far.
$data = array("polyline" => "".$encodedPolyLine."", "vehicleClass" => "B", "departureTime" => $travelDateTime); $data_string = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.transport.nsw.gov.au/v2/roads/toll_calc/data"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Authorization: apikey XXXXX', 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string) )); curl_setopt($curl, CURLOPT_TIMEOUT, 5); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); $result = curl_exec($curl); curl_close($curl); return $result;
If I take out the POST fields it connects fine and give the data like https://opendata.transport.nsw.gov.au/node/7407/exploreapi
Once I add POST data I get a “Requested resource was not found” error.
I use DATE_ISO8601 for the date format. I get the polyline from Google maps api.
Any idea what I am doing wrong?