API Access Key
Your API access key is your unique authentication token used to gain access to the Coinlayer API. You can find yours in your Dashboard.
In order to authenticate with the API, simply append the access_key parameter to the API's base URL and set it to your API access key value.
Base URL:
https://api.apilayer.net/coinlayer/Append your API access key: Here is an example API call illustrating how to authenticate with the Coinlayer API:
https://api.apilayer.net/coinlayer/live?access_key=YOUR_ACCESS_KEYAPI Response
In the example API request above, the Coinlayer API's live endpoint was used. Below you will see the standard API response in JSON format containing exchange rate data for all available cryptocurrencies.
{
"success": true,
"terms": "https://coinlayer.com/terms",
"privacy": "https://coinlayer.com/privacy",
"timestamp": 1529571067,
"target": "USD",
"rates": {
"611": 0.389165,
"ABC": 59.99,
"ACP": 0.014931,
"ACT": 0.15927,
"ACT*": 0.14371,
"ADA": 0.160502,
"ADCN": 0.001406,
"ADL": 121.5,
"ADX": 0.427854,
"ADZ": 0.02908,
"AE": 2.551479,
"AGI": 0.12555,
"AIB": 0.005626,
"AIDOC": 0.02605,
[...]
}
}The basic structure of the Coinlayer API's JSON response is similar across all API endpoints. Throughout the API Endpoints section you will learn more about the meaning of each response object.
Available Endpoints
In total, the Coinlayer API offers 6 endpoints, each with its own functionality. Find a quick summary below.
- Live Data: Query the API for the latest available exchange rate data.
- Historical Data: Look up crypto rates for a specific date.
- Conversion Endpoint: Convert amounts between cryptocurrencies and target currencies.
- Time-Frame Data: Query the API for crypto data in a specific period.
- Change Data: Retrieve data about rate fluctuation in a specific period.
- List Endpoint: Retrieve a list of all available cryptocurrencies and target currencies.
Connecting via HTTPS
All plans available for the Coinlayer API come with support for 256-bit SSL encryption. To connect to the API via HTTPS, simply use the https protocol instead of standard http.
JSONP Callbacks
The Coinlayer API supports JSONP Callbacks, enabling you to enter a function name and cause the API to return your requested API result wrapped inside that function. In order to specify a callback, pass a function name into the API's callback GET parameter.
Example Request: In our example request we are specifying the function name to be CALLBACK_FUNCTION
https://api.apilayer.net/coinlayer/live?access_key=YOUR_ACCESS_KEY&callback=CALLBACK_FUNCTIONExample Response: Your API response will be wrapped inside your preferred callback function.
CALLBACK_FUNCTION({
"success": true,
"terms": "https://coinlayer.com/terms",
"privacy": "https://coinlayer.com/privacy",
"timestamp": 1529571067,
"target": "USD",
"rates": {
"611": 0.389165,
"ABC": 59.99,
"ACP": 0.014931,
"ACT": 0.15927,
[...]
}
})Error Codes
Whenever a requested resource is not available or an API call fails for another reason, a JSON error is returned. Errors always come with an error code and a description.
Example Error: The following error is returned if an invalid target currency is entered.
{
"success": false,
"error": {
"code": 201,
"type": "invalid_target_currency",
"info": "An invalid target currency has been entered."
}
}Other Errors:
| Code | Type | Info |
|---|---|---|
| 105 | function_access_restricted | The requested endpoint or feature is not included in your plan, for example /convert on the Free plan, /timeframe and /change on the Free and Starter plans, or a feature such as target or expand. Returned with HTTP 403. |
106 | no_rates_available | The current request did not return any results (for example a historical date with symbols and target that have no rate). [historical] |
201 | invalid_target_currency | An invalid target currency has been entered. |
202 | invalid_currency_symbols | One or more invalid symbols have been specified. |
202 | failed_getting_fiat_currency_data | No fiat exchange-rate data is available for the requested date (any date before 2022-06-01). [historical, convert, timeframe, change] |
202 | failed_getting_crypto_currency_data | No crypto data is available for the requested date (for example 2010-01-01). [historical] |
302 | invalid_date | An invalid date has been specified. Also returned for a path that is not a Coinlayer endpoint (for example /foo, /LIVE or /live/), because it is read as a date. [historical, convert] |
302 | invalid_compare_date | An invalid compare date has been specified. [live, historical] |
202 | failed_getting_compare_fiat_currency_data | No fiat exchange-rate data is available for the compare date (for example 2010-01-01). [live, historical] |
402 | invalid_from_currency | An invalid "from" currency has been specified. [convert] |
402 | invalid_to_currency | An invalid "to" currency has been specified. [convert] |
403 | invalid_conversion_amount | No or an invalid amount has been specified. [convert] |
501 | no_timeframe_supplied | No or an invalid timeframe has been specified. [timeframe, change] |
502 | invalid_start_date | No or an invalid "start_date" has been specified. [timeframe, change] |
503 | invalid_end_date | No or an invalid "end_date" has been specified. [timeframe, change] |
504 | invalid_time_frame | An invalid timeframe has been specified, for example start_date after end_date. [timeframe] |
505 | time_frame_too_long | The specified timeframe is too long: more than 367 days (the info text says 365). /change has no maximum period. [timeframe] |
Note: the validation errors (codes 106 and 201 to 505) are returned with HTTP 400. Codes 202, 302 and 402 are each used for more than one error, so check type as well as code.
Missing or invalid API keys (HTTP 401) and the monthly quota (HTTP 429) are handled by the API gateway. See API Error Codes.