Getting started overview

Integrating with Currencylayer involves a series of steps designed to quickly enable access to real-time and historical currency exchange rate data. The process focuses on account creation, API key retrieval, and making an initial authenticated request. Currencylayer provides a RESTful API that returns data in JSON format, facilitating integration into various programming environments.

The service offers a Free Plan that includes 250 API requests per month, suitable for evaluation and small-scale projects. Authentication for all requests is handled via a unique API key, appended as a URL parameter to each call. This guide outlines the necessary steps to go from account registration to a successful API call, including common troubleshooting tips.

Step Action Location/Tool
1 Sign up for a Currencylayer account Currencylayer product page
2 Locate your unique API Key Currencylayer Dashboard
3 Construct your first API request Code Editor / Terminal
4 Execute the request Terminal (cURL) or HTTP client library
5 Parse the JSON response Code Editor

Create an account and get keys

To begin using the Currencylayer API, you must first create an account. This process grants you access to your personal dashboard where your unique API key is generated and managed. The API key is critical for authenticating all your requests to ensure proper access and usage tracking.

  1. Visit the Currencylayer Website: Navigate to the official Currencylayer product page.
  2. Choose a Plan: Select the 'Free Plan' to start, or any other paid plan if your project requires more requests or advanced features immediately. Each plan outlines its request limits and available features.
  3. Complete Registration: Fill out the required registration details, typically including your email address and a password. After submission, you may need to verify your email address.
  4. Access Your Dashboard: Once registered and logged in, you will be redirected to your personal Currencylayer dashboard.
  5. Retrieve Your API Key: Your unique API key is prominently displayed on the main page of your dashboard. It is a hexadecimal string that you will append to every API request. Ensure you copy this key accurately, as it is case-sensitive. Keep your API key secure and do not expose it in client-side code or public repositories.

For more detailed information on account management and features, refer to the Currencylayer documentation.

Your first request

After obtaining your API key, you can make your first API call to retrieve live exchange rates. The simplest way to test your integration is by using the live endpoint. This endpoint returns the most recent exchange rates for all available currencies, relative to a default source currency (USD for free plan users).

Using cURL (Recommended for initial testing)

cURL is a command-line tool and library for transferring data with URLs, widely supported across operating systems, and excellent for quick API tests without writing code. To make your first live rates request, open your terminal or command prompt and execute the following cURL command:

curl "http://api.currencylayer.com/live?access_key=YOUR_API_KEY"

Replace YOUR_API_KEY with the actual API key you retrieved from your Currencylayer dashboard. Upon successful execution, the API will return a JSON object containing the live exchange rates.

Example JSON Response

{
  "success": true,
  "terms": "https://currencylayer.com/terms",
  "privacy": "https://currencylayer.com/privacy",
  "timestamp": 1678886400,
  "source": "USD",
  "quotes": {
    "USDAUD": 1.5000,
    "USDEUR": 0.9200,
    ""USDGBP": 0.8500,
    // ... more quotes
  }
}

The success field indicates whether the request was processed successfully. The timestamp provides the Unix timestamp of the data update. The source indicates the base currency, and quotes contains key-value pairs of currency codes and their respective exchange rates against the source currency.

Using Python

For programmatic access, you can use an HTTP client library in your preferred language. Here's an example using Python's requests library:

import requests

api_key = "YOUR_API_KEY"
url = f"http://api.currencylayer.com/live?access_key={api_key}"

response = requests.get(url)
data = response.json()

if data.get("success"):
    print("Live Exchange Rates:")
    for currency_pair, rate in data.get("quotes", {}).items():
        print(f"{currency_pair}: {rate}")
else:
    print(f"API Error: {data.get('error', {}).get('info', 'Unknown error')}")

Install the requests library if you haven't already: pip install requests. This script fetches the live rates and prints them to the console, demonstrating a basic integration. For more advanced Python examples, consult the Currencylayer documentation.

Common next steps

Once you have successfully made your first request, you can explore Currencylayer's additional functionalities to enrich your application. Here are some common next steps:

  • Specify Target Currencies: Instead of fetching all quotes, you can specify particular target currencies using the currencies parameter. For example, to get USD to EUR and GBP rates: http://api.currencylayer.com/live?access_key=YOUR_API_KEY&currencies=EUR,GBP.
  • Change Source Currency: For paid plans, you can change the source currency from USD to any other available currency using the source parameter. For instance, to get EUR to USD rates: http://api.currencylayer.com/live?access_key=YOUR_API_KEY&source=EUR&currencies=USD.
  • Historical Data: Access past exchange rates using the historical endpoint. This is useful for analytics or displaying rates from a specific date: http://api.currencylayer.com/historical?access_key=YOUR_API_KEY&date=YYYY-MM-DD.
  • Currency Conversion: Utilize the convert endpoint to convert any amount from one currency to another on a specific date: http://api.currencylayer.com/convert?access_key=YOUR_API_KEY&from=USD&to=GBP&amount=100.
  • Time-Series Data: For paid plans, retrieve exchange rate data for a specific period using the timeseries endpoint, valuable for trend analysis: http://api.currencylayer.com/time-series?access_key=YOUR_API_KEY&start_date=YYYY-MM-DD&end_date=YYYY-MM-DD&currencies=EUR,GBP.
  • Error Handling: Implement robust error handling in your application to gracefully manage API errors, such as invalid API keys, rate limits, or invalid parameters. The API returns specific error codes and messages in its JSON responses.
  • Secure Your API Key: Beyond initial testing, ensure your API key is not hardcoded in your application, especially in client-side code. Use environment variables or a secure configuration management system to store and retrieve your key. For best practices in API key management, refer to resources like Google Cloud's API key security guide.
  • Monitor Usage: Regularly check your Currencylayer dashboard to monitor your API request usage and ensure you stay within your plan's limits.

The Currencylayer API reference provides comprehensive details on all available endpoints and parameters.

Troubleshooting the first call

When making your first API call, you might encounter issues. Here are common problems and their solutions:

  • Invalid API Key (Error Code 101): This is the most frequent issue. Double-check that you have copied your API key correctly from your Currencylayer dashboard. Ensure there are no leading or trailing spaces, and that the key is exactly as provided. Verify that it's included as the access_key URL parameter.
  • HTTPS Access Restriction (Error Code 105): The Free Plan only supports HTTP access. If you try to use https://api.currencylayer.com with a Free Plan, it will fail. Ensure your request uses http://api.currencylayer.com. HTTPS access is available with paid plans.
  • No Source Currency Specified / Invalid Source Currency (Error Code 201, 202): The Free Plan defaults to USD as the source currency. Attempting to specify a different source currency will result in an error. For paid plans, ensure the source currency code is valid and supported.
  • Invalid Currency Codes (Error Code 203): If you are specifying target currencies, ensure that all currency codes are valid ISO 4217 currency codes (e.g., EUR, GBP, JPY). Incorrect codes will cause the API to return an error.
  • Request Limit Reached (Error Code 104): If you exceed the 250 requests per month limit on the Free Plan, subsequent requests will fail until your quota resets or you upgrade your plan. Check your dashboard for current usage.
  • Network Issues: Verify your internet connection. If using cURL, ensure it's installed and not blocked by a local firewall. For programmatic calls, check for network errors in your HTTP client library.
  • Incorrect Endpoint: Ensure you are calling the correct endpoint (e.g., /live, /historical) and that the endpoint is available on your current plan.

When an error occurs, the API typically returns a JSON response with an error object containing a code and info field. These fields provide specific details to help you diagnose the problem. Consult the Currencylayer error codes documentation for a complete list and explanations.