Identify the Currency of a Country in Java
Automating the identification of a country’s currency on your website, application, or other system will set you up for smoother transactions with international customers. The following API can assist in this automation by auto-populating a country’s currency, ISO code, and currency symbol when you input the country name.
To begin the process, we first need to install the Maven SD by adding a reference to the repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then, we will add a reference to the dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>
Once the installation is complete, we are ready to add the imports to our controller and call the function:
// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.AddressApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");AddressApi apiInstance = new AddressApi();
ValidateCountryRequest input = new ValidateCountryRequest(); // ValidateCountryRequest | Input request
try {
ValidateCountryResponse result = apiInstance.addressGetCountryCurrency(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AddressApi#addressGetCountryCurrency");
e.printStackTrace();
}
This will deliver the aforementioned currency, ISO code, and currency symbol for the specified country. Visit the Cloudmersive website to retrieve your free API key and gain access to 800 calls/month.