Requested resource was not found

Hello Team,

I am using Toll Calculator V1 API in my webiste and this is working fine. Now I am trying to upgrade the version in V2. I have setup all things which are suggested by this link https://opendata.transport.nsw.gov.au/node/7407/exploreapi#!/pricing/getMatch. I am trying to post the data by Curl.

I am using below script.

$headers = array(
‘Content-Type: application/json;charset=utf-8’,
‘Accept: application/json’,
‘Authorization: apikey APIKEy’
);

        $fields = array(
            'polyline' => "tc_mEgb_y[@Nz@jK@@BX@?@@@??@@?@@?@?@?@?@?@?@A@?@A@A?@H?NABb@`E\\`DJpAhAhI?V?FB?B@@@BB?D?BABABC@C@~@dJhD~\\l@CnAK~@MlB[j@Mz@U`Bg@pAc@~Ag@t@Sf@Kl@It@I\\PRHh@ZFHDLBP?DPtDBb@RnENnCHhCDz@DlAD~@LbCHhARvBVnCbB|KV~AZnBbArFPp@X`ATv@Vv@Tn@Zr@b@|@d@t@^l@^j@bA~AfAfBbAbBf@v@\\n@`@x@`@bA`@hAPn@TbAThAVjBJdADr@DtA@nACbBIdBKlAQrAUnA_@zAc@xAi@zAu@xBY~@Sr@Qp@Ov@Y~AQlAKz@IjAGnACr@At@AnA@fADtAFnAJlAJfALx@Jr@ThAXhAd@|AtAvDv@pBf@tAbAlC|@`Cx@lCZhAXdAV~A^tB^rBZvBHv@Ht@NxATjAF|@NxBJ`BLlBJfBj@bJV|DFhANfAHhAVzDNfCL|ANbBLzALrA^lCPnAl@zDb@`CXbBXhBZfCT`BV`Bx@rEn@vDrAxHZ`BT`Ap@dDd@jCz@pFZtBVlBJn@XxBDZr@rGLjAJrAL|A`@zFz@nMn@jNTbDCbDIlCCn@E`@OdBK~@OfAY`B[xAm@zB]lAs@lB{@bBe@~@iBfC}AjBuAvAuBhB{A~@i@\\mGbEaJvFs@b@cCzA{CpB_DrBqD|ByClBqDdCqDpCm@f@uAjAwBnBwDpDsDzDcD|D_DbEkA~AwFlI}A`CwDxFgC~D{BlD{CvFwFlKsAtCeChFqAvCOZsBfFiB`FuAjDeBfFeBxFmBtGc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z@Rv@d@bARb@P\\b@n@b@f@f@f@d@b@lAv@TVTVRXPXRb@|@bCrAjDLTLNFBFH~@Ld@?\\C`@I\\Qf@e@j@s@b@k@f@g@f@a@j@[d@Qd@Oh@Kj@Gt@Av@Bp@J|@RbAf@z@n@h@^p@`@|@Vd@Fr@Dn@Ah@Gl@Md@Q^ORU@EBEDEDCFAD@B@BBDD@F@FAFADCD@f@F\\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",
            "vehicleClass" => "A",
            "excludeToll" => true,
            "includeSteps" => false,
            "departureTime" => "2020-06-29T19:42:19.641Z",
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://api.transport.nsw.gov.au/v2/roads/toll_calc/match');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)."\'");

        $result = curl_exec($ch);

        curl_close($ch);

        $result = json_decode($result);

I am getting below response

array(3) { [“tollResponse”]=> object(stdClass)#1312 (1) { [“ErrorDetails”]=> object(stdClass)#1317 (5) { [“TransactionId”]=> string(24) “000001722cab8356-684aab1” [“ErrorDateTime”]=> string(29) “2020-06-29T12:43:20.449-07:00” [“Message”]=> string(32) “Requested resource was not found” [“RequestedUrl”]=> string(25) “/v2/roads/toll_calc/match” [“RequestedMethod”]=> string(4) “POST” } } [“message”]=> string(20) “Toll Cost not found!” [“statusCode”]=> int(401) }

Can you please let me know the issue? and how can I solve?

Thanks

Hey Suresht,

Looking at the status code 401, have you added this Toll Calc v2 API to your application?

Hello Dear

Yes. As you can check my provided code and you can see, I am using V2 API https://api.transport.nsw.gov.au/v2/roads/toll_calc/match for getting the toll costing.

Thanks

You shouldn’t need to append the "\'" at the end of the POST body. Try omitting it… gave it a go and it worked fine :slight_smile:

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

Hello Jxeeno,

Thanks for your support. Yes your solution is working and I am getting the below response.

array(3) {
[“tollResponse”]=>
object(stdClass)#1321 (1) {
[“match”]=>
object(stdClass)#1317 (11) {
[“confidence”]=>
float(0.975625)
[“geometry”]=>
string(634) "~cjmEuawyXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[“distance”]=>
float(8004.2)
[“duration”]=>
float(589.1)
[“minChargeInCents”]=>
int(343)
[“maxChargeInCents”]=>
int(343)
[“summary”]=>
string(29) “Lane Cove Tunnel, Epping Road”
[“tollsCharged”]=>
array(1) {
[0]=>
object(stdClass)#1319 (5) {
[“gantryVisits”]=>
array(1) {
[0]=>
object(stdClass)#1312 (5) {
[“estimatedArrivalTime”]=>
string(24) “2020-06-29T19:48:07.141Z”
[“gantryRef”]=>
string(7) “LCE/W-1”
[“gantry”]=>
object(stdClass)#1313 (8) {
[“gantryRef”]=>
string(7) “LCE/W-1”
[“gantryName”]=>
string(48) “LCE-1 - Lane Cove Tunnel Eastbound and Westbound”
[“motorwayRef”]=>
string(3) “LCT”
[“motorwayName”]=>
string(16) “Lane Cove Tunnel”
[“motorwayProvider”]=>
string(16) “Transurban Linkt”
[“chargeType”]=>
string(5) “Fixed”
[“latitude”]=>
float(-33.8017)
[“longitude”]=>
float(151.145)
}
[“distance”]=>
float(4794.48)
[“duration”]=>
float(347.5)
}
}
[“chargeType”]=>
string(5) “Fixed”
[“charges”]=>
array(1) {
[0]=>
object(stdClass)#1320 (2) {
[“vehicleClass”]=>
string(1) “A”
[“chargeInCents”]=>
int(343)
}
}
[“minChargeInCents”]=>
int(343)
[“maxChargeInCents”]=>
int(343)
}
}
[“isCheapest”]=>
bool(true)
[“isShortest”]=>
bool(true)
[“isQuickest”]=>
bool(true)
}
}
[“message”]=>
string(29) “Toll Cost loaded successfully”
[“statusCode”]=>
int(200)
}

But there are two charges are showing in response, min charge and max charge. So which charge I need to consider?

Thanks

min and max are there to describe when a range of pricing exists. That usually happens when not all variables are provided - e.g. :

  • if a vehicle class isn’t specified and the toll charges are based on vehicle class, then the max charge would represent Class B (heavy vehicle) tolls and min charge would represent Class A tolls.
  • if a departure time isn’t supplied and the toll charge varies depending time/day of use, then the cheapest time of use would be listed for min and most expensive time of use would be listed for max.

The breakdown of those potential charges is provided in the charges array.

Hello,

So you mean that final charges, I need to consider from the below charges array:

[“charges”]=>
array(1) {
[0]=>
object(stdClass)#1320 (2) {
[“vehicleClass”]=>
string(1) “A”
[“chargeInCents”]=>
int(343)
}

and toll charge will be 343?

Thanks

Sorry, I was a bit unclear! I’ll try and explain another way :slight_smile:

If you provide all the parameters needed to determine the applicable toll in your initial API request (i.e. both vehicleClass and departureTime), the max and min values should always be equal. In that scenario, it won’t matter which you use. You should only see one charge object in the array and the chargeInCents should also match maxChargeInCents and minChargeInCents.

// request
$fields = array(
        "polyline" => "...",
        "vehicleClass" => "A",
        "excludeToll" => false,
        "includeSteps" => false,
        "departureTime" => "2020-06-29T19:42:19.641Z",
);

// response
{
    "charges": [
        {
            "vehicleClass": "A",
            "chargeInCents": 836
        }
    ],
    "minChargeInCents": 836,
    "maxChargeInCents": 836
}

If you omit some of those fields in your API request – for example, you don’t provide vehicleClass, the response may include multiple potential charges in the array and a range where min != max:

// request
$fields = array(
        "polyline" => "...",
        // note vehicle class is omitted
        "excludeToll" => false,
        "includeSteps" => false,
        "departureTime" => "2020-06-29T19:42:19.641Z",
);

// response
{
    "charges": [
        {
            "vehicleClass": "A",
            "chargeInCents": 836
        },
        {
            "vehicleClass": "B",
            "chargeInCents": 2508
        }
    ],
    "minChargeInCents": 836,
    "maxChargeInCents": 2508
}

Hope that makes sense?

1 Like

Hello Jxeeno,

I got and thanks for big support.

Thanks

1 Like

Hello,

I am getting response from the Toll API V2. In this response, how can i get how many tolls come into way, what is the name of tolls and charges of each toll from the below response

array(3) {
[“tollResponse”]=>
object(stdClass)#1321 (1) {
[“match”]=>
object(stdClass)#1317 (11) {
[“confidence”]=>
float(0.975625)
[“geometry”]=>
string(634) “~cjmEuawy[@f@HNt@vAA~BPd@|ApE|AcADEl@]PU?E@CBEBAD@B@BB@D?DA@EFpAjEDJx@bC^jAB|D@N?HGLgErC[TKFIFKHPXl@bANRHNLRFJ\l@HPZb@LLb@b@XTFDJFTL\LVHZDR?B?Z@D@DEPGDCHEBABGDM@C@E?IAGGYMc@I@EQCYAG?K?G?I@I@EFOJQHIJEJCHAX?LDZRb@f@Tl@LtA@VEr@Mt@m@bCc@rBU~AE^Ij@KxAMbB[rDEb@QrB]~BoAfHmBnKi@pDaAvHuAlMe@nEk@|Di@xCs@~Cm@tB}@hCcAfCk@lAmA|BeBxCkAjByAbCm@jAeAzByAvDk@lBmAE}@nC_A|B_@x@i@fAsA|BsAtBkAzAqBzBuAlBIJ]f@[d@c@r@Yf@wAhCWb@Ud@Yr@M\IVUt@_@nAcAbD[~AUv@a@jAcArBu@rA]f@S@QRu@z@]@}@|@oAfAOLk@^QNWPIHg@b@u@x@w@dAqAjBaArAy@hAs@bAIFMLwApB}AxB}@nAc@l@w@hAMPi@t@kBjCi@t@i@t@MRKPENIJwAlBoAdBoAbBQh@uBxCqCxDMPaA|AKVYr@CJCNDLFN~CnDlCxCrFlGpDEnDxDX\xBzBHIPY”
[“distance”]=>
float(8004.2)
[“duration”]=>
float(589.1)
[“minChargeInCents”]=>
int(343)
[“maxChargeInCents”]=>
int(343)
[“summary”]=>
string(29) “Lane Cove Tunnel, Epping Road”
[“tollsCharged”]=>
array(1) {
[0]=>
object(stdClass)#1319 (5) {
[“gantryVisits”]=>
array(1) {
[0]=>
object(stdClass)#1312 (5) {
[“estimatedArrivalTime”]=>
string(24) “2020-06-29T19:48:07.141Z”
[“gantryRef”]=>
string(7) “LCE/W-1”
[“gantry”]=>
object(stdClass)#1313 (8) {
[“gantryRef”]=>
string(7) “LCE/W-1”
[“gantryName”]=>
string(48) “LCE-1 - Lane Cove Tunnel Eastbound and Westbound”
[“motorwayRef”]=>
string(3) “LCT”
[“motorwayName”]=>
string(16) “Lane Cove Tunnel”
[“motorwayProvider”]=>
string(16) “Transurban Linkt”
[“chargeType”]=>
string(5) “Fixed”
[“latitude”]=>
float(-33.8017)
[“longitude”]=>
float(151.145)
}
[“distance”]=>
float(4794.48)
[“duration”]=>
float(347.5)
}
}
[“chargeType”]=>
string(5) “Fixed”
[“charges”]=>
array(1) {
[0]=>
object(stdClass)#1320 (2) {
[“vehicleClass”]=>
string(1) “A”
[“chargeInCents”]=>
int(343)
}
}
[“minChargeInCents”]=>
int(343)
[“maxChargeInCents”]=>
int(343)
}
}
[“isCheapest”]=>
bool(true)
[“isShortest”]=>
bool(true)
[“isQuickest”]=>
bool(true)
}
}
[“message”]=>
string(29) “Toll Cost loaded successfully”
[“statusCode”]=>
int(200)
}

Thanks

Hello,

Anyone can check my concern and give me suggestion so I will get details of tolls and their charges.

Thanks

In your example, there’s only one toll that’s applicable. You can loop through the tollsCharged array to get the list of charges applicable:

<?php
foreach($data["tollResponse"]["match"]["tollsCharged"] as $toll){
    $estimatedCharge = $toll["maxChargeInCents"]; // 343
    $motorwayName = $toll["gantryVisits"][0]["gantry"]["motorwayName"]; // Lane Cove Tunnel
    echo "Toll: ${motorwayName}\nCharge: ${estimatedCharge} cents\n\n";
}

// Expected output:
// Toll: Lane Cove Tunnel
// Charge: 343 cents
?>

If you try matching a route that passes more than one motorway, you’ll get a response that has multiple elements in the tollsCharged array. See below example:

Request

{
	"polyline": "tncnEitzx[a@jHK|AANjBTh@FxFv@`@IHCFEHEFKDKBE@GLi@B_@@WD]BYDc@TqAJk@BSBMBWHi@Fi@DYRqBRkCt@eJHcAXeDZgF`@mGf@cH\\{F`@cG\\_FNuBR_DRkDT_DR}Cv@uL\\cFRmDNqCRoED{ATeKH{EDmE@sD@iHAkK?gL?}A?sC?eAAe@CqBEkBEiAI}AKcBKsAQeBMaAUkBKq@O}@Os@]cBa@kB_@sA_@oAc@{AmAsD]iA{@kCi@cBM]i@{As@uBY}@WmAa@yCQqBQwC?aCFaBLyDN}EHsBDuADgC?wB?sBG_BIkBi@}Lw@uN_@_Hi@aH{@{I}@aJg@yMa@wLo@kRUsJc@eNo@wRUiJSwN@iG@iGD_IJyJZ}In@kIhAmQdA{Pp@aJz@wNTcE?}FE}Fu@{Km@oEm@iC_BqGoAqDeBqEoCcFcCwDaCsCyBsBgFeEsBsA}DiB{@c@eDcAyGsAaHeA}EcAqCw@{Bw@qB}@_CsAqBoA_CgBiAiAeBsAcA_AyAqBi@w@}AsBcAmA{AoBaAkA}C{DsCsDsC_Gs@iBw@aCKc@YwAgAwGYqDK}BCoAAgB?eBDqARsDd@eHHkADcB?aBCiBIcCIyAMeAKa@Ma@Wo@OYOYW]UWT_@JQXc@b@i@dA_AFGzAqApBaB@Al@k@h@k@BC^c@`@s@j@_A`@o@RYFEHIBCBALIRINEJCFAF?NAT@d@DtC\\B@N@NBNBxC\\p@LIZK|Ag@nGPB"
}

Response

{
  "match": {
    "confidence": 0.982085,
    "geometry": "tnc...",
    "distance": 16682.9,
    "duration": 805.9,
    "minChargeInCents": 1180,
    "maxChargeInCents": 3542,
    "summary": "M5 Motorway, M8 Motorway Tunnel",
    "tollsCharged": [
      {
        "gantryVisits": [
          {
            "gantryRef": "M5-HV41-44",
            "gantry": {
              "gantryRef": "M5-HV41-44",
              "gantryName": "M5-FR 41 to 44 - Fairford Rd",
              "motorwayRef": "M5",
              "motorwayName": "M5 South-West",
              "motorwayProvider": "E-way",
              "chargeType": "Fixed",
              "latitude": -33.9405,
              "longitude": 151.036
            },
            "distance": 641.67,
            "duration": 60.2
          }
        ],
        "chargeType": "Fixed",
        "charges": [
          {
            "vehicleClass": "A",
            "chargeInCents": 485
          },
          {
            "vehicleClass": "B",
            "chargeInCents": 1456
          }
        ],
        "minChargeInCents": 485,
        "maxChargeInCents": 1456
      },
      {
        "gantryVisits": [
          {
            "gantryRef": "TP-46-A",
            "gantry": {
              "gantryRef": "TP-46-A",
              "gantryName": "KGR M5W Mainline Entry",
              "motorwayRef": "M8",
              "motorwayName": "WestConnex M8/M5 East",
              "motorwayProvider": "Transurban Linkt",
              "chargeType": "Distance",
              "latitude": -33.94285,
              "longitude": 151.07818
            },
            "distance": 4438.46,
            "duration": 245.1
          },
          {
            "gantryRef": "TP-41-A",
            "gantry": {
              "gantryRef": "TP-41-A",
              "gantryName": "St Peters Interchange Exit",
              "motorwayRef": "M8",
              "motorwayName": "WestConnex M8/M5 East",
              "motorwayProvider": "Transurban Linkt",
              "chargeType": "Distance",
              "latitude": -33.91577,
              "longitude": 151.17522
            },
            "distance": 14838.52,
            "duration": 669.2
          }
        ],
        "chargeType": "Distance",
        "charges": [
          {
            "vehicleClass": "A",
            "chargeInCents": 695
          },
          {
            "vehicleClass": "B",
            "chargeInCents": 2086
          }
        ],
        "minChargeInCents": 695,
        "maxChargeInCents": 2086
      }
    ],
    "isCheapest": true,
    "isShortest": true,
    "isQuickest": true
  }
}
© Transport for NSW