Version Numbers API End Point Sample Code in PHP

As discussed in the Integration Guide, to get a list of all the version numbers for all the packages we provide, you need to send a simple HTTP GET request, which includes the Authentication Header. This sample code will show you how to do it easily.

By using the powerful and popular cURL extension, it can be done like this:

# -- Add your API Key to the request headers $headers = [ 'X-API-KEY: '.$api_key, ]; # -- Create a CURL handle $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); # -- Make the request $result = curl_exec($ch); $curl_info = curl_getinfo($ch); curl_close($ch); # -- Decode the api response as json $result_json = json_decode($result); if ($result_json === null) { echo "Couldn't decode the response as JSON\n"; echo $result; exit(); } # -- Pretty print the full response echo "
".json_encode($result_json, JSON_PRETTY_PRINT)."
\n"; # -- Demonstrating printing out specific software version numbers: echo "Latest Chrome on Windows Version Number: ".implode(".", $result_json->version_data->software->chrome->windows->latest_version)."\n"; echo "Latest Firefox (standard, desktop) Version Number: ". implode(".", $result_json->version_data->software->firefox->standard->latest_version)."\n";

The last two lines of the sample code demonstrate combining the list of version fragments for Chrome and Firefox and sending them to the output. Of course, you can use all of the version numbers however you want; saving them to your database for quick access, or to a configuration file are two popular options.

Download a working sample file: version-numbers.php.