Get Instant Access to our Exchange Rates API

Get access instantly - 1000 requests free p/m.


How to Use Our Java Currency Conversion API

We offer an easy to use, accurate and reliable currency conversion API for Java that's perfect for both personal and professional use.

Fetching exchange rates using our Java exchange rates API is as easy as making GET requests. This means you can easily integrate our API into your Java project however you'd prefer.

For more details on the different types of request we support please see our Main Documentation.

Alternatively simply use the Java library code below to get started with our currency data as fast as you can copy & paste!

Simple Java Currency Conversion Example

This example relies on Google's GSON library.


// Setting URL
String url_str = "https://v3.exchangerate-api.com/bulk/YOUR-API-KEY/USD";

// Making Request
URL url = new URL(url_str);
HttpURLConnection request = (HttpURLConnection) url.openConnection();
request.connect();

// Convert to JSON
JsonParser jp = new JsonParser();
JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
JsonObject jsonobj = root.getAsJsonObject();

// Accessing object
String req_result = jsonobj.get("result").getAsString();
				

This will return the exchange rates from USD to all other currencies we support:

{
	"result": "success",
	"from": "USD",
	"rates": {
		"AUD": ((AUD in terms of USD)),
		"BGN": 1.8096,
		"BRL": 3.1143,
		"...": 1.3113,
		"...": 7.473, etc. etc.
	}
}

Please see our main documentation for further information on this query type & error response details.



We also offer automatic localization requests:



Automatic Currency Localization for Java

This example relies on Google's GSON library.


// Getting visitor IP address
String ip = request.getRemoteAddr();

// Setting URL
String url_str = "https://v3.exchangerate-api.com/local/YOUR-API-KEY/USD/" + ip;

// Making Request
URL url = new URL(url_str);
HttpURLConnection request = (HttpURLConnection) url.openConnection();
request.connect();

// Convert to JSON
JsonParser jp = new JsonParser();
JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
JsonObject jsonobj = root.getAsJsonObject();

// Accessing object
String req_result = jsonobj.get("result").getAsString();

// If you want to display the currency's symbol in HTML:
String symbol_html = "";
String symbol_codes = jsonobj.get("currency_symbol").getAsString();
String[] symbol_characters = symbol_codes.split(",");
for(int i=0; i < symbol_characters.length; i++) {
	symbol_html = symbol_html + "&#x"+symbol_characters[i]+";";
}
				

This will return the exchange rate from your base currency to the visitor currency & i18n data on your visitor.

In the example API response below your prices are in USD and a customer was visiting from a Bulgarian IP address so BGN is returned as the appropriate currency for a Bulgarian visitor.

{
	"result": "success",
	"from": "USD",
	"to": "BGN",
	"country_code": "BG",
	"currency_symbol": "43b,432",
	"rate": 1.81
}

Please see our main documentation for further information on this query type & error response details.

Additionally, please email us if you'd like to submit a better code example, we'll credit you!