### Currencylayer API JSONP Callback Example Source: https://docs.apilayer.com/currencylayer/docs/getting-started This example demonstrates how to enable JSONP callbacks for the Currencylayer API. By appending `callback=CALLBACK_FUNCTION` to the API endpoint, the response is wrapped within the specified JavaScript function, allowing for cross-domain data retrieval. ```javascript https://api.currencylayer.com/live ? access_key = YOUR_ACCESS_KEY & callback = CALLBACK_FUNCTION ``` ```javascript CALLBACK_FUNCTION ({ "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "timestamp": 1432480209, "source": "USD", "quotes": { "USDAED": 3.67315, "USDAFN": 60.790001, "USDALL": 126.194504, "USDAMD": 477.359985, "USDANG": 1.790403, [...] } }) ``` -------------------------------- ### Currencylayer API JSON Formatting Example Source: https://docs.apilayer.com/currencylayer/docs/getting-started This example shows how to enable pretty-printing for Currencylayer API responses by appending `format=1` to the API URL. This feature is useful for debugging as it makes the JSON response more human-readable, though it may increase response size and is not guaranteed to be valid JSON. ```url https://api.currencylayer.com/live ? access_key = YOUR_ACCESS_KEY & format = 1 ``` -------------------------------- ### Currencylayer API Example Response Source: https://docs.apilayer.com/currencylayer/docs/getting-started This is an example of a standard API response from the Currencylayer API. It includes success status, terms, privacy policy, timestamp, source currency, and exchange rate quotes. ```json { "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "timestamp": 1430401802, "source": "USD", "quotes": { "USDAED": 3.672982, "USDAFN": 57.8936, "USDALL": 126.1652, "USDAMD": 475.306, "USDANG": 1.78952, "USDAOA": 109.216875, "USDARS": 8.901966, "USDAUD": 1.269072, "USDAWG": 1.792375, "USDAZN": 1.04945, "USDBAM": 1.757305, [...] } } ``` -------------------------------- ### Request List of Supported Currencies Source: https://docs.apilayer.com/currencylayer/docs/getting-started This example demonstrates how to request a list of all supported currencies from the Currencylayer API. Append your access key to the list endpoint. ```bash https://api.currencylayer.com/list ? access_key = YOUR_ACCESS_KEY ``` -------------------------------- ### GET /live Source: https://docs.apilayer.com/currencylayer/docs/api-documentation Retrieves the most recent exchange rate data for all available currencies. ```APIDOC ## GET /live ### Description Fetches real-time exchange rates for 168 world currencies. ### Method GET ### Endpoint /live ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API access key. - **source** (string) - Optional - The source currency code (default: USD). - **currencies** (string) - Optional - Comma-separated list of currency codes to limit the output. ### Request Example GET /live?access_key=YOUR_KEY¤cies=EUR,GBP,JPY ### Response #### Success Response (200) - **quotes** (object) - Map of currency pairs and their exchange rates. #### Response Example { "success": true, "quotes": { "USDEUR": 0.92, "USDGBP": 0.78 } } ``` -------------------------------- ### Authenticate with Currencylayer API Source: https://docs.apilayer.com/currencylayer/docs/getting-started This example shows how to append your API access key to the live endpoint URL for authentication. Replace 'YOUR_ACCESS_KEY' with your actual key. ```bash https://api.currencylayer.com/live ? access_key = YOUR_ACCESS_KEY ``` -------------------------------- ### GET /live Source: https://docs.apilayer.com/currencylayer/docs/currencylayer-api-v-1-0-0 Retrieves the most recent exchange rate data for all available currencies. ```APIDOC ## GET /live ### Description Returns the latest exchange rates for all supported currencies relative to a base currency (default USD). ### Method GET ### Endpoint https://api.currencylayer.com/live ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API access key. - **source** (string) - Optional - The currency code to use as the source (e.g., EUR). - **currencies** (string) - Optional - Comma-separated list of currency codes to limit the output. ### Request Example GET https://api.currencylayer.com/live?access_key=YOUR_KEY ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **quotes** (object) - Key-value pairs of currency pairs and their rates. #### Response Example { "success": true, "quotes": { "USDAED": 3.6725, "USDAFN": 88.412 } } ``` -------------------------------- ### Secure Connection with HTTPS Source: https://docs.apilayer.com/currencylayer/docs/getting-started This example shows how to establish a secure HTTPS connection to the Currencylayer API by adding an 's' to the HTTP protocol. This ensures data is transmitted securely. ```bash https://api.currencylayer.com/live?access_key=YOUR_ACCESS_KEY ``` -------------------------------- ### GET /convert Source: https://docs.apilayer.com/currencylayer/docs/api-documentation Converts a specific amount from one currency to another. ```APIDOC ## GET /convert ### Description Performs currency conversion between two specified currencies. ### Method GET ### Endpoint /convert ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API access key. - **from** (string) - Required - The currency code to convert from. - **to** (string) - Required - The currency code to convert to. - **amount** (number) - Required - The amount to be converted. - **date** (string) - Optional - Specific date for historical conversion (YYYY-MM-DD). ### Request Example GET /convert?access_key=YOUR_KEY&from=USD&to=EUR&amount=100 ### Response #### Success Response (200) - **result** (number) - The converted amount. #### Response Example { "success": true, "result": 92.00 } ``` -------------------------------- ### GET /list/html/table Source: https://docs.apilayer.com/currencylayer/docs/downloads Retrieves a list of all supported currencies formatted as a standard HTML table. ```APIDOC ## GET /list/html/table ### Description Returns a clean HTML structure containing currency codes and their corresponding names. ### Method GET ### Endpoint /list/html/table ### Response #### Success Response (200) - **body** (string) - HTML table element containing currency data. #### Response Example
Code Name
AED United Arab Emirates Dirham
``` -------------------------------- ### Retrieve Live Exchange Rates in Java Source: https://docs.apilayer.com/currencylayer/docs/code-examples This Java code demonstrates how to use the Apache HttpClient library to send a GET request to the Currencylayer live endpoint. It parses the JSON response to extract and print the timestamp and specific currency conversion rates. ```java package org.json.poc; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.http.HttpEntity; import org.apache.http.ParseException; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; public class LiveResponseDemo{ public static final String ACCESS_KEY = "YOUR_ACCESS_KEY"; public static final String BASE_URL = "http://api.currencylayer.com/"; public static final String ENDPOINT = "live"; static CloseableHttpClient httpClient = HttpClients.createDefault(); public static void sendLiveRequest(){ HttpGet get = new HttpGet(BASE_URL + ENDPOINT + "?access_key=" + ACCESS_KEY); try { CloseableHttpResponse response = httpClient.execute(get); HttpEntity entity = response.getEntity(); JSONObject exchangeRates = new JSONObject(EntityUtils.toString(entity)); System.out.println("Live Currency Exchange Rates"); Date timeStampDate = new Date((long)(exchangeRates.getLong("timestamp")*1000)); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss a"); String formattedDate = dateFormat.format(timeStampDate); System.out.println("1 " + exchangeRates.getString("source") + " in GBP : " + exchangeRates.getJSONObject("quotes").getDouble("USDGBP") + " (Date: " + formattedDate + ")"); response.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) throws IOException{ sendLiveRequest(); httpClient.close(); } } ``` -------------------------------- ### GET /convert Source: https://docs.apilayer.com/currencylayer/docs/currencylayer-api-v-1-0-0 Performs a currency conversion between two specific currencies based on the latest rates. ```APIDOC ## GET /convert ### Description Converts a specific amount from one currency to another. ### Method GET ### Endpoint https://api.currencylayer.com/convert ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API access key. - **from** (string) - Required - The currency code to convert from. - **to** (string) - Required - The currency code to convert to. - **amount** (number) - Required - The amount to be converted. ### Request Example GET https://api.currencylayer.com/convert?access_key=YOUR_KEY&from=USD&to=EUR&amount=100 ### Response #### Success Response (200) - **result** (number) - The converted amount. #### Response Example { "success": true, "result": 92.45 } ``` -------------------------------- ### GET /list/html/select Source: https://docs.apilayer.com/currencylayer/docs/downloads Retrieves a list of all supported currencies wrapped in HTML select-option tags for easy integration into web forms. ```APIDOC ## GET /list/html/select ### Description Returns a pre-formatted HTML string containing ``` -------------------------------- ### Currencylayer API Endpoints Source: https://docs.apilayer.com/currencylayer/docs/quickstart-guide This section details the various endpoints available in the Currencylayer API, including their purpose and example usage. ```APIDOC ## LIVE Endpoint ### Description Retrieves the most recent exchange rate data. ### Method GET ### Endpoint http://api.currencylayer.com/live ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API Access Key. - **source** (string) - Optional - The currency code of the source currency (e.g., GBP). - **currencies** (string) - Optional - A comma-separated list of currency codes to retrieve rates for (e.g., USD,AUD,CAD,PLN,MXN). - **format** (integer) - Optional - Set to 1 for JSON format. ### Request Example ``` http://api.currencylayer.com/live?access_key=YOUR_ACCESS_KEY&source=GBP¤cies=USD,AUD,CAD,PLN,MXN&format=1 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the API call was successful. - **timestamp** (integer) - The time at which the exchange rates were last updated. - **source** (string) - The source currency code. - **quotes** (object) - An object containing currency pairs and their exchange rates. #### Response Example ```json { "success": true, "timestamp": 1432400000, "source": "GBP", "quotes": { "GBPUSD": 1.5, "GBPAUD": 2.0, "GBPCAD": 1.8, "GBPPLN": 5.5, "GBPZAR": 12.0 } } ``` ``` ```APIDOC ## HISTORICAL Endpoint ### Description Retrieves historical currency exchange rates for a specific day. ### Method GET ### Endpoint http://api.currencylayer.com/historical ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API Access Key. - **date** (string) - Required - The date for which to retrieve historical rates (YYYY-MM-DD). - **source** (string) - Optional - The currency code of the source currency (e.g., EUR). - **currencies** (string) - Optional - A comma-separated list of currency codes (e.g., USD,AUD,CAD,PLN,MXN). - **format** (integer) - Optional - Set to 1 for JSON format. ### Request Example ``` http://api.currencylayer.com/historical?access_key=YOUR_ACCESS_KEY&date=2023-01-01&source=EUR¤cies=USD,AUD,CAD,PLN,MXN&format=1 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the API call was successful. - **historical** (boolean) - Indicates if the data is historical. - **date** (string) - The date for which the rates are provided. - **timestamp** (integer) - The timestamp of the data. - **source** (string) - The source currency code. - **quotes** (object) - An object containing currency pairs and their historical exchange rates. #### Response Example ```json { "success": true, "historical": true, "date": "2023-01-01", "timestamp": 1672531199, "source": "EUR", "quotes": { "EURUSD": 1.07, "EURAUD": 1.55, "EURCAD": 1.45, "EURPLN": 4.65, "EURMXN": 21.0 } } ``` ``` ```APIDOC ## CONVERT Endpoint ### Description Converts an amount from one currency to another using real-time or historical rates. ### Method GET ### Endpoint http://api.currencylayer.com/convert ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API Access Key. - **from** (string) - Required - The currency code to convert from (e.g., USD). - **to** (string) - Required - The currency code to convert to (e.g., EUR). - **amount** (number) - Required - The amount to convert (e.g., 25). - **date** (string) - Optional - The date for historical conversion (YYYY-MM-DD). - **format** (integer) - Optional - Set to 1 for JSON format. ### Request Example ``` http://api.currencylayer.com/convert?access_key=YOUR_ACCESS_KEY&from=USD&to=EUR&amount=25&date=2023-01-01&format=1 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the API call was successful. - **query** (object) - Details of the conversion query. - **result** (number) - The converted amount. #### Response Example ```json { "success": true, "query": { "from": "USD", "to": "EUR", "amount": 25, "date": "2023-01-01" }, "result": 23.36 } ``` ``` ```APIDOC ## TIMEFRAME Endpoint ### Description Retrieves exchange rates for a specific period. ### Method GET ### Endpoint http://api.currencylayer.com/timeframe ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API Access Key. - **start_date** (string) - Required - The start date of the period (YYYY-MM-DD). - **end_date** (string) - Required - The end date of the period (YYYY-MM-DD). - **source** (string) - Optional - The currency code of the source currency (e.g., EUR). - **currencies** (string) - Optional - A comma-separated list of currency codes (e.g., USD,AUD,CAD,PLN,MXN). - **format** (integer) - Optional - Set to 1 for JSON format. ### Request Example ``` http://api.currencylayer.com/timeframe?access_key=YOUR_ACCESS_KEY&start_date=2023-01-01&end_date=2023-01-05&source=EUR¤cies=USD,AUD,CAD,PLN,MXN&format=1 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the API call was successful. - **timeframe** (boolean) - Indicates if the data is for a timeframe. - **start_date** (string) - The start date of the period. - **end_date** (string) - The end date of the period. - **source** (string) - The source currency code. - **quotes** (object) - An object containing currency pairs and their exchange rates for each day in the period. #### Response Example ```json { "success": true, "timeframe": true, "start_date": "2023-01-01", "end_date": "2023-01-05", "source": "EUR", "quotes": { "2023-01-01": { "EURUSD": 1.07, "EURAUD": 1.55 }, "2023-01-02": { "EURUSD": 1.075, "EURAUD": 1.555 } } } ``` ``` ```APIDOC ## CHANGE Endpoint ### Description Retrieves currency change parameters (margin and percentage) over a specified period. ### Method GET ### Endpoint http://api.currencylayer.com/change ### Parameters #### Query Parameters - **access_key** (string) - Required - Your API Access Key. - **source** (string) - Optional - The currency code of the source currency (e.g., GBP). - **currencies** (string) - Optional - A comma-separated list of currency codes (e.g., USD,AUD,CAD,PLN,MXN). - **start_date** (string) - Optional - The start date for the change period (YYYY-MM-DD). - **end_date** (string) - Optional - The end date for the change period (YYYY-MM-DD). - **format** (integer) - Optional - Set to 1 for JSON format. ### Request Example ``` http://api.currencylayer.com/change?access_key=YOUR_ACCESS_KEY&source=GBP¤cies=USD,AUD,CAD,PLN,MXN&start_date=2023-01-01&end_date=2023-01-05&format=1 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the API call was successful. - **change** (boolean) - Indicates if change data is provided. - **start_date** (string) - The start date of the period. - **end_date** (string) - The end date of the period. - **source** (string) - The source currency code. - **currency_change** (object) - An object containing change details for each currency pair. #### Response Example ```json { "success": true, "change": true, "start_date": "2023-01-01", "end_date": "2023-01-05", "source": "GBP", "currency_change": { "GBPUSD": { "change": 0.05, "change_pct": 0.5 }, "GBPAUD": { "change": 0.1, "change_pct": 0.6 } } } ``` ``` -------------------------------- ### JavaScript: Access Real-Time Exchange Rates with jQuery.ajax Source: https://docs.apilayer.com/currencylayer/docs/code-examples This example shows how to fetch live exchange rates using jQuery's AJAX method. It makes a JSONP request to the 'live' endpoint and processes the response to display exchange rates, source currency, and timestamp. ```JavaScript // set endpoint and your access key endpoint = 'live' access_key = 'YOUR_ACCESS_KEY'; // get the most recent exchange rates via the "live" endpoint: $.ajax({ url: 'https://api.currencylayer.com/' + endpoint + '?access_key=' + access_key, dataType: 'jsonp', success: function(json) { // exchange rata data is stored in json.quotes alert(json.quotes.USDGBP); // source currency is stored in json.source alert(json.source); // timestamp can be accessed in json.timestamp alert(json.timestamp); } }); ``` -------------------------------- ### Live Exchange Rates Source: https://docs.apilayer.com/currencylayer/docs/getting-started Get the most recent exchange rate data. This endpoint requires your access key for authentication. ```APIDOC ## GET /live ### Description Retrieves the most recent exchange rate data. ### Method GET ### Endpoint ``` https://api.currencylayer.com/live ``` ### Query Parameters - **access_key** (string) - Required - Your unique API access key. ### Request Example ``` https://api.currencylayer.com/live?access_key=YOUR_ACCESS_KEY ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **terms** (string) - Link to the currencylayer Terms & Conditions. - **privacy** (string) - Link to the currencylayer Privacy Policy. - **timestamp** (integer) - UNIX timestamp of when the exchange rates were collected. - **source** (string) - The currency to which all exchange rates are relative (default: USD). - **quotes** (object) - Contains all exchange rate values, consisting of currency pairs and their respective conversion rates. #### Response Example ```json { "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "timestamp": 1430401802, "source": "USD", "quotes": { "USDAED": 3.672982, "USDAFN": 57.8936, "USDALL": 126.1652, "USDAMD": 475.306, "USDANG": 1.78952, "USDAOA": 109.216875, "USDARS": 8.901966, "USDAUD": 1.269072, "USDAWG": 1.792375, "USDAZN": 1.04945, "USDBAM": 1.757305 } } ``` ``` -------------------------------- ### Authentication and Base URL Source: https://docs.apilayer.com/currencylayer/docs/getting-started All API requests start with the base URL and require your unique access key for authentication. Append your access key to the endpoint URL. ```APIDOC ## Base URL ``` https://api.currencylayer.com/ ``` ### Authentication To authenticate with the Currencylayer API, simply attach your `access_key` to your preferred endpoint URL. ### Example API Call ``` https://api.currencylayer.com/live ? access_key = YOUR_ACCESS_KEY ``` ``` -------------------------------- ### Timeframe Exchange Rates Source: https://docs.apilayer.com/currencylayer/docs/getting-started Request exchange rates for a specific period of time. Requires your access key, start date, and end date. ```APIDOC ## GET /timeframe ### Description Requests exchange rates for a specific period of time. ### Method GET ### Endpoint ``` https://api.currencylayer.com/timeframe ``` ### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **start_date** (string) - Required - The start date of the period (YYYY-MM-DD). - **end_date** (string) - Required - The end date of the period (YYYY-MM-DD). ### Request Example ``` https://api.currencylayer.com/timeframe?access_key=YOUR_ACCESS_KEY&start_date=2015-01-01&end_date=2015-05-01 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **terms** (string) - Link to the currencylayer Terms & Conditions. - **privacy** (string) - Link to the currencylayer Privacy Policy. - **start_date** (string) - The start date of the period. - **end_date** (string) - The end date of the period. - **source** (string) - The currency to which all exchange rates are relative. - **quotes** (object) - Contains exchange rate values for each day within the specified period. #### Response Example ```json { "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "start_date": "2015-01-01", "end_date": "2015-05-01", "source": "USD", "quotes": { "2015-01-01": {"USD...": 1.23456}, "2015-01-02": {"USD...": 1.23457} } } ``` ``` -------------------------------- ### Currencylayer API Error Response Example Source: https://docs.apilayer.com/currencylayer/docs/getting-started This JSON object represents a typical error response from the Currencylayer API. It indicates a failure in the API request and provides a specific error code and a human-readable message explaining the issue, such as exceeding the monthly usage limit. ```json { "success": false, "error": { "code": 104, "info": "Your monthly usage limit has been reached. Please upgrade your subscription plan." } } ``` -------------------------------- ### JSONP and Formatting Source: https://docs.apilayer.com/currencylayer/docs/getting-started Details how to use JSONP callbacks for cross-domain requests and the format parameter for debugging. ```APIDOC ## JSONP and Formatting ### JSONP Callbacks Append `callback=FUNCTION_NAME` to any endpoint to wrap the response in a callback function. ### JSON Formatting Append `format=1` to any endpoint to receive a human-readable, formatted JSON response. Note: This is for debugging only and increases response size. ### Request Example https://api.currencylayer.com/live?access_key=YOUR_KEY&callback=myCallback&format=1 ``` -------------------------------- ### Currencylayer API Endpoints Overview Source: https://docs.apilayer.com/currencylayer/docs/getting-started This snippet outlines the different API endpoints available in Currencylayer, including live rates, historical data, currency conversion, timeframe data, and change parameters. Remember to append your access key. ```bash // "live" - get the most recent exchange rate data https://api.currencylayer.com/live // "historical" - get historical rates for a specific day https://api.currencylayer.com/historical?date=YYYY-MM-DD // "convert" - convert one currency to another https://api.currencylayer.com/convert?from=EUR&to=GBP&amount=100 // "timeframe" - request exchange rates for a specific period of time https://api.currencylayer.com/timeframe?start_date=2015-01-01&end_date=2015-05-01 // "change" - request any currency's change parameters (margin, percentage) https://api.currencylayer.com/change?currencies=USD,EUR ``` -------------------------------- ### Supported Currencies Source: https://docs.apilayer.com/currencylayer/docs/getting-started Retrieve a list of all supported currencies in JSON format. Requires your access key. ```APIDOC ## GET /list ### Description Retrieves a list of all currently supported currencies. ### Method GET ### Endpoint ``` https://api.currencylayer.com/list ``` ### Query Parameters - **access_key** (string) - Required - Your unique API access key. ### Request Example ``` https://api.currencylayer.com/list?access_key=YOUR_ACCESS_KEY ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **terms** (string) - Link to the currencylayer Terms & Conditions. - **privacy** (string) - Link to the currencylayer Privacy Policy. - **currencies** (object) - An object containing currency codes as keys and their full names as values. #### Response Example ```json { "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "currencies": { "AED": "United Arab Emirates Dirham", "AFN": "Afghan Afghani", "ALL": "Albanian Lek", "AMD": "Armenian Dram", "ANG": "Netherlands Antillean Guilder" } } ``` ``` -------------------------------- ### PHP: Perform Currency Conversion with cURL Source: https://docs.apilayer.com/currencylayer/docs/code-examples Demonstrates how to convert a specific amount from one currency to another using PHP's cURL. The code targets the 'convert' endpoint, specifying the source and target currencies, and the amount, then decodes the result. ```PHP // set API Endpoint, access key, required parameters $endpoint = 'convert'; $access_key = 'YOUR_ACCESS_KEY'; $from = 'USD'; $to = 'EUR'; $amount = 10; // initialize CURL: $ch = curl_init('https://api.currencylayer.com/'.$endpoint.'?access_key='.$access_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 echo $conversionResult['result']; ``` -------------------------------- ### Currency Change Parameters Source: https://docs.apilayer.com/currencylayer/docs/getting-started Request change parameters (margin, percentage) for specified currencies. Requires your access key and a comma-separated list of currency codes. ```APIDOC ## GET /change ### Description Requests change parameters (e.g., margin, percentage) for specified currencies over a default period. ### Method GET ### Endpoint ``` https://api.currencylayer.com/change ``` ### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **currencies** (string) - Required - A comma-separated list of currency codes (e.g., USD,EUR). ### Request Example ``` https://api.currencylayer.com/change?access_key=YOUR_ACCESS_KEY¤cies=USD,EUR ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **terms** (string) - Link to the currencylayer Terms & Conditions. - **privacy** (string) - Link to the currencylayer Privacy Policy. - **change** (object) - Contains change parameters for each requested currency. - **rate** (number) - The current exchange rate. #### Response Example ```json { "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "change": { "USD": {"change": 0.001, "percentage": 0.08}, "EUR": {"change": -0.0005, "percentage": -0.04} }, "rate": 1.1234 } ``` ``` -------------------------------- ### Currency Conversion Source: https://docs.apilayer.com/currencylayer/docs/getting-started Convert an amount from one currency to another. Requires your access key, source currency, target currency, and amount. ```APIDOC ## GET /convert ### Description Converts a specified amount from one currency to another. ### Method GET ### Endpoint ``` https://api.currencylayer.com/convert ``` ### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **from** (string) - Required - The currency code to convert from (e.g., EUR). - **to** (string) - Required - The currency code to convert to (e.g., GBP). - **amount** (number) - Required - The amount to convert (e.g., 100). ### Request Example ``` https://api.currencylayer.com/convert?access_key=YOUR_ACCESS_KEY&from=EUR&to=GBP&amount=100 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **terms** (string) - Link to the currencylayer Terms & Conditions. - **privacy** (string) - Link to the currencylayer Privacy Policy. - **query** (object) - Details of the conversion query. - **result** (number) - The converted amount. #### Response Example ```json { "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "query": { "from": "EUR", "to": "GBP", "amount": 100 }, "result": 85.50 } ``` ``` -------------------------------- ### Generate HTML Currency Data Table Source: https://docs.apilayer.com/currencylayer/docs/downloads Provides a structured HTML table containing currency codes and their corresponding names. This format is ideal for displaying comprehensive currency lists in a readable, tabular layout. ```html [...]
Code Name
AED United Arab Emirates Dirham
AFN Afghan Afghani
ALL Albanian Lek
AMD Armenian Dram
``` -------------------------------- ### PHP: Access Real-Time Exchange Rates with cURL Source: https://docs.apilayer.com/currencylayer/docs/code-examples This snippet shows how to retrieve the latest exchange rate data using PHP's cURL library. It initializes a cURL session, fetches the JSON response from the 'live' endpoint, and decodes it to access specific exchange rates. ```PHP // set API Endpoint and access key (and any options of your choice) $endpoint = 'live'; $access_key = 'YOUR_ACCESS_KEY'; // Initialize CURL: $ch = curl_init('https://api.currencylayer.com/'.$endpoint.'?access_key='.$access_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: echo $exchangeRates['quotes']['USDGBP']; ``` -------------------------------- ### Historical Exchange Rates Source: https://docs.apilayer.com/currencylayer/docs/getting-started Retrieve historical exchange rates for a specific day. Requires your access key and a specified date. ```APIDOC ## GET /historical ### Description Retrieves historical exchange rates for a specific day. ### Method GET ### Endpoint ``` https://api.currencylayer.com/historical ``` ### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **date** (string) - Required - The date for which to retrieve historical rates (YYYY-MM-DD). ### Request Example ``` https://api.currencylayer.com/historical?access_key=YOUR_ACCESS_KEY&date=2023-01-01 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **terms** (string) - Link to the currencylayer Terms & Conditions. - **privacy** (string) - Link to the currencylayer Privacy Policy. - **timestamp** (integer) - UNIX timestamp of when the exchange rates were collected. - **source** (string) - The currency to which all exchange rates are relative. - **quotes** (object) - Contains all exchange rate values for the specified date. #### Response Example ```json { "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "timestamp": 1672531200, "source": "USD", "quotes": { "USD..." : 1.23456 } } ``` ``` -------------------------------- ### HTTP ETags Source: https://docs.apilayer.com/currencylayer/docs/getting-started Explains the use of HTTP ETags to reduce bandwidth by caching unchanged exchange rate data. ```APIDOC ## HTTP ETags ### Description ETags allow you to determine if exchange rate data has changed since your last request. If the data is unchanged, the server returns a smaller response, reducing bandwidth usage. ### Usage Store the ETag header from your initial request and send it back in subsequent requests. If the data hasn't changed, the server will return a 304 Not Modified status. ``` -------------------------------- ### JavaScript: Perform Currency Conversion with jQuery.ajax Source: https://docs.apilayer.com/currencylayer/docs/code-examples This snippet illustrates how to perform currency conversions using jQuery's AJAX. It sends a request to the 'convert' endpoint with specified currencies and amount, then alerts the conversion result. ```JavaScript // set endpoint and your access key endpoint = 'convert'; access_key = 'YOUR_ACCESS_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.currencylayer.com/' + endpoint + '?access_key=' + access_key +'&from=' + from + '&to=' + to + '&amount=' + amount, dataType: 'jsonp', success: function(json) { // access the conversion result in json.result alert(json.result); } }); ``` -------------------------------- ### API Error Handling Source: https://docs.apilayer.com/currencylayer/docs/getting-started Explains the structure of error responses and provides a list of common error codes returned by the Currencylayer API. ```APIDOC ## Error Handling ### Description When an API request fails, the Currencylayer API returns a 3-digit error code and an informative message. ### Response Example { "success": false, "error": { "code": 104, "info": "Your monthly usage limit has been reached. Please upgrade your subscription plan." } } ### Common Error Codes - **101**: Invalid access key. - **103**: Non-existent API function. - **104**: Monthly usage limit reached. - **201**: Invalid Source Currency. - **301**: Date not specified (historical). - **404**: Resource not found. ``` -------------------------------- ### Generate HTML Select-Option Menu for Currencies Source: https://docs.apilayer.com/currencylayer/docs/downloads Provides an HTML select element populated with currency codes and names. This is useful for creating dropdown menus in web forms where users need to select a specific currency. ```html ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.