Below, we have code snippets you can use to access data from our API using various programming languages. We are always updating this list so feel free to send us code snippets you would like to see here.
// set API Endpoint and access key (and any options of your choice) $endpoint = 'live'; $api_key = 'API_KEY'; // Initialize CURL: $ch = curl_init('https://api.currencybeacon.com/'.$endpoint.'?base=USD&api_key='.$api_key.''); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Store the data: $json = curl_exec($ch); curl_close($ch); // Decode JSON response: $exchangeRates = json_decode($json, true); // Access the exchange rate values, e.g. GBP: print_r($exchangeRates);
// set API Endpoint, access key, required parameters $endpoint = 'convert'; $api_key = 'API_KEY'; $from = 'USD'; $to = 'EUR'; $amount = 10; // initialize CURL: $ch = curl_init('https://api.currencybeacon.com/'.$endpoint.'?api_key='.$api_key.'&from='.$from.'&to='.$to.'&amount='.$amount.''); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // get the (still encoded) JSON data: $json = curl_exec($ch); curl_close($ch); // Decode JSON response: $conversionResult = json_decode($json, true); // access the conversion result print_r($conversionResult);
// set endpoint and your access key endpoint = 'live' api_key = 'API_KEY'; // get the most recent exchange rates via the "live" endpoint: $.ajax({ url: 'https://api.currencybeacon.com/' + endpoint + '?api_key=' + api_key, dataType: 'jsonp', success: function(json) { // exchange rata data is stored in json.quotes alert(json); } });
// set endpoint and your access key endpoint = 'convert'; api_key = 'API_KEY'; // define from currency, to currency, and amount from = 'EUR'; to = 'GBP'; amount = '10'; // execute the conversion using the "convert" endpoint: $.ajax({ url: 'https://api.currencybeacon.com/' + endpoint + '?api_key=' + api_key +'&from=' + from + '&to=' + to + '&amount=' + amount, dataType: 'jsonp', success: function(json) { // access the conversion result in json.result alert(json); } });