PHP unsure of error

Hi Guys,

I keep on getting this error and I’m unsure why it is happening. Any help would be appreciated

Thanks.

<?php
    $apiEndpoint='https://api.transport.nsw.gov.au/v1/tp/';
    $apiCall='departure_mon';

// Set the location and time parameters
    $when = time();   // Now
    $stop = '10101331'; // Domestic Airport Station

// Build the request parameters
$params = !array(
        'outputFormat' => 'rapidJSON',
        'coordOutputFormat'    =>'EPSG:4326',
        'mode'              =>'direct',
        'type_dm'       =>'stop',
        'name_dm'       => $stop,
        'depArrMacro'   =>'dep',
        'itdDate'       =>date('Ymd', $when),
        'itdTime'       =>date('Hi', $when),
        'TfNSWDM'       =>'true',
);


$url = $apiEndpoint.$apiCall.'?'.http_build_query($params);
// Perform the request and build the JSON response data
$response = file_get_contents($url);
$json = json_decode($response, true);

$stopEvents = $json['stopEvents'];

// Loop over returned stop events
foreach ($stopEvents as $stopEvent) {

// Extract the route information
$transportation = $stopEvent['transportation'];
$routeNumber    = $transportation['number'];
$destination    = $transportation['destination']['name'];

// In the case of a train, the location s platform information
$location = $stopEvent['location'];

// Determine how many minutes until departure
$time      = strtotime($stopEvent['departureTimePlanned']);
$countdown = $time - time();
$minutes   = round($countdown / 60);

// Output the stop event with a countdown timer
echo $minutes . "m from " . $location['disassembledName'] . "\n";
echo $routeNumber . " to " . $destination . "\n\n";
}

WHICH RETURNS:

<br />
<b>Warning</b>:  http_build_query(): Parameter 1 expected to be Array or Object.  Incorrect value given in <b>[...][...]</b> on line <b>23</b><br />
<br />
<b>Warning</b>:  file_get_contents() has been disabled for security reasons in <b>[...][...]</b> on line <b>25</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>[...][...]</b> on line <b>31</b><br />

You’ll need to remove the exclamation mark (!) when setting up $params. What you have now is setting $params to false. Try it with this instead but don’t forget you’ll need to add in HTTP headers to authorise the API request.

$params = array(
        'outputFormat' => 'rapidJSON',
        'coordOutputFormat'    =>'EPSG:4326',
        'mode'              =>'direct',
        'type_dm'       =>'stop',
        'name_dm'       => $stop,
        'depArrMacro'   =>'dep',
        'itdDate'       =>date('Ymd', $when),
        'itdTime'       =>date('Hi', $when),
        'TfNSWDM'       =>'true',
);
1 Like

cheers thanks very much.