Jump to content

Using standard PHP Curl for VACENTRAL API Call


Recommended Posts

Posted

I would like to use the VACENTRAL Api call to get some information like Airport data to include in my related project.

However I do not want to mess with hosting and c-panel trying to both install Composer and VACENTRAL and woth rather call the API using Curl and pass the appropriate keys as I Have done this before on other API calls.

 

My question is has anyone or Nabeel got some documentation or an example PHP script to call the api in CUFRL and parse the returned data.

 

 

Posted

I have worked it out by looking at the code of the VACENTRAL Module  without installing it with Composer

 

the code is as follows -:   YOU MUST USE A VAILD API KEY and not the 'ZZZZZZZZZZZZZZZ'

 

<?php

/**

* Class and Function List:

* Function list:

* Classes list:

*/

/** \file      vacentral.php

*  \brief     Text  getting data from Vacentral using Curl

*  \details   This Script is used tinstead of Composer installation

*  \author    Leslie Jarrett

*  \version   1.0

*  \date      2025

*  \copyright 2025 Leslie Jarrett

*/

//

// GET AIRPORT INFORMATION FROM VACENTRAL

//

// The following URl string is required to get Airport Information

//

// https://api.vacentral.net/api/airports/[ICAO]?apiKey=[API_KEY]

//

// Where you replace [ICAO] with the Airport code you want to get data forr

//

// and replace [API_KEY] with your user API Key string

//

// Below is a worked example for the airport EGEW

// Using my own API KEY which is then hidden from the code

//

// set up your API KEY

//

$ApiKey = 'zzzzzzzzzzzzzzzzzzzzzzzzzzz';

//

// set up the Airport ICAO code

//

$AirportIcao = 'EGEW';

//

// set up the first part of the CURL URl

//

$AirportApiUrl = 'https://api.vacentral.net/api/airports/';

//

// add in the Airport Icao Code

//

$AirportApiUrl = $AirportApiUrl.$AirportIcao;

//

// add in the API Key

//

$AirportApiUrl = $AirportApiUrl.'?apiKey='.$ApiKey;

//

// now process the call to the API using Curl

//

// set the api curl handle

//

$AirportApiHandle = curl_init();

//

// Will return the response, if false it prints the response

//

curl_setopt($AirportApiHandle, CURLOPT_RETURNTRANSFER, true);

//

// Set the url

//

curl_setopt($AirportApiHandle, CURLOPT_URL,$AirportApiUrl);

//

// Execute the session and store the contents in $AirporApiRaw

//

$AirporApiRaw =curl_exec($AirportApiHandle,);

//

// Closing the session

//

curl_close($AirportApiHandle);

//

// upack the Json data to PHP array

//

$AirportData = json_decode($AirporApiRaw, true);

//

// the array $AirportData wwill have the following fields

//

// array(10) {

// ["icao"]=>

// string(4) "EGEW"

// ["iata"]=>

// string(3) "WRY"

// ["name"]=>

// string(15) "Westray Airport"

// ["city"]=>

// string(7) "Westray"

// ["country"]=>

// string(2) "GB"

// ["region"]=>

// string(6) "GB-SCT"

// ["tz"]=>

// string(13) "Europe/London"

// ["elevation"]=>

// int(29)

// ["lat"]=>

// float(59.3502998352)

// ["lon"]=>

// float(-2.9500000477)

// }

 

?>

Posted

Do you really need an API Key or authorization for this ? Below is a plain query result without an API key.

 

{
  "icao": "EGEW",
  "iata": "WRY",
  "name": "Westray Airport",
  "city": "Westray",
  "country": "GB",
  "region": "GB-SCT",
  "tz": "Europe/London",
  "elevation": 29,
  "lat": 59.3502998352,
  "lon": -2.9500000477
}

 

And it will be better if you just use the "code" feature of the forum with "php" language selected. Your cleaned up, more readable code will look like this if you do so.

 

<?php

/**
* Class and Function List:
* Function list:
* Classes list:
*/

/** \file      vacentral.php
*  \brief     Text  getting data from Vacentral using Curl
*  \details   This Script is used tinstead of Composer installation
*  \author    Leslie Jarrett
*  \version   1.0
*  \date      2025
*  \copyright 2025 Leslie Jarrett
*/

//
// GET AIRPORT INFORMATION FROM VACENTRAL
//
// The following URl string is required to get Airport Information
// https://api.vacentral.net/api/airports/[ICAO]?apiKey=[API_KEY]
// Where you replace [ICAO] with the Airport code you want to get data forr
// and replace [API_KEY] with your user API Key string
// Below is a worked example for the airport EGEW
// Using my own API KEY which is then hidden from the code

// set up your API KEY
$ApiKey = 'zzzzzzzzzzzzzzzzzzzzzzzzzzz';

// set up the Airport ICAO code
$AirportIcao = 'EGEW';

// set up the first part of the CURL URl
$AirportApiUrl = 'https://api.vacentral.net/api/airports/';

// add in the Airport Icao Code
$AirportApiUrl = $AirportApiUrl.$AirportIcao;

// add in the API Key
$AirportApiUrl = $AirportApiUrl.'?apiKey='.$ApiKey;

// now process the call to the API using Curl
// set the api curl handle
$AirportApiHandle = curl_init();

// Will return the response, if false it prints the response
curl_setopt($AirportApiHandle, CURLOPT_RETURNTRANSFER, true);

// Set the url
curl_setopt($AirportApiHandle, CURLOPT_URL,$AirportApiUrl);

// Execute the session and store the contents in $AirporApiRaw
$AirporApiRaw =curl_exec($AirportApiHandle,);

// Closing the session
curl_close($AirportApiHandle);

// unpack the Json data to PHP array
$AirportData = json_decode($AirporApiRaw, true);

// the array $AirportData will have the following fields
// array(10) {
// ["icao"] => string(4) "EGEW"
// ["iata"] => string(3) "WRY"
// ["name"] => string(15) "Westray Airport"
// ["city"] => string(7) "Westray"
// ["country"] => string(2) "GB"
// ["region"] => string(6) "GB-SCT"
// ["tz"] => string(13) "Europe/London"
// ["elevation"] => int(29)
// ["lat"]=> float(59.3502998352)
// ["lon"]=> float(-2.9500000477)
// }
?>

 

Have a nice day.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...