Using ExchangeRate-API.com is as simple as making HTTP requests:
Call:
|
Returns:
|
Example: To convert 9.99 US Dollars to Euros:
Call:
Returns:
Useful for: This a API query can be used whenever you already know what currency you want to convert from and to. For example, you may have a website where the user manually selects the currency they wish to use. You can then call this query to convert all the prices on your page to the correct amounts.
How do I implement this in code? We have compiled a large selection of code examples to illustrate how to implement our API in a variety of programming languages. Look to the top left of this page for links to each language example.
Error Codes:
The API returns the following error codes:
-1 if an invalid amount is used (Must be numeric floating point or integer numbers)
-2 if either of the 3 letter currency codes are invalid (Check our supported currencies)
-3 if an invalid key is used (Get an API key)
-4 if your API query limit is reached (Click here for extended usage)
We also offer two additional types of query:
1. Automatic currency conversion based on user's country:
|
Returns:
|
Example: To convert $10.95 for a user with an IP address of 178.79.140.74
Useful for: This query is extremely useful if you would like your website or app to automatically display the correct prices depending on the user's country. For example, an American user will see all prices on your website in US Dollars, while someone landing on your site from England will see all prices in British Pounds. This will happen automatically, and they will not need to manually choose their currencies.
How do I implement this in code? We have compiled a large selection of code examples to illustrate how to implement our API in a variety of programming languages. You can find these examples here
What if you don't have the exchange rate information for that country? If your user is in a country we don't have information for, or if their IP Address is somehow invalid, this query will return the original amount, currency-symbol and currency code of the FROM_CURRENCY submitted. So if your base currency is USD, your website will simply display USD amounts for these users. See our supported currencies here
2. Get country info and flag based on user's country:
|
Returns:
OL_UNICODE|FLAG
|
Example: To get country information for a user with an IP address of 178.79.140.74:
Useful for: This query is extremely useful if you would like to internationalize your website or app. For example, you can automatically display the user's country flag on the site, or display inviting text such as "We welcome all [country_name] users!". Of course, it's great to call this query in conjunction with the automatic currency conversion query if you are displaying any prices on your site.
How do I implement this in code? We have compiled a large selection of code examples to illustrate how to implement our API in a variety of programming languages. You can find these examples here
What if the IP address is invalid? In 99.5% of cases we can match a given IP to a country. However, if your user's IP Address is somehow invalid, or we cannot match it to a country, this query will return "-5". It is important that your code can handle this gracefully.
How Our API Works
Python
PHP
Ruby
Perl
ASP.NET
Java
Applescript
iPhone C
)