Toll Upgrade v2

Hi,

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?

Thank you.

Hi @Tenshi,

Looks like you’re pointing your request to the /data endpoint. Try sending it to the /match endpoint instead:

curl_setopt($curl, CURLOPT_URL, "https://api.transport.nsw.gov.au/v2/roads/toll_calc/match");

Thanks @jxeeno,

Good point, I have made that update to

curl_setopt($curl, CURLOPT_URL, “https://api.transport.nsw.gov.au/v2/roads/toll_calc/match”);

but unfortunately got the same result:

{
“ErrorDetails”:
{
“TransactionId”:“000001722cab8356-4e7eddf”,
“ErrorDateTime”:“2020-06-19T19:58:47.419-07:00”,
“Message”:“Requested resource was not found”,
“RequestedUrl”:"/v2/roads/toll_calc/match",
“RequestedMethod”:“POST”
}
}

Thank you for having a look for me.

Hmm, just gave it a go and it worked fine when I sent a valid ISO date time and polyline. But got the same error back whenever I provided an invalid polyline or ISO date time.

See below example:

    $encodedPolyLine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\\Jp@Fx@B|@?b@?^C~@Et@In@I\\S`@[n@M`@G`@?XF?DBDDBF?F~CD@G@EDCDCD?D@FYVm@PWZa@d@a@^Sf@Qt@KTAxAGP@B@LUDMHQ`@c@b@aAJOFM^_@v@[t@YHITQVYHKp@wA";
    $travelDateTime = '2020-06-20T06:01:55.978Z';
	$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/match");
	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 xxx',
        '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);
    
    echo $result;

Thank you @jxeeno,

I think the polyline is okay, I pushed it through V1 and it got lane cover road and tunnel, It must be my date format.

Thank you for helping with this. I will have another go at it tomorrow and update this thread with what I did wrong in case others slip on on this change over.

Cheers.

Thanks for jumping in here @jxeeno and helping out!

© Transport for NSW